Incorrect CDI Injection error?

Answered

I think we've found a case where IntelliJ reports an error when there isn't one.

From the Weld documentation: (4.9 Client Proxies https://docs.jboss.org/weld/reference/2.1.2.Final/en-US/html_single/#d0e1464), the java type of "classes which don't have a non-private constructor with no parameters" cannot be injected (emphasis mine).
This is common in the case where constructor-injection is used in the injected object's class.

The same Weld link suggests work-around is to introduce an interface, and inject the interface instead.

This deploys and works in Wildfly 8.1.

However, IntelliJ still shows an error in this case by saying, "Injected normal scoped bean is not proxyable". The inspection is "CdiUnproxyableBeanTypesInspection".

Is IntelliJ correct as per the specification, or is this a bug in the CDI inspection?


Minimal example:

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.io.Serializable;

class A {}

interface IB{}

@ApplicationScoped
class B implements IB, Serializable {
@Inject B(A a) {}
}

class C {
@Inject B b; // IntelliJ shows error but works in Weld
}

3 comments
Comment actions Permalink

I have exactly the same question as you. Can the Intellij team answer this?

0
Comment actions Permalink

I had the same issue, removing static modifiers to the bean's method resolved the warning.

0

Please sign in to leave a comment.