[ https://issues.apache.org/jira/browse/JEXL-324?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17025023#comment-17025023 ]
Henri Biestro commented on JEXL-324: ------------------------------------ Changeset: 1a304ae037c278ce2204989ecfdddf9ac449638c Author: henrib <hen...@apache.org> Date: 2020-01-28 11:26 Message: JEXL-324: refining parsing error reporting > 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 > Assignee: Henri Biestro > Priority: Minor > Fix For: 3.2 > > Time Spent: 10m > Remaining Estimate: 0h > > 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)