You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by he...@apache.org on 2020/01/16 13:39:32 UTC

[commons-jexl] branch master updated (9d18983 -> 12146f6)

This is an automated email from the ASF dual-hosted git repository.

henrib pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git.


    from 9d18983  JEXL-307: refactored test Task #JEXL-307 - Variable redeclaration option
     new bff5feb  JEXL-318: added copy constructor Task #JEXL-318 - Annotation processing may fail in lexical mode
     new 8f78f45  JEXL-307: better detection of shaded variables Task #JEXL-307 - Variable redeclaration option
     new 1eefeb5  JEXL-318: test Task #JEXL-318 - Annotation processing may fail in lexical mode
     new 12146f6  JEXL-318: release notes and changes Task #JEXL-318 - Annotation processing may fail in lexical mode

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 RELEASE-NOTES.txt                                  |  1 +
 .../apache/commons/jexl3/internal/Interpreter.java |  4 +--
 .../commons/jexl3/internal/InterpreterBase.java    | 42 ++++++++++++++--------
 .../commons/jexl3/internal/LexicalFrame.java       | 10 ++++++
 .../commons/jexl3/internal/LexicalScope.java       | 14 +++++++-
 src/site/xdoc/changes.xml                          |  3 ++
 .../java/org/apache/commons/jexl3/LexicalTest.java | 41 +++++++++++++++++++++
 7 files changed, 98 insertions(+), 17 deletions(-)


[commons-jexl] 03/04: JEXL-318: test Task #JEXL-318 - Annotation processing may fail in lexical mode

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit 1eefeb59e3f0d52aa011c29b1e18eee18e841049
Author: henrib <he...@apache.org>
AuthorDate: Thu Jan 16 14:36:34 2020 +0100

    JEXL-318: test
    Task #JEXL-318 - Annotation processing may fail in lexical mode
---
 .../java/org/apache/commons/jexl3/LexicalTest.java | 41 ++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/src/test/java/org/apache/commons/jexl3/LexicalTest.java b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
index e1b2954..699f70a 100644
--- a/src/test/java/org/apache/commons/jexl3/LexicalTest.java
+++ b/src/test/java/org/apache/commons/jexl3/LexicalTest.java
@@ -22,6 +22,7 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;
 import org.apache.commons.jexl3.internal.LexicalScope;
 import org.apache.commons.jexl3.internal.Script;
 import org.junit.Assert;
@@ -649,10 +650,19 @@ public class LexicalTest {
                 + "for (var i : count) {\n"
                 + "  $out.add(i);\n"
                 + "}";
+        String src2 = "var count = 10;\n" +
+                "  var outer = 0;\n"
+                + "for (var i : 0 .. count-1) {\n"
+                + "  $out.add(i);\n"
+                + "  outer = i;"
+                + "}\n"
+                + "outer == 9";
         JexlFeatures ff0 = runVarLoop(false, src0);
         JexlFeatures ft0= runVarLoop(true, src0);
         JexlFeatures ff1 = runVarLoop(false, src1);
         JexlFeatures ft1= runVarLoop(true, src1);
+        JexlFeatures ff2 = runVarLoop(false, src2);
+        JexlFeatures ft2= runVarLoop(true, src2);
         
         // and check some features features
         Assert.assertEquals(ff0, ff1);
@@ -688,4 +698,35 @@ public class LexicalTest {
             throw xany;
         }
     }
+    
+    public static class OptAnnotationContext extends JexlEvalContext implements JexlContext.AnnotationProcessor {
+        @Override
+        public Object processAnnotation(String name, Object[] args, Callable<Object> statement) throws Exception {
+            // transient side effect for strict
+            if ("scale".equals(name)) {
+                JexlOptions options = this.getEngineOptions();
+                int scale = options.getMathScale();
+                int newScale = (Integer) args[0];
+                options.setMathScale(newScale);
+                try {
+                    return statement.call();
+                } finally {
+                    options.setMathScale(scale);
+                }
+            }
+            return statement.call();
+        }
+    }
+    
+    @Test
+    public void testAnnotation() throws Exception {
+        JexlFeatures f = new JexlFeatures();
+        f.lexical(true);
+        JexlEngine jexl = new JexlBuilder().strict(true).features(f).create();
+        JexlScript script = jexl.createScript("@scale(13) @test var i = 42");
+        JexlContext jc = new OptAnnotationContext();
+        Object result = script.execute(jc);
+        Assert.assertEquals(result, 42);
+    }
+ 
 }


