lsp4jakarta
lsp4jakarta copied to clipboard
Dependency Injection: Diagnostic for `@Specialize` without extending a managed bean
If a bean class of a managed bean X is annotated @Specializes, then the bean class of X must directly extend the bean class of another managed bean Y. Then X directly specializes Y, as defined in Specialization.
If the bean class of X does not directly extend the bean class of another managed bean, the container automatically detects the problem and treats it as a definition error.
Diagnostics
- Identify the
@Injectfield/method/constructor - Check if the dependency class is annotated with
@Specializes - Deliver a diagnostic error that the dependency class must extend a managed bean if one of the following conditions are identified:
- the dependency class does not extend any class
- the dependency class extends a class that is not a managed bean (depends on #159)
Quickfixes
- Suggest removing the
@Specializeannotation
Example
@ApplicationScoped
@Specializes
// Error here due to not extending a managed bean
public class GreetingA {
public String greet(String name) {
return "GreetingA, " + name;
}
}
[INFO] [ERROR ] CWWKZ0004E: An exception occurred while starting the application demo-servlet. The exception message was: com.ibm.ws.container.service.state.StateChangeException: org.jboss.weld.exceptions.DefinitionException: WELD-000047: Specializing bean must extend another bean: Managed Bean [class io.openliberty.sample.jakarta.di.error.ext.GreetingA] with qualifiers [@Any @Default]
Related to #153