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

Specialization of generic beans throws inappropriate exception

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.2.2.Final
    • 1.1.19.Final, 2.2.0.CR2
    • None
    • None
    • Workaround Exists
    • Hide

      In the subclass declaration, reference the superclass without type parameters after the 'extends' keyword. That will result to a warning which can be suppressed using @SuppressWarnings("rawtypes").

      Following the example from the description, the specializing class would look like this:

      @Specializes
      public class BeanCustom<T extends AbstractClass> extends BeanDefault {
      }
      

      This way, type parameters of the specialized bean's bean types will be exactly the same (also equal in the java sense) as the type parameters of the specializing bean's bean types which are implied from extending the specialized class.

      Show
      In the subclass declaration, reference the superclass without type parameters after the 'extends' keyword. That will result to a warning which can be suppressed using @SuppressWarnings("rawtypes"). Following the example from the description, the specializing class would look like this: @Specializes public class BeanCustom<T extends AbstractClass> extends BeanDefault { } This way, type parameters of the specialized bean's bean types will be exactly the same (also equal in the java sense) as the type parameters of the specializing bean's bean types which are implied from extending the specialized class.

      Having this e.g this class:

      public class BeanDefault<T extends AbstractClass> {
      }
      

      and its specialization like this:

      @Specializes
      public class BeanCustom<T extends AbstractClass> extends BeanDefault<T> {
      }
      

      will result in:

      Caused by: org.jboss.weld.exceptions.DefinitionException: WELD-001511: Specializing bean Managed Bean [class mypackage.BeanCustom] with qualifiers [@Any @Default] does not have bean type class mypackage.BeanDefault<T> of specialized bean Managed Bean [class mypackage.BeanDefault] with qualifiers [@Any @Default]
      

      This is IMHO inappropriate since the type BeanDefault<T> is present. CDI spec says just:

      Formally, a bean X is said to specialize another bean Y if either:
      ...
      Furthermore, X must have all the bean types of Y. If X does not have some bean type of Y, the container automatically de-
      tects the problem and treats it as a definition error.

              bafco Matus Abaffy (Inactive)
              tremes1@redhat.com Tomas Remes
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Created:
                Updated:
                Resolved: