I like to implement a producer which can satisfy the following injection points:
private @Inject @IsFeatureA Boolean featureA; private @Inject @IsFeatureA boolean featureA;
Boolean (wrapper type) and boolean (primitive type) used at the same time.
This is currently not allowed by the CDI spec!
5.2.4. "Primitive types and null values" defines that
"For the purposes of typesafe resolution and dependency injection, primitive types and their corresponding wrapper types in the package java.lang are considered identical and assignable."
In the same paragraph it also states that
"However, if an injection point of primitive type resolves to a bean that may have null values, such as a producer method with a non-primitive return type or a producer field with a non-primitive type, the container automatically detects the prob- lem and treats it as a deployment problem."
This means that I can only have producer methods and fields which have primitive return values and never use their wrapper types if I like to inject into both boolean and Boolean fields.
But if I use the primitive type, then I loose the ability to explicitly return null for those.
Possible solution:
As primitives and their wrapper only can be @Dependent, it would be perfectly possible to e.g. inspect the InjectionPoint and on a primitive type return a default value and for a wrapper type return null.
- is related to
-
CDITCK-299 Remove all tests for BeanAttributes.isNullable()
- Resolved
- relates to
-
WELD-1194 Implement CDI-247
- Resolved