Author: henrib
Date: Fri Feb 18 14:06:47 2011
New Revision: 1072000
URL: http://svn.apache.org/viewvc?rev=1072000&view=rev
Log:
JEXL-83
Added:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
(with props)
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
commons/proper/jexl/trunk/src/site/xdoc/changes.xml
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/PublicFieldsTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlArithmetic.java
Fri Feb 18 14:06:47 2011
@@ -52,7 +52,7 @@ public class JexlArithmetic {
/** Long.MIN_VALUE as BigInteger. */
protected static final BigInteger BIGI_LONG_MIN_VALUE =
BigInteger.valueOf(Long.MIN_VALUE);
/** Whether this JexlArithmetic instance behaves in strict or lenient
mode. */
- private boolean strict;
+ protected final boolean strict;
/** The big decimal math context. */
protected final MathContext mathContext;
@@ -75,19 +75,6 @@ public class JexlArithmetic {
}
/**
- * Sets whether this JexlArithmetic instance triggers errors during
evaluation when
- * 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 &
evaluation.</p>
- * @see JexlEngine#setSilent
- * @see JexlEngine#setDebug
- * @param flag true means no JexlException will occur, false allows them
- */
- void setLenient(boolean flag) {
- this.strict = !flag;
- }
-
- /**
* Checks whether this JexlArithmetic instance triggers errors during
evaluation
* when null is used as an operand.
* @return true if lenient, false if strict
@@ -110,7 +97,7 @@ public class JexlArithmetic {
* @throws NullPointerException if strict
*/
protected Object controlNullNullOperands() {
- if (strict) {
+ if (!isLenient()) {
throw new NullPointerException(JexlException.NULL_OPERAND);
}
return Integer.valueOf(0);
@@ -121,7 +108,7 @@ public class JexlArithmetic {
* @throws NullPointerException if strict
*/
protected void controlNullOperand() {
- if (strict) {
+ if (!isLenient()) {
throw new NullPointerException(JexlException.NULL_OPERAND);
}
}
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
(original)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlEngine.java
Fri Feb 18 14:06:47 2011
@@ -216,6 +216,14 @@ public class JexlEngine {
}
/**
+ * Gets this engine underlying arithmetic.
+ * @return the arithmetic
+ */
+ public JexlArithmetic getArithmetic() {
+ return arithmetic;
+ }
+
+ /**
* Sets whether this engine reports debugging information when error
occurs.
* <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 & evaluation.</p>
@@ -265,7 +273,11 @@ public class JexlEngine {
* @param flag true means no JexlException will occur, false allows them
*/
public void setLenient(boolean flag) {
- this.arithmetic.setLenient(flag);
+ if (arithmetic instanceof JexlThreadedArithmetic) {
+ ((JexlThreadedArithmetic) arithmetic).setLenient(flag);
+ } else if (flag != isLenient()) {
+ logger.warn("setLenient only has an effect when using a
JexlThreadedArithmetic");
+ }
}
/**
Added:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java?rev=1072000&view=auto
==============================================================================
---
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
(added)
+++
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
Fri Feb 18 14:06:47 2011
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jexl2;
+
+/**
+ * A derived arithmetic that allows different threads to operate with
+ * different strict/lenient modes using the same JexlEngine.
+ */
+public class JexlThreadedArithmetic extends JexlArithmetic {
+ /** Whether this JexlArithmetic instance behaves in strict or lenient mode
for this thread. */
+ protected static final ThreadLocal<Boolean> lenient = new
ThreadLocal<Boolean>();
+
+ /**
+ * Standard ctor.
+ * @param lenient lenient versus strict evaluation flag
+ */
+ public JexlThreadedArithmetic(boolean lenient) {
+ super(lenient);
+ }
+
+ /**
+ * Overrides the default behavior and sets whether this JexlArithmetic
instance triggers errors
+ * during evaluation when null is used as an operand for the current
thread.
+ * <p>It is advised to protect calls by either calling
JexlThreadedArithmetic.setLenient explicitly before evaluation
+ * or add a try/finally clause resetting the flag to avoid unexpected
reuse of the lenient
+ * flag value through thread pools side-effects.</p>
+ * @see JexlEngine#setSilent
+ * @see JexlEngine#setDebug
+ * @param flag true means no JexlException will occur, false allows them,
null reverts to default behavior
+ */
+ public static void setLenient(Boolean flag) {
+ lenient.set(flag);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean isLenient() {
+ Boolean tl = lenient.get();
+ return tl == null? super.isLenient() : tl.booleanValue();
+ }
+}
Propchange:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl2/JexlThreadedArithmetic.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/proper/jexl/trunk/src/site/xdoc/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/site/xdoc/changes.xml?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/jexl/trunk/src/site/xdoc/changes.xml Fri Feb 18 14:06:47 2011
@@ -26,6 +26,12 @@
</properties>
<body>
<release version="2.0.2" date="unreleased">
+ <action dev="henrib" type="add" issue="JEXL-83" due-to="sebb">
+ Make JexlArithmetic immutable (and threadsafe)
+ </action>
+ <action dev="henrib" type="add" issue="JEXL-108" due-to="Cristian
Lorenzetto">
+ Parsing error if i define a empty literal array/map
+ </action>
<action dev="henrib" type="add" issue="JEXL-107" due-to="henrib">
Literals and parenthesized expressions can not be used as
references
</action>
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/ArithmeticTest.java
Fri Feb 18 14:06:47 2011
@@ -27,6 +27,10 @@ import org.apache.commons.jexl2.junit.As
public class ArithmeticTest extends JexlTestCase {
private Asserter asserter;
+ public ArithmeticTest() {
+ super(createThreadedArithmeticEngine(true));
+ }
+
@Override
public void setUp() {
asserter = new Asserter(JEXL);
@@ -256,12 +260,13 @@ public class ArithmeticTest extends Jexl
// number of permutations this will generate
final int PERMS = tnames.length * tnames.length;
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = this.createThreadedArithmeticEngine(true);
+ JexlThreadedArithmetic arith = (JexlThreadedArithmetic)
jexl.getArithmetic();
jexl.setCache(128);
jexl.setSilent(false);
// for non-silent, silent...
for (int s = 0; s < 2; ++s) {
- jexl.setLenient(s == 0);
+ arith.setLenient(s == 0);
int zthrow = 0;
int zeval = 0;
// for vars of all types...
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/AssignTest.java
Fri Feb 18 14:06:47 2011
@@ -23,10 +23,10 @@ package org.apache.commons.jexl2;
* @since 1.1
*/
public class AssignTest extends JexlTestCase {
- private static final JexlEngine ENGINE = new JexlEngine();
+ private static final JexlArithmetic ARITH = new JexlArithmetic(false);
+ private static final JexlEngine ENGINE = new JexlEngine(null, ARITH, null,
null);
static {
ENGINE.setSilent(false);
- ENGINE.setLenient(false);
}
public static class Froboz {
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/CacheTest.java
Fri Feb 18 14:06:47 2011
@@ -31,11 +31,10 @@ public class CacheTest extends JexlTestC
public CacheTest(String testName) {
super(testName);
}
- private static final JexlEngine jexl = new JexlEngine();
+ private static final JexlEngine jexl = createEngine(false);
static {
jexl.setCache(512);
- jexl.setLenient(false);
jexl.setSilent(false);
}
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IfTest.java
Fri Feb 18 14:06:47 2011
@@ -14,10 +14,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.commons.jexl2;
-
/**
* Test cases for the if statement.
*
@@ -25,7 +23,6 @@ package org.apache.commons.jexl2;
* @since 1.1
*/
public class IfTest extends JexlTestCase {
-
public IfTest(String testName) {
super(testName);
}
@@ -62,8 +59,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testSimpleElse() throws Exception {
- Expression e = JEXL
- .createExpression("if (false) 1 else 2;");
+ Expression e = JEXL.createExpression("if (false) 1 else 2;");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -76,8 +72,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testBlockIfTrue() throws Exception {
- Expression e = JEXL
- .createExpression("if (true) { 'hello'; }");
+ Expression e = JEXL.createExpression("if (true) { 'hello'; }");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -90,8 +85,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testBlockElse() throws Exception {
- Expression e = JEXL
- .createExpression("if (false) {1} else {2 ; 3}");
+ Expression e = JEXL.createExpression("if (false) {1} else {2 ; 3}");
JexlContext jc = new MapContext();
Object o = e.evaluate(jc);
@@ -104,8 +98,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithSimpleExpression() throws Exception {
- Expression e = JEXL
- .createExpression("if (x == 1) true;");
+ Expression e = JEXL.createExpression("if (x == 1) true;");
JexlContext jc = new MapContext();
jc.set("x", new Integer(1));
@@ -119,8 +112,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithArithmeticExpression() throws Exception {
- Expression e = JEXL
- .createExpression("if ((x * 2) + 1 == 5) true;");
+ Expression e = JEXL.createExpression("if ((x * 2) + 1 == 5) true;");
JexlContext jc = new MapContext();
jc.set("x", new Integer(2));
@@ -134,8 +126,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithDecimalArithmeticExpression() throws Exception {
- Expression e = JEXL
- .createExpression("if ((x * 2) == 5) true");
+ Expression e = JEXL.createExpression("if ((x * 2) == 5) true");
JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
@@ -149,8 +140,7 @@ public class IfTest extends JexlTestCase
* @throws Exception on any error
*/
public void testIfWithAssignment() throws Exception {
- Expression e = JEXL
- .createExpression("if ((x * 2) == 5) {y = 1} else {y = 2;}");
+ Expression e = JEXL.createExpression("if ((x * 2) == 5) {y = 1} else
{y = 2;}");
JexlContext jc = new MapContext();
jc.set("x", new Float(2.5f));
@@ -165,7 +155,7 @@ public class IfTest extends JexlTestCase
* @throws Exception
*/
public void testTernary() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createThreadedArithmeticEngine(true);
jexl.setCache(64);
JexlContext jc = new MapContext();
Expression e = jexl.createExpression("x.y.z = foo ?'bar':'quux'");
@@ -173,7 +163,7 @@ public class IfTest extends JexlTestCase
// undefined foo
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -184,7 +174,7 @@ public class IfTest extends JexlTestCase
jc.set("foo", null);
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -193,9 +183,9 @@ public class IfTest extends JexlTestCase
assertEquals("Should be quux", "quux", o);
}
- jc.set("foo",Boolean.FALSE);
+ jc.set("foo", Boolean.FALSE);
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -204,9 +194,9 @@ public class IfTest extends JexlTestCase
assertEquals("Should be quux", "quux", o);
}
- jc.set("foo",Boolean.TRUE);
+ jc.set("foo", Boolean.TRUE);
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -224,7 +214,7 @@ public class IfTest extends JexlTestCase
* @throws Exception
*/
public void testTernaryShorthand() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createThreadedArithmeticEngine(true);
jexl.setCache(64);
JexlContext jc = new MapContext();
Expression e = JEXL.createExpression("x.y.z = foo?:'quux'");
@@ -232,7 +222,7 @@ public class IfTest extends JexlTestCase
// undefined foo
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -243,7 +233,7 @@ public class IfTest extends JexlTestCase
jc.set("foo", null);
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -254,7 +244,7 @@ public class IfTest extends JexlTestCase
jc.set("foo", Boolean.FALSE);
- for(int l = 0; l < 4; ++l) {
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
@@ -263,9 +253,9 @@ public class IfTest extends JexlTestCase
assertEquals("Should be quux", "quux", o);
}
- jc.set("foo","bar");
-
- for(int l = 0; l < 4; ++l) {
+ jc.set("foo", "bar");
+
+ for (int l = 0; l < 4; ++l) {
jexl.setLenient((l & 1) != 0);
jexl.setSilent((l & 2) != 0);
o = e.evaluate(jc);
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/IssuesTest.java
Fri Feb 18 14:06:47 2011
@@ -150,7 +150,7 @@ public class IssuesTest extends JexlTest
// JEXL-52: can be implemented by deriving Interpreter.{g,s}etAttribute;
later
public void test52base() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
Uberspect uber = jexl.getUberspect();
// most likely, call will be in an Interpreter, getUberspect
String[] names = ((Introspector) uber).getMethodNames(Another.class);
@@ -176,10 +176,9 @@ public class IssuesTest extends JexlTest
// JEXL-10/JEXL-11: variable checking, null operand is error
public void test11() throws Exception {
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
// ensure errors will throw
jexl.setSilent(false);
- jexl.setLenient(false);
JexlContext ctxt = new MapContext();
ctxt.set("a", null);
@@ -204,7 +203,7 @@ public class IssuesTest extends JexlTest
// JEXL-62
public void test62() throws Exception {
JexlContext ctxt;
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
jexl.setSilent(true); // to avoid throwing JexlException on null
method call
Script jscript;
@@ -235,9 +234,8 @@ public class IssuesTest extends JexlTest
// JEXL-73
public void test73() throws Exception {
JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
jexl.setSilent(false);
- jexl.setLenient(false);
Expression e;
e = jexl.createExpression("c.e");
try {
@@ -261,9 +259,8 @@ public class IssuesTest extends JexlTest
// JEXL-87
public void test87() throws Exception {
JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
jexl.setSilent(false);
- jexl.setLenient(false);
Expression divide = jexl.createExpression("l / r");
Expression modulo = jexl.createExpression("l % r");
@@ -281,9 +278,8 @@ public class IssuesTest extends JexlTest
// JEXL-90
public void test90() throws Exception {
JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
jexl.setSilent(false);
- jexl.setLenient(false);
jexl.setCache(16);
// ';' is necessary between expressions
String[] fexprs = {
@@ -321,9 +317,8 @@ public class IssuesTest extends JexlTest
// JEXL-44
public void test44() throws Exception {
JexlContext ctxt = new MapContext();
- JexlEngine jexl = new JexlEngine();
+ JexlEngine jexl = createEngine(false);
jexl.setSilent(false);
- jexl.setLenient(false);
Script script;
script = jexl.createScript("'hello world!'//commented");
assertEquals("hello world!", script.execute(ctxt));
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/JexlTestCase.java
Fri Feb 18 14:06:47 2011
@@ -64,6 +64,14 @@ public class JexlTestCase extends TestCa
protected void tearDown() throws Exception {
debuggerCheck(JEXL);
}
+
+ public static JexlEngine createEngine(boolean lenient) {
+ return new JexlEngine(null, new JexlArithmetic(lenient), null, null);
+ }
+
+ public static JexlEngine createThreadedArithmeticEngine(boolean lenient) {
+ return new JexlEngine(null, new JexlThreadedArithmetic(lenient), null,
null);
+ }
/**
* Will force testing the debugger for each derived test class by
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/PublicFieldsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/PublicFieldsTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/PublicFieldsTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/PublicFieldsTest.java
Fri Feb 18 14:06:47 2011
@@ -45,7 +45,7 @@ public class PublicFieldsTest extends Je
private JexlContext ctxt;
public PublicFieldsTest() {
- JEXL.setLenient(false);
+ super(createEngine(false));
}
@Override
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/UnifiedJEXLTest.java
Fri Feb 18 14:06:47 2011
@@ -23,9 +23,8 @@ import org.apache.commons.logging.LogFac
* Test cases for the UnifiedEL.
*/
public class UnifiedJEXLTest extends JexlTestCase {
- private static final JexlEngine ENGINE = new JexlEngine();
+ private static final JexlEngine ENGINE = createEngine(false);
static {
- ENGINE.setLenient(false);
ENGINE.setSilent(false);
ENGINE.setCache(128);
}
Modified:
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java
URL:
http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java?rev=1072000&r1=1071999&r2=1072000&view=diff
==============================================================================
---
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java
(original)
+++
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl2/junit/Asserter.java
Fri Feb 18 14:06:47 2011
@@ -27,6 +27,7 @@ import org.apache.commons.jexl2.JexlCont
import org.apache.commons.jexl2.MapContext;
import org.apache.commons.jexl2.JexlEngine;
import org.apache.commons.jexl2.JexlException;
+import org.apache.commons.jexl2.JexlThreadedArithmetic;
/**
* A utility class for performing JUnit based assertions using Jexl
@@ -98,7 +99,9 @@ public class Asserter extends Assert {
public void failExpression(String expression, String matchException)
throws Exception {
boolean[] flags = { engine.isLenient(), engine.isSilent() };
try {
- engine.setLenient(false);
+ if (engine.getArithmetic() instanceof JexlThreadedArithmetic) {
+ engine.setLenient(false);
+ }
engine.setSilent(false);
Expression exp = engine.createExpression(expression);
exp.evaluate(context);
@@ -108,7 +111,9 @@ public class Asserter extends Assert {
fail("expression: " + expression + ", expected: " +
matchException + ", got " + xjexl.getMessage());
}
} finally {
- engine.setLenient(flags[0]);
+ if (engine.getArithmetic() instanceof JexlThreadedArithmetic) {
+ engine.setLenient(flags[0]);
+ }
engine.setSilent(flags[1]);
}
}