2 Replies Latest reply on Dec 19, 2016 6:21 AM by Nuno Godinho de Matos

    Doubt about Spec Section 5.2.4. Assignability of raw and parameterized types - On injection point without diamond operator

    Nuno Godinho de Matos Newbie

      Hi,

       

      I have doubt about the following spec section:

      https://docs.jboss.org/cdi/spec/1.2/cdi-spec.html#assignable_parameters

       

      I am trying to understand what paragraph in the spec explains the reason why a parameterized bean would not be injectable into a raw type delcared injection point.

      From what I understand in CDI 1.0 weld se core final, there was an implementation bug that has since been fixed, whereby the following type of injection would work:


      @ Inject

      Instance<Dao> allDaos;

       

      Now Dao, is a paremeterized interface.

      And in CDI 1.1 weld 2.3.2 final, the code to be made to work would need to fix the injection point to read as follows:

      Instance<Dao<?>> allDaos;

       

      So, one would jave to declare that he wants to inject a Dao where the type parameter is unbounded / wild carded.

       

      Of course, the Dao class could be for example a

      public interface Dao<T>{

      }

       

      The problem of course, is that as I try to upgrade, I am encountering some runtime blowups where essentially instances that used to be made accessible from injection points that were not using the diamon wild card fail.

      This is fine, I will fix those ... I do need to spot them all... but life is like that. Mistakes have a price.

       

      But in any case, i would like to see in the spec document the phrase that states that a class.

      public class UserDao implements Dao<User>{

      }

       

      Is not assignable to the injection point Instance<Dao>.

       

      I suspect the phrase is htis one:

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

      In this case:

      A A parameterized bean type

      UserDao

      is considered assignbale to a raw requred type

      @ Inject

      Instance<Dao> allDaos;

       

       

      if the raw types

      "Dao"

      and all type parameters of the bean type

      "User"

      either unbounded type

      (it is not the case right it is bounded to "User")

      or "java.lang.Object".

       

      But I am not sure 100% that my interepretaiton is corect.

      If it is, this means that to the old injection point only a class of the form:

      UnAssigninedDao <T> extends Dao<T>{

      }

       

      Or a class

      ObjectDao  extends Dao<Object>{

      }

       

      would be legal candaidates to the injection point above?

       

      Thanks for the clarification, this is discovery is an unfortunate setback... that is blowing up in my face in runtime testing.