[commons-jexl] 04/04: JEXL-318: release notes and changes Task #JEXL-318 - Annotation processing may fail in lexical mode

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit 12146f65fca5c24ac276c82e08b2ee52b3209225
Author: henrib <he...@apache.org>
AuthorDate: Thu Jan 16 14:38:59 2020 +0100

    JEXL-318: release notes and changes
    Task #JEXL-318 - Annotation processing may fail in lexical mode
---
 RELEASE-NOTES.txt         | 1 +
 src/site/xdoc/changes.xml | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 23ce03f..7950413 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -74,6 +74,7 @@ New Features in 3.2:
 
 Bugs Fixed in 3.2:
 ==================
+* JEXL-318:      Annotation processing may fail in lexical mode
 * JEXL-315:      JxltEngine literal string strings ending in \ $ or # throw JxltEngine$Exception
 * JEXL-314:      Comparison NULL values of variables NAME1.NAME2
 * JEXL-312:      @NoJexl fails to disallow method call
diff --git a/src/site/xdoc/changes.xml b/src/site/xdoc/changes.xml
index 7ecbf0c..20480fd 100644
--- a/src/site/xdoc/changes.xml
+++ b/src/site/xdoc/changes.xml
@@ -26,6 +26,9 @@
     </properties>
     <body>
         <release version="3.2" date="unreleased">
+            <action dev="henrib" type="fix" issue="JEXL-318" due-to="Dmitri Blinov">
+                Annotation processing may fail in lexical mode
+            </action>
             <action dev="henrib" type="add" issue="JEXL-317">
                 Support script cancellation through less invasive API
             </action>


[commons-jexl] 02/04: JEXL-307: better detection of shaded variables Task #JEXL-307 - Variable redeclaration option

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit 8f78f4580341ca2edf17c0eae1cf9f36f39c28f5
Author: henrib <he...@apache.org>
AuthorDate: Thu Jan 16 14:35:47 2020 +0100

    JEXL-307: better detection of shaded variables
    Task #JEXL-307 - Variable redeclaration option
---
 .../apache/commons/jexl3/internal/Interpreter.java |  4 +--
 .../commons/jexl3/internal/InterpreterBase.java    | 42 ++++++++++++++--------
 2 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
