Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0
-
None
Description
Consider the following unit test:
public void testNullParameters()
{ Expression e = ExpressionFactory.matchExp("X", null); assertEquals("X = null", e.toString()); e = Expression.fromString("X = $x").expWithParameters( Collections.singletonMap("x", null)); assertEquals("X = null", e.toString()); }The first assertion succeeds, while the second throws an NPE:
java.lang.NullPointerException
at org.apache.cayenne.exp.parser.SimpleNode.encodeAsString(SimpleNode.java:184)
at org.apache.cayenne.exp.Expression.toString(Expression.java:549)
at org.apache.cayenne.exp.ExpressionTest.testNullParameters(ExpressionTest.java:42)
Turns out the difference is in wrapping of the NULL parameter in ASTScalar in the first case, and leaving a bare NULL in the second. I guess this requires two-part fix:
1. Ensure that NULL's are wrapped in ASTScalar in 'expWithParameters'
2. Null checks in encodeAsString (just in case)