Uploaded image for project: 'Commons JEXL'
  1. Commons JEXL
  2. JEXL-324

JexlEngine.createExpression("new()").getParsedText() throws NPE

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1
    • 3.2
    • None

    Description

      JEXL is able to parse the expression "new()", but some parts of the system do not expect this.  Specifically, if you try to get the parsed text, JEXL throws a NullPointerException instead of returning "new()".

      I expect JexlExpression.getParsedText() to return a String  for any expression that was successfully parsed. So either createExpression() should throw an exception or getParsedText() should return "new()".  My preference is for createExpression() to fail and I'll try to submit a PR for this.

       

      Impact:
      My program tries to fail fast with a clear error message when a user attempts to "register" a function using a reserved name (function registration happens outside of JEXL and is implemented by populating a JexlContext with a parsed expression). My program does this by probing for valid function names by parsing FUNCTION_NAME+"()" and checking for errors.  Since "new()" is a legal expression, my program has a special case to disallow "new".  If createExpression("new()") threw an exception, then I could remove the special case.

       

      Steps to Reproduce:

       

          @Test
          public void testNew() throws IOException {
              JexlEngine jexl = new JexlBuilder().create();
              try {
                  JexlExpression expression = jexl.createExpression("new()");
                  Assert.assertEquals("new()", expression.getParsedText());
              } catch (JexlException.Parsing exception) {
              }
          }
      

       

      What Happens:
      getParsedText() throws a NullPointerException.

      Expected Result:
      Either JexlEngine.createExpression() throws a JexlException.Parsing or expression.getParsedText() returns "new()".

      Note:
      This was found on JEXL 3.1, the latest official release. I reproduced it on a snapshot of JEXL 3.2 built from GitHub source.

       

      Attachments

        Issue Links

          Activity

            People

              henrib Henri Biestro
              david_costanzo David Costanzo
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m