Uploaded image for project: 'CDI Specification Issues'
  1. CDI Specification Issues
  2. CDI-169

Remove the 'No type variable in event objects' restriction

    Details

    • Type: Feature Request
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1.PFD
    • Component/s: None
    • Labels:
      None

      Description

      CDI 10.1 states:

      An event object is an instance of a concrete Java class with no type variables. ... An event type may not contain a type variable.

      Which seems silly considering the container fires events with a type variable at startup. I can't think of any reason why this should be prohibited.

        Gliffy Diagrams

          Issue Links

            Activity

            Hide
            mkouba Martin Kouba added a comment -

            Not a good example I think. In this situation it is possible. Event knows its InjectionPoint that knows its java.lang.reflect.Member (Field in this case). Following pseudocode will work.

             
            Field field = (Field) injectionPoint.getMember();
            Type eventType = field.getGenericType();
             
            if(eventType instanceof ParameterizedType) {
             
              for(Type eventTypeArgument : ((ParameterizedType) eventType).getActualTypeArguments()){
               // Now at Event level
             
               if(eventTypeArgument instanceof ParameterizedType) {
                 for (Type fooTypeArgument : ((ParameterizedType) eventTypeArgument).getActualTypeArguments())
                 {
                  // Now at Foo level
                  System.out.println("fooTypeArgument = " + fooTypeArgument);
                 }
                }
              }
            }
            

            See http://tutorials.jenkov.com/java-reflection/generics.html

            However in this situation it is NOT possible...

            class Bar {
             
              @Inject
              BeanManager beanManager;
             
              public void fire() {
                beanManager.fireEvent(new Foo<Baz>());
              }
             
            }
            

            Show
            mkouba Martin Kouba added a comment - Not a good example I think. In this situation it is possible. Event knows its InjectionPoint that knows its java.lang.reflect.Member (Field in this case). Following pseudocode will work. Field field = (Field) injectionPoint.getMember(); Type eventType = field.getGenericType();   if(eventType instanceof ParameterizedType) {   for(Type eventTypeArgument : ((ParameterizedType) eventType).getActualTypeArguments()){ // Now at Event level   if(eventTypeArgument instanceof ParameterizedType) { for (Type fooTypeArgument : ((ParameterizedType) eventTypeArgument).getActualTypeArguments()) { // Now at Foo level System.out.println("fooTypeArgument = " + fooTypeArgument); } } } } See http://tutorials.jenkov.com/java-reflection/generics.html However in this situation it is NOT possible... class Bar {   @Inject BeanManager beanManager;   public void fire() { beanManager.fireEvent(new Foo<Baz>()); }   }
            Hide
            pmuir Pete Muir added a comment -

            I should clarify that this is following the CDI 1.0 spec, which doesn't allow Weld to look at the type of the event injection, but only at the type of the event object.

            Show
            pmuir Pete Muir added a comment - I should clarify that this is following the CDI 1.0 spec, which doesn't allow Weld to look at the type of the event injection, but only at the type of the event object.
            Hide
            arnelim Arne Limburg added a comment -

            And, to correct Petes example, in the following case the detection is not possible either:

            class Foo<T> {}
             
            class Bar<U> {
             
               @Inject Event<Foo<U>> evt;
             
               public void doIt(Foo<U> foo) {
                  evt.fire(foo);
            }
            

            Show
            arnelim Arne Limburg added a comment - And, to correct Petes example, in the following case the detection is not possible either: class Foo<T> {}   class Bar<U> {   @Inject Event<Foo<U>> evt;   public void doIt(Foo<U> foo) { evt.fire(foo); }
            Hide
            pmuir Pete Muir added a comment -

            No, my example is correct. The spec does not allow you to look at the parameterized type of event, it just talks about the type of the event type, which is Foo<Baz> in my example, and undetectable.

            Show
            pmuir Pete Muir added a comment - No, my example is correct. The spec does not allow you to look at the parameterized type of event, it just talks about the type of the event type, which is Foo<Baz> in my example, and undetectable.
            Hide
            pmuir Pete Muir added a comment -

            This got fixed as part of CDI-256, when we changed it to disallow unresolvable type variables. We defined that an unresolvable type variable is one which can't be inferred from the Event injection point.

            Show
            pmuir Pete Muir added a comment - This got fixed as part of CDI-256 , when we changed it to disallow unresolvable type variables. We defined that an unresolvable type variable is one which can't be inferred from the Event injection point.

              People

              • Assignee:
                pmuir Pete Muir
                Reporter:
                swd847 Stuart Douglas
              • Votes:
                1 Vote for this issue
                Watchers:
                8 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Development