[ 
https://issues.apache.org/jira/browse/JEXL-460?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18085259#comment-18085259
 ] 

David Costanzo edited comment on JEXL-460 at 6/1/26 4:18 PM:
-------------------------------------------------------------

Thanks, [~henrib].  After some quick testing of the workaround, it should world 
perfectly for my application.  It fixes "a{{{} ? a : my_function(b){}}}".  
"a{{{}?a:myfunction(b){}}}" (without spaces) isn't recognized as a ternary 
operator, but it also wasn't recognized as one in JEXL 3.3, so there's no 
compatibility risk for upgrading to JEXL 3.6.2.

Believe it or not, I had seen the "{{{}namespaceIdentifier(boolean){}}}" method 
and tried to fix this by setting it to {{{}false{}}}, as my application doesn't 
use namespaces.  I figured that I didn't want any namespace identifiers to be 
used, so I should disable them.  It never occurred to me to set it to {{true}} 
to stop "a{{{} : my_function(b){}}}" from being treated as a namespace function 
call.

By the way, my application disables namespaces like this:
{code:java}
JexlFeatures features = new JexlFeatures();
features.namespaceTest(x -> false); // disable function namespaces{code}


was (Author: david_costanzo):
Thanks, [~henrib].  After some quick testing of the workaround, it should world 
perfectly for my application.  It fixes "{{{}x ? x : my_function(y){}}}".  
"{{{}x?x:myfunction(y){}}}" (without spaces) isn't recognized as a ternary 
operator, but it also wasn't recognized as one in JEXL 3.3, so there's no 
compatibility risk for upgrading to JEXL 3.6.2.

Believe it or not, I had seen the "namespaceIdentifier(boolean)" method and 
tried to fix this by setting it to {{{}false{}}}, as my application doesn't use 
namespaces.  I figured that I didn't want any namespace identifiers to be used, 
so I should disable them.  It never occurred to me to set it to {{true}} to 
stop "{{{}x : my_function(y){}}}" from being treated as a namespace function 
call.

By the way, my application disables namespaces like this:
{code:java}
JexlFeatures features = new JexlFeatures();
features.namespaceTest(x -> false); // disable function namespaces{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)

Reply via email to