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

Incorrect check of bean type when obtaining contextual reference via BeanManager#getReference()

    XMLWordPrintable

Details

    Description

      CDI 1.0 section 11.3.1 Obtaining a contextual reference for a bean states:
      "If the given type is not a bean type of the given bean, an IllegalArgumentException is thrown."

      However no such exception is thrown. Refer to CDI TCK test [1].

      After inspecting the source code I suppose the problem is probably related to following part of org.jboss.weld.manager.BeanManagerImpl.getReference(Bean<?>, Type, CreationalContext<?>):

      if (!Reflections.isAssignableFrom(bean.getTypes(), beanType))
      {
       throw new IllegalArgumentException(SPECIFIED_TYPE_NOT_BEAN_TYPE, beanType, bean );
      }
      

      All beans have the bean type java.lang.Object (2.2. Bean types) - since java.lang.Object is assignable from any class Reflections.isAssignableFrom(bean.getTypes(), beanType) will always return true.

      [1] https://github.com/jboss/cdi-tck/blob/master/impl/src/main/java/org/jboss/jsr299/tck/tests/lookup/manager/ManagerTest.java

      Attachments

        Activity

          People

            rhn-engineering-jharting Jozef Hartinger
            mkouba@redhat.com Martin Kouba
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: