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

Injection of parameterized types does not longer work in 2.x (starting with 2.0.0.Alpha3)

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 2.2.5.Final
    • 2.0.0.Alpha3, 2.2.4.Final
    • None
    • None

    Description

      Injection of parameterized types does not work correctly in 2.0.0.Alpha3 and up, if the parameterized type "extends" another type. It used to work in 1.x and up to 2.0.0.Alpha2.

      Example code:

      public interface Foo<T extends Serializable> { } // will fail
      public class FooBean implements Foo { }
      public interface Bar<T> { } // will work
      public class BarBean implements Bar { }
      @Singleton
      @Startup
      public class TestSingleton {
          @Inject
          private Instance<Foo> foo;
          @Inject
          private Instance<Bar> bar;
          @PostConstruct
          public void init() {
              System.out.println("##### foo is unsatisfied = " + foo.isUnsatisfied());
              for (Foo f : foo)
                  System.out.println("foo is: " + f.getClass().getCanonicalName());
              System.out.println("##### bar is unsatisfied = " + bar.isUnsatisfied());
              for (Bar b : bar)
                  System.out.println("bar is: " + b.getClass().getCanonicalName());
          }
      }
      
      ==================================
      WORKS in Weld 1.x and 2.0.0.Alpha2: (this is the expected output)
      ==================================
      
      16 [org.example.weldtest.App.main()] INFO org.jboss.weld.Version - WELD-000900 2.0.0 (Alpha2)
      50 [org.example.weldtest.App.main()] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      236 [org.example.weldtest.App.main()] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
      236 [org.example.weldtest.App.main()] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
      ##### foo is unsatisfied = false
      foo is: org.example.weldtest.FooBean
      ##### bar is unsatisfied = false
      bar is: org.example.weldtest.BarBean
      
      ==============================
      BROKEN ON: 2.0.0.Alpha3 and up:
      ===============================
      
      14 [org.example.weldtest.App.main()] INFO org.jboss.weld.Version - WELD-000900 2.0.0 (Alpha3)
      46 [org.example.weldtest.App.main()] INFO org.jboss.weld.Bootstrap - WELD-000101 Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      276 [org.example.weldtest.App.main()] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
      276 [org.example.weldtest.App.main()] WARN org.jboss.weld.interceptor.util.InterceptionTypeRegistry - Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
      ##### foo is unsatisfied = true
      ##### bar is unsatisfied = false
      bar is: org.example.weldtest.BarBean
      
      ----
      
      Aug 26, 2014 12:06:15 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
      INFO: WELD-000900: 2.2.4 (Final)
      Aug 26, 2014 12:06:15 PM org.jboss.weld.bootstrap.WeldStartup startContainer
      INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
      Aug 26, 2014 12:06:15 PM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
      WARN: WELD-001700: Interceptor annotation class javax.ejb.PostActivate not found, interception based on it is not enabled
      Aug 26, 2014 12:06:15 PM org.jboss.weld.interceptor.util.InterceptionTypeRegistry <clinit>
      WARN: WELD-001700: Interceptor annotation class javax.ejb.PrePassivate not found, interception based on it is not enabled
      ##### foo is unsatisfied = true
      ##### bar is unsatisfied = false
      bar is: org.example.weldtest.BarBean
      

      I have created a minimal working example, which is available at https://github.com/lngr/weldtest and also attached to this issue.

      This was previously reported in WFLY-3632

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-jharting Jozef Hartinger
              doegi_jira Alexander Langer (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: