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

Multiple instances of interceptors created for same target


      Using a Service class like this:

      public class TestService {
      public class MyInterceptor {
      Object field;
          public void wrapConstructor(InvocationContext ctx) throws Exception {
               field = new Object();
          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:
      "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)
            0 Vote for this issue
            2 Start watching this issue