EL expression: passing null as value of BigDecimal

2020-07-24 05:43发布

问题:

I have class with BigDecimal property. When I bind to it EL expression and passing null - valueExpression.set(context, null), new value of property becomes to be BigDecimal.ZERO.

Is there any way to pass null to BigDecimal field without converting it to zero?

回答1:

You seem to be running Tomcat of at least version 6.0.16 or a fork of it like JBoss AS. Tomcat's builtin Apache EL parser will indeed do that for all classes extending Number. You need to add the following VM argument to disable this behaviour (which is indeed unintuitive, but unfortunately strictly as per the EL spec):

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

See also JSP/EL spec issue 184 and Tomcat issue 42385.



标签: java jsp el