Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-847

Expression NULL handling

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0
    • 3.0M2
    • Core Library
    • 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)

      Attachments

        Activity

          People

            andrus Andrus Adamchik
            andrus Andrus Adamchik
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: