So I've been away from Java EE for six months and I'm now back and migrating an application to Java EE 7 and I am noticing that JSR-341/ the EL 3.0 spec. contains changes in the section Type Conversion (now, section 1.23; formerly, section 1.18).
In section 1.23, the very first rule in all of the various types except String is that if X is null and Y is not a primitive return null. This is a much welcome change.
So my first question is: with regard to section 1.23.3 Coerce A to Number type N,
In EL 2.1:
If A is null or "", return 0.
In EL 3.0:
If A is null and N is not a primitive type, return null.
Else if A is null or "", return 0.
Is it now no longer necessary to set the system property org.apache.el.parser.COERCE_TO_ZERO=false
?
Next, there are a couple of other changes that beg questions:
In the very first subsection, section 1.23.1 (formerly 1.18.1) To Coerce a Value X to Type Y, the rule for the general case is given. Now, a new bullet has been added (emphasis mine):
If X is null and Y is not a primitive type and also not a String, return null.
In section 1.23.2 Coerce A to String the first two bullets have been flipped around. They are now in the following order:
If A is null: return “”
Otherwise, if A is String: return A
It appears that whereas before a null String remained a null String after coercion, now a null String is coerced to an empty String. So my second question is: am I reading this correctly, that the String is now treated differently than the other kinds of objects with respect to coercion? If so, why?
Such a change seems counterintuitive because as we all know null has special meaning. Moreover, such a change is alarming because it can adversely affect the code that I'm migrating, which was was originally written against an older spec.
And, finally, my third question is: what about bean validation? Does this mean that now @NotNull
annotations on Strings in backing beans are useless because coerced String values can never be null? I doubt it, but I'd like to know how the new changes all work together.