Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Injection: Diagnostics for bean class of generic or parameterized type #210

Closed
Tracked by #16
KidoVin01 opened this issue Nov 11, 2021 · 3 comments · Fixed by #225
Closed
Tracked by #16

Dependency Injection: Diagnostics for bean class of generic or parameterized type #210

KidoVin01 opened this issue Nov 11, 2021 · 3 comments · Fixed by #225
Assignees
Labels
diagnostic Diagnostic item

Comments

@KidoVin01
Copy link
Contributor

KidoVin01 commented Nov 11, 2021

Managed Beans

If the managed bean class is a generic type, it must have scope @dependent. If a managed bean with a parameterized bean class declares any scope other than @dependent, the container automatically detects the problem and treats it as a definition error.

Diagnostics

  1. Check if class is a managed bean
  2. Check if managed bean is of generic/parameterized type
  3. Check if dependency class is annotated with @Dependent or has no other scope specified
  4. If not, deliver an error at the class declaration

Quickfixes

  • Suggest removing scope

Example

@ApplicationScoped
// Error here due to the generic type
public class Greeting<T>{
	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-000071: Managed bean with a parameterized bean class must be @Dependent: class io.openliberty.sample.jakarta.di.error.generic.Greeting

Related to #153

@KidoVin01
Copy link
Contributor Author

KidoVin01 commented Nov 11, 2021

Working on this

@kathrynkodama
Copy link
Contributor

  1. Identify @Inject field/method/constructor
  2. Check if dependency class is a generic/parameterized type
  3. Check if dependency class is annotated with @Dependent or has no other scope specified
  4. If so, deliver an error at the class declaration

Is step (1) really needed to check for this diagnostic? If not let's remove it

@KidoVin01
Copy link
Contributor Author

I have updated the diagnostics accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment