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

Dmitri Blinov edited comment on JEXL-307 at 11/18/19 9:04 AM:
--------------------------------------------------------------

The problem is that by allowing lexical option to be dynamically 
enabled/disabled we are creating controversy that does not help in any way with 
initial intention of finding bugs. Consider the following, exaggerated and 
artificial, example
{code:java}
    @Test
    public void testLexicalOption() throws Exception {
        JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
        JexlEvalContext ctxt = new JexlEvalContext();
        JexlOptions options = ctxt.getEngineOptions();
        ctxt.set("options", options);
        JexlScript script = jexl.createScript("{var x = 42;} options.lexical = 
false; x");
        Object result = script.execute(ctxt);
        Assert.assertNull(result);
    }
 {code}
What should we expect as a result here? Until {{options.lexical = false}} we 
were in lexical mode, so one might think that once the block finished no 
variables should be visible and what't more critical - have any value. By 
allowing to change the mode on the fly, we are asking for trouble...

We may spend some more effort to try to fix this particular case, to allow 
lexical mode to coexist with non-lexical, but globally I think we should not 
mix the two. At least once we have parsed the script with lexical feature 
enabled, there is no point in allowing it to be disabled via options.


was (Author: dmitri_blinov):
The problem is that by allowing lexical option to be dynamically 
enabled/disabled we are creating controversy that does not help in any way with 
initial intention of finding bugs. Consider the following, exaggerated and 
artificial, example
{code:java}
    @Test
    public void testLexicalOption() throws Exception {
        JexlEngine jexl = new JexlBuilder().strict(true).lexical(true).create();
        JexlEvalContext ctxt = new JexlEvalContext();
        JexlOptions options = ctxt.getEngineOptions();
        ctxt.set("options", options);
        JexlScript script = jexl.createScript("{var x = 42;} options.lexical = 
false; x");
        Object result = script.execute(ctxt);
        Assert.assertNull(result);
    }
 {code}
What should we expect as a result here? Until {{options.lexical = false}} we 
were in lexical mode, so one might think that once the block finished no 
variables should be visible and what't more critical - have any value. By 
allowing to change the mode on the fly, we are asking for trouble...

We may spend some more effort to try to fix this particular case, to allow 
lexical mode to coexist with non-lexical, but globally I think we should not 
mix the two. At least once we parsed the script with lexical feature enabled, 
there is no point in allowing it to be disabled via options.

> Variable redeclaration option
> -----------------------------
>
>                 Key: JEXL-307
>                 URL: https://issues.apache.org/jira/browse/JEXL-307
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>            Reporter: Dmitri Blinov
>            Assignee: Henri Biestro
>            Priority: Minor
>             Fix For: 3.2
>
>
> As of now, JEXL allows a script writer to redeclare a local variable during 
> script evaluation.
> {code:java}
> var a = 1; var a = 2;{code}
> This may lead to potential errors with misspelled names and clashed 
> variables. Checking for already defined variable is a common feature of many 
> languages. This feature can be implemented in JEXL as an additional option of 
> JexlFeatures class, enabled by default, thus allowing compatibility with 
> existing code.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to