[cdi-dev] [JBoss JIRA] (CDI-247) It's currently not possible to implement a primitive and wrapping type producer method for the same type

Jozef Hartinger (JIRA) jira-events at lists.jboss.org
Mon Sep 17 09:20:35 EDT 2012


     [ https://issues.jboss.org/browse/CDI-247?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Jozef Hartinger reopened CDI-247:
---------------------------------



The following paragraph is still present in the specification:

{quote}
For a custom implementation of the Bean interface defined in Section 11.1, “The Bean interface”, the container calls isNullable() to determine whether the bean may have null values.
{quote}

Since resolving a possibly nullable bean for a primitive injection point is no longer treated as a deployment problem by the specification, there is no  need for a container to use the `isNullable()` method. The TCK currently checks whether the method is called on a custom bean and the test fails if the method is not called. This is too strict.

I can see these possible options:
* removing the paragraph entirely and deprecating the method
* changing the paragraph to say that the container *may* use the method (e.g. for its own optimization) but is not required to do so. The method would remain untouched (not deprecated).
* perhaps the specification does not need a change, only the TCK is too strict and should be changed
                
> It's currently not possible to implement a primitive and wrapping type producer method for the same type
> --------------------------------------------------------------------------------------------------------
>
>                 Key: CDI-247
>                 URL: https://issues.jboss.org/browse/CDI-247
>             Project: CDI Specification Issues
>          Issue Type: Bug
>          Components: Concepts
>    Affects Versions: 1.0, 1.1.EDR
>            Reporter: Mark Struberg
>            Assignee: Pete Muir
>             Fix For: 1.1.PRD
>
>
> I like to implement a producer which can satisfy the following injection points:
> {code}
> private @Inject @IsFeatureA Boolean featureA;
> private @Inject @IsFeatureA boolean featureA;
> {code}
> 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.

--
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



More information about the cdi-dev mailing list