[
https://issues.apache.org/jira/browse/JEXL-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18084277#comment-18084277
]
Henri Biestro edited comment on JEXL-460 at 5/29/26 7:54 AM:
-------------------------------------------------------------
There is a workaround by setting the 'namespaceIdentifier' feature that
enforces that namespace calls should have no space between the namespace and
the function name, ie consider them as a dedicated type of identifier.
(JEXL-412)
{code:java}
@Test
void test346() {
JexlFeatures f = JexlFeatures.createDefault().namespaceIdentifier(true);
final JexlEngine jexl = new JexlBuilder().features(f).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}
Added illustrating test in
[62927f5a|https://github.com/apache/commons-jexl/commit/62927f5a1ab4cbefa1f16b93f6342a0175362417]
was (Author: henrib):
There is a workaround by setting the 'namespaceIdentifier' feature that
enforces that namespace calls should have no space between the namespace and
the function name, ie consider them as a dedicated type of identifier.
(JEXL-412)
{code:java}
@Test
void test346() {
JexlFeatures f = JexlFeatures.createDefault().namespaceIdentifier(true);
final JexlEngine jexl = new JexlBuilder().features(f).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}
> 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
> Assignee: Henri Biestro
> Priority: Minor
>
> 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)