[ 
https://issues.apache.org/jira/browse/OWB-893?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13755614#comment-13755614
 ] 

Arjan Tijms commented on OWB-893:
---------------------------------

Mark, thanks a lot for your thorough reply.

{quote}
The CDI-1.0 spec is defined for [...] what does happen if the injection point 
type is generic but the bean type is raw or unbound.
{quote}

And there's the generic method producer of course. So for the producer there 
are three options:

Raw:
{code}
@Produces
public ParamValue produce(InjectionPoint injectionPoint)
{code}

Unbound:
{code}
@Produces
public ParamValue<?> produce(InjectionPoint injectionPoint)
{code}

Generic method with type parameter:
{code} 
@Produces 
public <V> ParamValue<V> produce(InjectionPoint injectionPoint) 
{code} 

{quote}
But there is no way with the current wording to do it the other way around:
{code}
@Inject Stable<Horse> horseStable;
@Inject Stable<Pig> pigStable;
{code}
with a single producer method {{@Produces <PET> Stable<PET>}}
{quote}

Indeed, with both CDI 1.0 and CDI 1.1 this seemingly obvious thing seems to be 
impossible. Despite not being specified, for CDI 1.0 implementations using the 
"hack" where the producer returns a raw type seems to work with Weld, 
OpenWebBeans and CanDI. Unfortunately for CDI 1.1 implementations this doesn't 
work, as Weld 2.0 doesn't work with it.

{quote}If it would be only me, then I'd really ditch this paragraph again and 
do it properly, which means we need to introduce a multi-pass approach as this 
imo prevents us from providing such a 'generic' producer method which takes the 
type info from the InjectionPoint. {quote}

There are probably some intricate details I'm not aware of, but that sounds 
really good to me. Unfortunately Java EE 7 was just released and it thus will 
be a long time for a new CDI 1.2 will see the light of day. For utility 
libraries or applications that need to be compatible with CDI 1.0, 1.1 and the 
upcoming 1.2 it will be really hard if not impossible to have a single producer 
method that works on all 3 versions.

Is OWB 1.2.1 btw going to be a CDI 1.1 implementation, or still a CDI 1.0 one 
but with some 1.1 semantics?
                
> OpenWebBeans 1.2.1 fails when injecting generic value holder
> ------------------------------------------------------------
>
>                 Key: OWB-893
>                 URL: https://issues.apache.org/jira/browse/OWB-893
>             Project: OpenWebBeans
>          Issue Type: Bug
>          Components: Injection and Lookup
>    Affects Versions: 1.2.1
>            Reporter: Arjan Tijms
>            Assignee: Mark Struberg
>
> In OmniFaces we're using a producer method with the following signature:
> {code}
> @Produces
> @Param
> public <V> ParamValue<V> produce(InjectionPoint injectionPoint)
> {code}
> Injection then takes place into a bean as follows:
> {code}
> @Inject @Param
> private ParamValue<String> text1;
> {code}
> {{@Param}} is a qualifier with only non-binding attributes.
> See 
> [RequestParameterProducer|https://code.google.com/p/omnifaces/source/browse/src/org/omnifaces/cdi/param/RequestParameterProducer.java]
>  and 
> [Param|https://code.google.com/p/omnifaces/source/browse/src/org/omnifaces/cdi/Param.java]
> This works in all versions of Weld that we tested on and in OpenWebBeans 
> 1.1.8 (TomEE 1.5.2.). Unfortunately it does not work with OpenWebBeans 
> 1.2.1-SNAPSHOT (TomEE 1.6.0-SNAPSHOT).
> The problem seems to be that 1.2.1 has added an additional check in 
> {{org.apache.webbeans.util.GenericsUtil.satisfiesDependency}} that wasn't 
> there before:
> {code}
> return ClassUtil.isSame(injectionPointRawType, beanRawType)? 
> isAssignableFrom(injectionPointType, beanType): false;
> {code}
> The problem is with {{isAssignableFrom}}, because the producer is always seen 
> as producing a {{ParamValue<Object}}. The actual values at the point of 
> evaluation with the above given injection example where:
> {noformat}
> injectionPoint = ParamValue<class java.lang.String> 
> beanType = ParamValue<class java.lang.Object>
> {noformat}
> Those are not directly assignable so the injection fails.
> Is OmniFaces doing something wrong here, is this check to strict, or should 
> the producer type not be seen as {{ParamValue<Object>}}?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to