Classes that use both the Specializes and Alternative annotations are not injected into other modules

This rule flags classes that are annotated with both the @Specializes and @Alternative annotations. If the class is referenced by a class from another module, the class is not injected into the other module unless it is listed as an <alternative> in the META-INF/beans.xml of the other module.

In the following example, the AltClass3 class is listed in the jar2/META-INF/beans.xml file as an <alternative>. The class is not listed as an <alternative> in the jar1/META-INF/beans.xml file.


WEB-INF/lib/jar1:
  Class1 {
    @Inject @SomeQualifer String foo;
  }
 
WEB-INF/lib/jar2:
  Class2 { 
    @Produces @SomeQualifer String doFoo() { ... } 
  }
  @Alternative @Specializes AltClass3 extends Class2 { 
    @Produces @SomeQualifer String doFoo() { ... } 
  }  

In the Contexts and Dependency Injection (CDI) 1.0 implementation, Class2 is injected and used as a producer for Class1.foo. In the CDI 1.2 implementation, Class2 is not injected and the application does not start, stating that no producer for Class1.foo can be found.

You can resolve the issue in two ways:

For more information about the Java Platform, Enterprise Edition (Java EE) 7 CDI 1.2 implementation, see Contexts and Dependency Injection 1.2 behavior changes.