jakartaee / expression-language

Jakarta Expression Language
https://eclipse.org/ee4j/el
Other
68 stars 49 forks source link

Missing coercion from null values cuases argument mismatch #30

Closed glassfishrobot closed 12 years ago

glassfishrobot commented 12 years ago

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.

glassfishrobot commented 6 years ago
glassfishrobot commented 12 years ago

@glassfishrobot Commented Reported by kchung

glassfishrobot commented 12 years ago

@glassfishrobot Commented kchung said: Project: uel Repository: svn Revision: 352 Author: kchung Date: 2012-04-19 17:22:11 UTC Link:

Log Message:

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.

Revisions:

352

Modified Paths:

trunk/impl/pom.xml trunk/impl/src/main/java/com/sun/el/parser/AstValue.java

Diffs:

Index: 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 {

{ + return false; + } else if (value != null && targetClass.isPrimitive()) { + return false; + }

else if (value != null && !targetClass.isInstance(value))

{ + return false; + }

[http://uel.java.net](http://uel.java.net) @@ -137,6 +137,7 @@ org.apache.felix maven-bundle-plugin + 1.4.3 $ {bundle.symbolicName}
glassfishrobot commented 12 years ago

@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 12 years ago

@glassfishrobot Commented File: testWeb-source.zip Attached By: kchung

glassfishrobot commented 12 years ago

@glassfishrobot Commented File: testWeb.war Attached By: kchung

glassfishrobot commented 12 years ago

@glassfishrobot Commented Was assigned to kchung

glassfishrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA UEL-30

glassfishrobot commented 12 years ago

@glassfishrobot Commented Marked as fixed on Thursday, April 19th 2012, 10:28:33 am