Expression NULL handling
------------------------

                 Key: CAY-847
                 URL: https://issues.apache.org/cayenne/browse/CAY-847
             Project: Cayenne
          Issue Type: Bug
          Components: Cayenne Core Library
    Affects Versions: 3.0
            Reporter: Andrus Adamchik
            Assignee: Andrus Adamchik
             Fix For: 3.0


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)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to