The call method with null parameters in EL ends with 0, not null

I have a POJO:

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

I put it as a model parameter from Spring MVC in JSP and try to use it:

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

But in the getValue method

 arg0 = 0 arg1 = 0 

instead of the expected

 arg0 = null arg1 = null 

I tried to launch it on Tomcat 7.0.40 and on berth 9.0.3

Is this some kind of Tomcat bug, or is this the correct way EL works? How can I call a method with null parameters in EL?

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

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

solves it.

But when I install it, nothing happens. I installed it correctly

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

returns "false" at runtime)

Maybe Tomcat needs some other tweaks to change this setting ...

+8
java spring-mvc tomcat el
source share
2 answers

As far as I know, when using Null, any program is created to initialize the Null value with the default value for the primitive. This means that int values ​​will always have 0, double 0.0, boolean will be false, etc.

What you can do is do some additional tests and check if the values ​​are zeros at the beginning of your method and, if any, do a few extra tests.

-one
source share

Try the following:

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

Now u will get the expected result as shown below

 arg0 = null arg1 = null 
-one
source share

All Articles