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

Weld creates multiple interceptor instances per target instance

    XMLWordPrintable

Details

    Description

      The CDI spec says:

      An interceptor instance is a dependent object of the object it inter-cepts.

      The Interceptors spec says:

      The lifecycle of an interceptor instance is the same as that of the target class instance with which it
      is associated. When the target instance is created, a corresponding interceptor instance is created for
      each associated interceptor class. These interceptor instances are destroyed when the target instance
      is removed.

      and also

      An interceptor instance may hold state.

      It is clear that at most one instance of an interceptor class should be created for an instance of a CDI bean. However, Weld currently creates an instance per method per target instance.

      Having a simple intercepted bean:

      @ApplicationScoped
      @LionBinding
      public class Lion
          public Object foo() {
              return null;
          }
      
          public Object bar() {
              return null;
          }
      }
      
      • multiple invocations of a single method (e.g. foo()) are intercepted by the same interceptor instance
      • when invoking different methods on the same bean instance, every method is intercepted by a different interceptor instance - which is wrong

      Attachments

        Activity

          People

            marko.luksa@gmail.com Marko Luksa (Inactive)
            rhn-engineering-jharting Jozef Hartinger
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: