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

Specialization of generic beans throws inappropriate exception

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.1.19.Final, 2.2.0.CR2
    • Fix Version/s: 2.2.2.Final
    • Component/s: None
    • Labels:
      None
    • Workaround:
      Workaround Exists
    • Workaround Description:
      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.
    • Bugzilla Update:
      Perform

      Description

      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.

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  bafco Matus Abaffy
                  Reporter:
                  tremes Tomas Remes
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: