David Costanzo created JEXL-460:
-----------------------------------
Summary: namespace function syntax leads to strange error for
"common case" of ternary operator -- regression
Key: JEXL-460
URL: https://issues.apache.org/jira/browse/JEXL-460
Project: Commons JEXL
Issue Type: Bug
Affects Versions: 3.6.2
Reporter: David Costanzo
Note: This is a duplicate of JEXL-346. The bug was fixed in 3.2 and worked in
3.3, but doesn't work in 3.6.2. I don't know if you prefer that I reopen the
old bug or create a new one, so I have created a new one.
The bug is that, if you have a ternary operator and the "else clause" is a
function call, you get a parse error when creating the script. For example,
parsing
{noformat}
x != null ? x : my_function(y){noformat}
throws
{noformat}
org.apache.commons.jexl3.JexlException$Parsing:
org.apache.commons.jexl3.Issues300Test.test346:771@1:30 parsing error in ')'
{noformat}
Enclosing the "else clause" in parens fixes the problem.
Here is a unit test that I had written for JEXL-346, which you can paste into
Issues300Test.
{code:java}
@Test
void test346() {
final JexlEngine jexl = new JexlBuilder().create();
final JexlContext jc = new MapContext();
jc.set("x", 1);
jc.set("y", 2);
jc.set("my_function", jexl.createScript("(a) -> { a * 1000 }"));
final JexlScript script = jexl.createScript("x != null ? x :
my_function(y)");
final Object result = script.execute(jc);
assertEquals(1, result, "Result is not x");
} {code}
I can submit a PR to add the test case if you prefer.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)