index dac5b49..563877f 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
@@ -149,6 +149,7 @@ public class Interpreter extends InterpreterBase {
     protected Interpreter(Interpreter ii, JexlArithmetic jexla) {
         super(ii, jexla);
         frame = ii.frame;
+        block = ii.block != null? new LexicalFrame(ii.block) : null;
     }
 
     /**
@@ -1311,8 +1312,7 @@ public class Interpreter extends InterpreterBase {
                     if (!block.declareSymbol(symbol)) {
                         return redefinedVariable(var, var.getName());
                     }
-                // if not in lexical block, undefined if (in its symbol) shade
-                } else if (!block.hasSymbol(symbol) && options.isLexicalShade()) {
+                } else if (isSymbolShaded(symbol, block)) { 
                     return undefinedVariable(var, var.getName());
                 }
             }
diff --git a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
index 75b2d12..97c936d 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/InterpreterBase.java
@@ -69,12 +69,12 @@ public abstract class InterpreterBase extends ParserVisitor {
     protected static final Object[] EMPTY_PARAMS = new Object[0];
     /** The context to store/retrieve variables. */
     protected final JexlContext.NamespaceResolver ns;
+    /** The operators evaluation delegate. */
+    protected final Operators operators;
     /** The map of 'prefix:function' to object resolving as namespaces. */
     protected final Map<String, Object> functions;
     /** The map of dynamically creates namespaces, NamespaceFunctor or duck-types of those. */
     protected Map<String, Object> functors;
-    /** The operators evaluation delegate. */
-    protected final Operators operators;
     
     /**
      * Creates an interpreter base.
@@ -120,15 +120,15 @@ public abstract class InterpreterBase extends ParserVisitor {
         jexl = ii.jexl;
         logger = ii.logger;
         uberspect = ii.uberspect;
+        arithmetic = jexla;
         context = ii.context;
-        arithmetic = ii.arithmetic;
+        options = ii.options.copy();
         cache = ii.cache;
         ns = ii.ns;
+        operators = ii.operators;
         cancelled = ii.cancelled;
         functions = ii.functions;
         functors = ii.functors;
-        operators = ii.operators;
-        options = ii.options.copy();
     }
 
 
@@ -243,6 +243,27 @@ public abstract class InterpreterBase extends ParserVisitor {
     }
 
     /**
+     * Checks whether a symbol is a shade or actually accessible.
+     * @param symbol the symbol
+     * @param block the block to check from (canoot be null)
+     * @return true is symbol is just a shade, false otherwise
+     */
+    protected boolean isSymbolShaded(int symbol, LexicalScope block) {
+        if (!options.isLexicalShade()) {
+            return false;
+        }
+        // if not in lexical block, undefined if (in its symbol) shade
+        LexicalScope b = block;
+        while (b != null) {
+            if (b.hasSymbol(symbol)) {
+                return false;
+            }
+            b = b.previous;
+        }
+        return true;
+    }
+    
+    /**
      * Gets a value of a defined local variable or from the context.
      * @param frame the local frame
      * @param block the lexical block if any
@@ -254,15 +275,8 @@ public abstract class InterpreterBase extends ParserVisitor {
         // if we have a symbol, we have a scope thus a frame
         if (symbol >= 0) {
             if (frame.has(symbol)) {
-                if (options.isLexical() && options.isLexicalShade()) {
-                    // if not in lexical block, undefined if (in its symbol) shade
-                    LexicalScope b = block;
-                    while(b != null && !b.hasSymbol(symbol)) {
-                        b = b.previous;
-                    }
-                    if (b == null) {
-                        return undefinedVariable(identifier, identifier.getName());
-                    }
+                if (options.isLexical() && isSymbolShaded(symbol, block)) {
+                    return undefinedVariable(identifier, identifier.getName());
                 }
                 Object value = frame.get(symbol);
                 if (value != Scope.UNDEFINED) {


[commons-jexl] 01/04: JEXL-318: added copy constructor Task #JEXL-318 - Annotation processing may fail in lexical mode

Posted by he...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

henrib pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jexl.git

commit bff5feb4e5680d8932155634e3adf989c8f17d8e
Author: henrib <he...@apache.org>
AuthorDate: Thu Jan 16 14:34:22 2020 +0100

    JEXL-318: added copy constructor
    Task #JEXL-318 - Annotation processing may fail in lexical mode
---
 .../org/apache/commons/jexl3/internal/LexicalFrame.java    | 10 ++++++++++
 .../org/apache/commons/jexl3/internal/LexicalScope.java    | 14 +++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java b/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
index 4af5bff..6bb5f1e 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/LexicalFrame.java
@@ -37,6 +37,16 @@ public class LexicalFrame extends LexicalScope {
         super(previous);
         this.frame = scriptf;
     }
+    
+    /**
+     * Copy ctor.
+     * @param src the frame to copy
+     */
+    public LexicalFrame(LexicalFrame src) {
+        super(src.symbols, src.moreSymbols, src.previous);
+        frame = src.frame;
+        stack = src.stack != null? new ArrayDeque<Object>(src.stack) : null;
+    }
 
     /**
      * Declare the arguments.
diff --git a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
index 3ab83ad..bc2b6a8 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/LexicalScope.java
@@ -40,12 +40,24 @@ public class LexicalScope {
     public LexicalScope(LexicalScope scope) {
         previous = scope;
     }
+        
+    /**
+     * Frame copy ctor base.
+     * @param s the symbols mask
+     * @param ms the more symbols bitset
+     * @param pscope the previous scope
+     */
+    protected LexicalScope(long s, BitSet ms, LexicalScope pscope) {
+        previous = pscope;
+        symbols = s;
+        moreSymbols = ms != null? (BitSet) ms.clone() : null;
+    }
 
     /**
      * Ensure more symbpls can be stored.
      * @return the set of more symbols
      */
-    final BitSet moreSymbols() {
+    protected final BitSet moreSymbols() {
         if (moreSymbols == null) {
             moreSymbols = new BitSet();
         }