Closed glassfishrobot closed 12 years ago
@glassfishrobot Commented Reported by kchung
@glassfishrobot Commented kchung said: Project: uel Repository: svn Revision: 352 Author: kchung Date: 2012-04-19 17:22:11 UTC Link:
Issue http://java.net/jira/browse/UEL-30
With this fix, setting a null to a bean property of primitive type will be converted to 0. To revert to the previous behavior, set the environment property "org.glassfish.el.COERCE_TO_ZERO" to false.
352
trunk/impl/pom.xml trunk/impl/src/main/java/com/sun/el/parser/AstValue.java
— trunk/impl/src/main/java/com/sun/el/parser/AstValue.java (revision 351) +++ trunk/impl/src/main/java/com/sun/el/parser/AstValue.java (revision 352) @@ -62,6 +62,9 @@ */ public final class AstValue extends SimpleNode {
static boolean COERCE_TO_ZERO = "true".equals(System.getProperty(
"org.glassfish.el.COERCE_TO_ZERO", "true"));
protected static class Target { protected Object base; protected Node suffixNode; @@ -210,9 +213,9 @@ Object property = t.suffixNode.getValue(ctx); ctx.setPropertyResolved(false); ELResolver elResolver = ctx.getELResolver();
if (value != null) {
value = ELSupport.coerceToType(value,
elResolver.getType(ctx, t.base, property));
elResolver.setValue(ctx, t.base, property, value); if (! ctx.isPropertyResolved())
{ @@ -220,6 +223,17 @@ }
}
private boolean isAssignable(Object value, Class<?> targetClass) {
if (targetClass == null)
{ + return false; + } else if (value != null && targetClass.isPrimitive()) { + return false; + }
else if (value != null && !targetClass.isInstance(value))
{ + return false; + }
return true;
}
— trunk/impl/pom.xml (revision 351) +++ trunk/impl/pom.xml (revision 352) @@ -53,7 +53,7 @@
@glassfishrobot Commented kchung said: For the record, there are numerous complaints about the spec for converting null values to the default non-null value, especially if the target type is non-primitive. See for instance,
http://java.net/jira/browse/JSP_SPEC_PUBLIC-184 and https://issues.apache.org/bugzilla/show_bug.cgi?id=43285
So this behavior may change in the next spec. In the mean time, if the previous behavior is wanted (i.e. don't convert nulls to default), set the environment property "org.glassfish.el.COERCE_TO_ZERO" to false.
@glassfishrobot Commented File: testWeb-source.zip Attached By: kchung
@glassfishrobot Commented File: testWeb.war Attached By: kchung
@glassfishrobot Commented Was assigned to kchung
@glassfishrobot Commented This issue was imported from java.net JIRA UEL-30
@glassfishrobot Commented Marked as fixed on Thursday, April 19th 2012, 10:28:33 am
When setting a bean property, if the type is a char, and the value to set is null, an "IllegalArgumentException: argument type mismatch" will be thrown. To demonstrate, run the attached test, submit "click" while leaving the field blank.
This behavior is a violation of the EL specification. EL 2.2 section 1.2.1.1 says "In the case of lvalues the expected type is ignored and the provided value is coerced to the actual type of the property the expression points to, before that property is set." Furthermore, according to the coercion rules defined in the section "1.18.3 Coerce A to Number type N" the Expression Language implementation has to coerce both null and "" to 0.