Using parameterized type varaibles fails for Producer Method injection
----------------------------------------------------------------------
Key: OWB-245
URL: https://issues.apache.org/jira/browse/OWB-245
Project: OpenWebBeans
Issue Type: Bug
Components: Injection and Lookup
Affects Versions: M3
Environment: Windows, Eclipse running Jetty.
Reporter: Bill Wigger
Assignee: Gurkan Erdogdu
Fix For: M3
As per section 3.3 of the spec:
"If the producer method return type is a parameterized type, it must specify an
actual type parameter or type variable for each type parameter."
Problem using @Inject
The below code fragment is for a parameterized type variable, and the inject is
yielding an exception, instead of being injected properly.
public class MethodTypeProduces1<T> {
@Produces @Dependent @Named("ProMethodParameterized3") ArrayList<T>
methodPT3() { ... }
}
Inject it as follows:
public @Inject @Dependent @Named("ProMethodParameterized3")
ArrayList<String> pt3;
the following error occurs:
javax.enterprise.inject.UnsatisfiedResolutionException: Api type
[java.util.ArrayList] is not found with the qualifiers
[[email protected](value=ProMethodParameterized3)]
at
org.apache.webbeans.container.ResolutionUtil.checkResolvedBeans(ResolutionUtil.java:93)
at
org.apache.webbeans.container.InjectionResolver.getInjectionPointBean(InjectionResolver.java:232)
Problem when access via the Bean Manager:
Using this as the producer:
@Produces @Dependent @Named("ProMethodParameterized3S") ArrayList<String>
methodPT4() { .. }
I can get a reference to it with the following code:
TypeLiteral<ArrayList<String>> x = new TypeLiteral<ArrayList<String>>() { };
Bean<ArrayList<String>> iBean = (Bean<ArrayList<String>>)
manager.getBeans("ProMethodParameterized3S").iterator().next();
ArrayList<String> as = (ArrayList<String>) manager.getReference(iBean,
x.getType() , manager.createCreationalContext(iBean));
But it this is the producer:
public class MethodTypeProduces1<T> {
//Test: Parameterized Field
@Produces @Dependent @Named("ProMethodParameterized3") ArrayList<T> methodPT3()
{ ... }
then the following fails:
TypeLiteral<ArrayList<String>> x = new TypeLiteral<ArrayList<String>>() { };
Bean<ArrayList<String>> iBean = (Bean<ArrayList<String>>)
manager.getBeans("ProMethodParameterized3").iterator().next();
ArrayList<String> as = (ArrayList<String>) manager.getReference(iBean,
x.getType() , manager.createCreationalContext(iBean));
with an exception when the manager.getReference(....) is called:
java.lang.IllegalArgumentException: Given bean type :
java.util.ArrayList<java.lang.String> is not applicable for the bean instance :
Name:ProMethodParameterized3,WebBeans Type:PRODUCERMETHOD,API
Types:...java.util.ArrayList...
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.