David Costanzo created JEXL-324:
-----------------------------------
Summary: JexlEngine.createExpression("new()").getParsedText()
throws NPE
Key: JEXL-324
URL: https://issues.apache.org/jira/browse/JEXL-324
Project: Commons JEXL
Issue Type: Bug
Affects Versions: 3.1
Reporter: David Costanzo
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:*
{code:java}
@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) {
}
}
{code}
*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.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)