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 2021/06/03 15:41:53 UTC

[commons-jexl] 10/19: Binary compatibilty fixes

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

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

commit bb1ad4ca98f37da19004b68fe8a8aff9a2341497
Author: Sebastian Bazley <se...@apache.org>
AuthorDate: Fri Dec 2 22:12:42 2011 +0000

    Binary compatibilty fixes
    
    git-svn-id: https://svn-us.apache.org/repos/asf/commons/proper/jexl/branches/2.0@1209727 13f79535-47bb-0310-9956-ffa450edef68
---
 .../java/org/apache/commons/jexl2/Interpreter.java | 22 +++++++-
 .../org/apache/commons/jexl2/JexlArithmetic.java   | 10 ++--
 .../java/org/apache/commons/jexl2/JexlEngine.java  | 59 +++++++++++++++++-----
 .../java/org/apache/commons/jexl2/UnifiedJEXL.java |  9 ++--
 4 files changed, 77 insertions(+), 23 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl2/Interpreter.java b/src/main/java/org/apache/commons/jexl2/Interpreter.java
index da0cfd4..25b4fc8 100644
--- a/src/main/java/org/apache/commons/jexl2/Interpreter.java
+++ b/src/main/java/org/apache/commons/jexl2/Interpreter.java
@@ -27,6 +27,8 @@ import java.util.Set;
 import org.apache.commons.jexl2.parser.SimpleNode;
 import org.apache.commons.logging.Log;
 
+import org.apache.commons.jexl2.parser.ASTFloatLiteral;
+import org.apache.commons.jexl2.parser.ASTIntegerLiteral;
 import org.apache.commons.jexl2.parser.JexlNode;
 import org.apache.commons.jexl2.parser.ASTAdditiveNode;
 import org.apache.commons.jexl2.parser.ASTAdditiveOperator;
@@ -103,9 +105,9 @@ public class Interpreter implements ParserVisitor {
     protected Map<String, Object> functors;
     /** The context to store/retrieve variables. */
     protected final JexlContext context;
-    /** Strict interpreter flag. Do not modify; will be made final in a later version. */
+    /** Strict interpreter flag. Do not modify; will be made final/private in a later version. */
     protected boolean strict;
-    /** Silent intepreter flag.  Do not modify; will be made final in a later version. */
+    /** Silent intepreter flag.  Do not modify; will be made final/private in a later version. */
     protected boolean silent;
     /** Cache executors. */
     protected final boolean cache;
@@ -879,6 +881,22 @@ public class Interpreter implements ParserVisitor {
         }
     }
 
+    /**
+     * @deprecated Do not use
+     */
+    @Deprecated
+    public Object visit(ASTFloatLiteral node, Object data) {
+        throw new UnsupportedOperationException("Method should not be called; only present for API compatibiltiy");
+    }
+
+    /**
+     * @deprecated Do not use
+     */
+    @Deprecated
+    public Object visit(ASTIntegerLiteral node, Object data) {
+        throw new UnsupportedOperationException("Method should not be called; only present for API compatibiltiy");
+    }
+
     /** {@inheritDoc} */
     public Object visit(ASTVar node, Object data) {
         return visit((ASTIdentifier) node, data);
diff --git a/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java b/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
index ef821a9..0149bb3 100644
--- a/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
@@ -57,9 +57,10 @@ public class JexlArithmetic {
      * @since 2.1 
      */
     protected static final int BIGD_SCALE = -1;
-    /** Whether this JexlArithmetic instance behaves in strict or lenient mode. */
-    /** @deprecated : will become final in next version. */
-    protected boolean strict;
+    /** Whether this JexlArithmetic instance behaves in strict or lenient mode.
+     * May be made final in a later version.
+     */
+    private volatile boolean strict;
     /** 
      * The big decimal math context.
      * @since 2.1 
@@ -98,10 +99,11 @@ public class JexlArithmetic {
      * null is used as an operand.
      * <p>This method is <em>not</em> thread safe; it may be called as an optional step by the JexlEngine
      * in its initialization code before expression creation &amp; evaluation.</p>
+     * @see JexlEngine#setLenient
      * @see JexlEngine#setSilent
      * @see JexlEngine#setDebug
      * @param flag true means no JexlException will occur, false allows them
-     * @deprecated as of 2.1
+     * @deprecated as of 2.1 - may be removed in a later release
      */
     @Deprecated
     void setLenient(boolean flag) {
diff --git a/src/main/java/org/apache/commons/jexl2/JexlEngine.java b/src/main/java/org/apache/commons/jexl2/JexlEngine.java
index bcbd460..2ee9699 100644
--- a/src/main/java/org/apache/commons/jexl2/JexlEngine.java
+++ b/src/main/java/org/apache/commons/jexl2/JexlEngine.java
@@ -154,23 +154,22 @@ public class JexlEngine {
      * Whether expressions evaluated by this engine will throw exceptions (false) or 
      * return null (true) on errors. Default is false.
      */
-    protected boolean silent = false;
-    /**
-     * Whether this engine is in lenient or strict mode; if unspecified, use the arithmetic lenient property.
-     * Provision for version after 2.1.
-     */
-    // protected Boolean strict = null;
+    // TODO could this be private?
+    protected volatile boolean silent = false;
     /**
      * Whether error messages will carry debugging information.
      */
-    protected boolean debug = true;
+    // TODO could this be private?
+    protected volatile boolean debug = true;
     /**
      *  The map of 'prefix:function' to object implementing the functions.
      */
+    // TODO this could probably be private; is it threadsafe?
     protected Map<String, Object> functions = Collections.emptyMap();
     /**
      * The expression cache.
      */
+    // TODO is this thread-safe? Could it be made private?
     protected SoftCache<String, ASTJexlScript> cache = null;
     /**
      * The default cache load factor.
@@ -279,11 +278,11 @@ public class JexlEngine {
     
     /**
      * Sets whether this engine considers unknown variables, methods and constructors as errors or evaluates them
-     * as null.
+     * as null or zero.
      * <p>This method is <em>not</em> thread safe; it should be called as an optional step of the JexlEngine
      * initialization code before expression creation &amp; evaluation.</p>
-     * <p>After 2.1, you will need a JexlThreadedArithmetic instance for this call to also modify the JexlArithmetic
-     * leniency behavior.</p>
+     * <p>As of 2.1, you can use a JexlThreadedArithmetic instance to allow the JexlArithmetic
+     * leniency behavior to be independently specified per thread, whilst still using a single engine.</p>
      * @see JexlEngine#setSilent
      * @see JexlEngine#setDebug
      * @param flag true means no JexlException will occur, false allows them
@@ -293,24 +292,23 @@ public class JexlEngine {
         if (arithmetic instanceof JexlThreadedArithmetic) {
             JexlThreadedArithmetic.setLenient(Boolean.valueOf(flag));
         } else {
-            //strict = flag ? Boolean.FALSE : Boolean.TRUE;
             this.arithmetic.setLenient(flag);
         }
     }
 
     /**
      * Checks whether this engine considers unknown variables, methods and constructors as errors.
-     * <p>If not explicitly set, the arithmetic leniency value applies.</p>
      * @return true if lenient, false if strict
      */
     public boolean isLenient() {
-        //return strict == null ? arithmetic.isLenient() : !strict.booleanValue();
-        return this.arithmetic.isLenient();
+        return arithmetic.isLenient();
     }
 
     /**
      * Sets whether this engine behaves in strict or lenient mode.
      * Equivalent to setLenient(!flag).
+     * <p>This method is <em>not</em> thread safe; it should be called as an optional step of the JexlEngine
+     * initialization code before expression creation &amp; evaluation.</p>
      * @param flag true for strict, false for lenient
      * @since 2.1
      */
@@ -459,6 +457,26 @@ public class JexlEngine {
      * This method parses the script which validates the syntax.
      *
      * @param scriptText A String containing valid JEXL syntax
+     * @param info An info structure to carry debugging information if needed
+     * @return A {@link Script} which can be executed using a {@link JexlContext}.
+     * @throws JexlException if there is a problem parsing the script.
+     * @deprecated Use {@link #createScript(String, JexlInfo, String[])}
+     */
+    @Deprecated
+    public Script createScript(String scriptText, JexlInfo info) {
+        if (scriptText == null) {
+            throw new NullPointerException("scriptText is null");
+        }
+        // Parse the expression
+        ASTJexlScript tree = parse(scriptText, info);
+        return createScript(tree, scriptText);
+    }
+
+    /**
+     * Creates a Script from a String containing valid JEXL syntax.
+     * This method parses the script which validates the syntax.
+     *
+     * @param scriptText A String containing valid JEXL syntax
      * @param names the script parameter names
      * @return A {@link Script} which can be executed using a {@link JexlContext}.
      * @throws JexlException if there is a problem parsing the script.
@@ -1187,6 +1205,19 @@ public class JexlEngine {
      * Parses an expression.
      * @param expression the expression to parse
      * @param info debug information structure
+     * @return the parsed tree
+     * @throws JexlException if any error occured during parsing
+     * @deprecated Use {@link #parse(CharSequence, JexlInfo, Scope)} instead
+     */
+    @Deprecated
+    protected ASTJexlScript parse(CharSequence expression, JexlInfo info) {
+        return parse(expression, info, null);
+    }
+
+    /**
+     * Parses an expression.
+     * @param expression the expression to parse
+     * @param info debug information structure
      * @param frame the script frame to use
      * @return the parsed tree
      * @throws JexlException if any error occured during parsing
diff --git a/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java b/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
index af2d0b2..13b9183 100644
--- a/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
+++ b/src/main/java/org/apache/commons/jexl2/UnifiedJEXL.java
@@ -276,10 +276,11 @@ public final class UnifiedJEXL {
         /**
          * Formats this expression, adding its source string representation in
          * comments if available: 'expression /*= source *\/'' .
+         * <b>Note:</b> do not override; will be made final in a future release.
          * @return the formatted expression string
          */
         @Override
-        public final String toString() {
+        public String toString() {
             StringBuilder strb = new StringBuilder();
             asString(strb);
             if (source != this) {
@@ -343,11 +344,12 @@ public final class UnifiedJEXL {
          * <p>
          * If the underlying JEXL engine is silent, errors will be logged through its logger as warning.
          * </p>
+         * <b>Note:</b> do not override; will be made final in a future release.
          * @param context the context to use for immediate expression evaluations
          * @return an expression or null if an error occurs and the {@link JexlEngine} is running in silent mode
          * @throws UnifiedJEXL.Exception if an error occurs and the {@link JexlEngine} is not in silent mode
          */
-        public final Expression prepare(JexlContext context) {
+        public Expression prepare(JexlContext context) {
             try {
                 Interpreter interpreter = new Interpreter(jexl, context, !jexl.isLenient(), jexl.isSilent());
                 if (context instanceof TemplateContext) {
@@ -369,12 +371,13 @@ public final class UnifiedJEXL {
          * <p>
          * If the underlying JEXL engine is silent, errors will be logged through its logger as warning.
          * </p>
+         * <b>Note:</b> do not override; will be made final in a future release.
          * @param context the variable context
          * @return the result of this expression evaluation or null if an error occurs and the {@link JexlEngine} is
          * running in silent mode
          * @throws UnifiedJEXL.Exception if an error occurs and the {@link JexlEngine} is not silent
          */
-        public final Object evaluate(JexlContext context) {
+        public Object evaluate(JexlContext context) {
             try {
                 Interpreter interpreter = new Interpreter(jexl, context, !jexl.isLenient(), jexl.isSilent());
                 if (context instanceof TemplateContext) {