Uploaded image for project: 'Weld'
  1. Weld
  2. WELD-2131

Multiple instances of interceptors created for same target

XMLWordPrintable

      Using a Service class like this:

      @Interceptors(MyInterceptor.class)
      public class TestService {
      ...
      }
      
      @ManagedBean
      public class MyInterceptor {
      Object field;
      @AroundConstruct
          public void wrapConstructor(InvocationContext ctx) throws Exception {
               field = new Object();
      }
       @AroundInvoke
          public Object guard(final InvocationContext context) throws Exception {
              assert field != null;
      }
      }
      

      I would expect the assert to pass. However it fails, because weld creates two instances of this interceptor, one for each Interception Type.

      I did not see this documented, and I am not sure if it is a bug. If not, more documentation would help.

      JSR 318 seems to say this:
      http://download.oracle.com/otndocs/jcp/interceptors-1_2-mrel2-spec/
      "Except as noted below, when the target instance is created, a corresponding interceptor instance is created for each associated interceptor class."

      "The applicability of a method-level interceptor to more than one method of an associated target class does not affect the relationship between the interceptor instance and the target class—only a single instance of the interceptor class is created per target class instance"

              mkouba@redhat.com Martin Kouba
              tkruse_jira Thibault Kruse (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: