[cdi-dev] [JBoss JIRA] (CDI-736) Observer resolution - assignability clarification

Antoine Sabot-Durand (JIRA) issues at jboss.org
Wed Sep 26 07:53:00 EDT 2018


    [ https://issues.jboss.org/browse/CDI-736?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13638727#comment-13638727 ] 

Antoine Sabot-Durand commented on CDI-736:
------------------------------------------

Agree with you [~manovotn]. Re-reading 10.3.1 we have rules  to assign parametrized event type to raw observer but no rules for the other way around : raw event type to parameterized observer.

As you suggested we should follow assignability defined in [5.2.4. Assignability of raw and parameterized types|http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#assignable_parameters]:

{quote}A raw bean type is considered assignable to a parameterized required type if the raw types are identical and all type parameters of the required type are either unbounded type variables or java.lang.Object.{quote}

Thus, sentence to add to 10.3.1 should be:

{quote}A raw event type is considered assignable to a parameterized observed event type if the raw types are identical and all type parameters of the required type are either unbounded type variables or java.lang.Object.{quote}

> Observer resolution - assignability clarification
> -------------------------------------------------
>
>                 Key: CDI-736
>                 URL: https://issues.jboss.org/browse/CDI-736
>             Project: CDI Specification Issues
>          Issue Type: Clarification
>          Components: Resolution
>    Affects Versions: 2.0.SP1
>            Reporter: Matej Novotny
>             Fix For: 2.1 (Discussion)
>
>
> Recently we came up across an observer resolution issue which concerns [10.3.1. Assignability of type variables, raw and parameterized types|http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#observers_assignability].
> What happens when you are trying to assign a non-parameterized subclass to a parameterized superclass?
> Here is a bit of code, we have following two classes:
> {code}
> public interface QualifiedEvent<T> {
>  // some methods
> }
> public class EventImpl implements QualifiedEvent { //NOTE - implements raw type
>  // some method impls
> }
> {code}
> Here is observer code:
> {code}
>     void listenForChildEvent(@Observes QualifiedEvent<Bar> foo) {
>       // stuff going on here...
>     }
> {code}
> And your event type is:
> {code}
> new EventImpl(clazz);
> {code}
> In this scenario, the spec is IMO unclear on what should happen in this particular case.
> Looking at other parts of spec, we already have this covered in, for instance, [delegate injection point assignability|http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#delegate_assignable_parameters], where it says:
> bq. A raw bean type is considered assignable to a parameterized delegate type if the raw types are identical and all type parameters of the delegate type are either unbounded type variables or java.lang.Object.
> I think we should add a similar sentence to  [10.3.1. Assignability of type variables, raw and parameterized types|http://docs.jboss.org/cdi/spec/2.0/cdi-spec.html#observers_assignability]. That way the spec will behave coherently and *the above observer/event assignability should not work*.
> Side note - for the sample above to work, you would need to change the observed types to {{QualifiedEvent<?>}}.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the cdi-dev mailing list