lsp4jakarta icon indicating copy to clipboard operation
lsp4jakarta copied to clipboard

Dependency Injection: Diagnostic for `@Specialize` without extending a managed bean

Open KidoVin01 opened this issue 4 years ago • 0 comments

Specializing 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

  1. Identify the @Inject field/method/constructor
  2. Check if the dependency class is annotated with @Specializes
  3. 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 @Specialize annotation

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

KidoVin01 avatar Nov 12 '21 02:11 KidoVin01