简体   繁体   中英

Calling method with null parameters in EL ends up in 0 being passed instead of null

I have a POJO:

public class Foo {
    public String getValue(Integer arg0, BigDecimal arg1) {...}
}

I put it as model-parameter from Spring MVC into JSP, and try to use it:

<c:set var="ans" value="${foo.getValue(null, null)}"/>

But in getValue method

arg0 = 0
arg1 = 0

instead of expected

arg0 = null
arg1 = null

I tried to run it on Tomcat 7.0.40 and on jetty 9.0.3

Is it some Tomcat bug, or It is right way EL works? How can I call method with null parameters in EL?

Update 1: Several sources, and documentation ( http://tomcat.apache.org/tomcat-7.0-doc/config/systemprops.html ) says that adding JVM property

-Dorg.apache.el.parser.COERCE_TO_ZERO=false

solves it.

But when I set it, nothing happen. I've set it correct

System.getProperty("org.apache.el.parser.COERCE_TO_ZERO")` 

returns "false" in runtime)

May be Tomcat need some other settings to change to use this param...

As far as I know, when you use Null, any program is made to initialize the Null value to a default value of the primitive. That means that int values will always have 0, double 0.0, boolean will be false etc.

What you could do, is to make some additional tests and verify whether the values are null at the beginning of your method, and in case they are, to make some additional tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM