Author: sebb
Date: Wed Nov 30 23:20:45 2011
New Revision: 1208875

URL: http://svn.apache.org/viewvc?rev=1208875&view=rev
Log:
JEXL-83 Make JexlArithmetic immutable (and threadsafe)
Alternate solution, use volatile to make it conditionally threadsafe

Modified:
    
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
    
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlEngine.java

Modified: 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java?rev=1208875&r1=1208874&r2=1208875&view=diff
==============================================================================
--- 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
 (original)
+++ 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
 Wed Nov 30 23:20:45 2011
@@ -55,8 +55,10 @@ public class JexlArithmetic {
     /** Default BigDecimal scale. */
     protected static final int BIGD_SCALE = -1;
     /** Whether this JexlArithmetic instance behaves in strict or lenient 
mode. 
-     * DO NOT MODIFY - will be made final. */
-    protected boolean strict;
+     * @deprecated - do not access directly, may be made private later 
+     */
+    @Deprecated
+    protected volatile boolean strict;
     /** The big decimal math context. */
     protected final MathContext mathContext;
     /** The big decimal scale. */
@@ -1110,4 +1112,18 @@ public class JexlArithmetic {
         }
         return result;
     }
+
+    /**
+     * Sets whether this JexlArithmetic instance triggers errors during 
evaluation when
+     * null is used as an operand.
+     * <p>This method is thread safe, however using it whilst an expression is 
+     * currently being evaluated is not recommended.</p>
+     * @see JexlEngine#setLenient
+     * @see JexlEngine#setSilent
+     * @see JexlEngine#setDebug
+     * @param flag true means no JexlException will occur, false allows them
+     */
+    void setLenient(boolean flag) {
+        this.strict = !flag;
+    }
 }
\ No newline at end of file

Modified: 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlEngine.java
URL: 
http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=1208875&r1=1208874&r2=1208875&view=diff
==============================================================================
--- 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlEngine.java
 (original)
+++ 
commons/proper/jexl/branches/2.0-API-COMPAT/src/main/java/org/apache/commons/jexl2/JexlEngine.java
 Wed Nov 30 23:20:45 2011
@@ -156,10 +156,6 @@ public class JexlEngine {
      */
     protected boolean silent = false;
     /**
-     * Whether this engine is in lenient or strict mode; if unspecified, use 
the arithmetic lenient property.
-     */
-    protected Boolean strict = null;
-    /**
      * Whether error messages will carry debugging information.
      */
     protected boolean debug = true;
@@ -277,11 +273,12 @@ public class JexlEngine {
 
     /**
      * Sets whether this engine considers unknown variables, methods and 
constructors as errors or evaluates them
-     * as null.
-     * <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>As of 2.1, you need a JexlThreadedArithmetic instance for this call 
to also modify the JexlArithmetic
-     * leniency behavior.</p>
+     * as null or zero.
+     * <p>This method is <em>conditionally</em> thread safe.
+     * If a single JexlEngine is to be shared between threads, 
+     * it should only be called when the engine is not being used.</p>
+     * <p>As of 2.1, you can use 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
@@ -290,17 +287,16 @@ public class JexlEngine {
         if (arithmetic instanceof JexlThreadedArithmetic) {
             JexlThreadedArithmetic.setLenient(Boolean.valueOf(flag));
         } else {
-            strict = flag ? Boolean.FALSE : Boolean.TRUE;
+            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 arithmetic.isLenient();
     }
 
     /**


Reply via email to