[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-commons-dev
Subject: svn commit: r1758541 - in /commons/proper/jexl/trunk/src: main/java/org/apache/commons/jexl3/interna
From: henrib () apache ! org
Date: 2016-08-31 8:03:57
Message-ID: 20160831080358.4D5153A0DCF () svn01-us-west ! apache ! org
[Download RAW message or body]
Author: henrib
Date: Wed Aug 31 08:03:57 2016
New Revision: 1758541
URL: http://svn.apache.org/viewvc?rev=1758541&view=rev
Log:
JEXL-217: protect tryInvoke in the same try/catch as invoke
Modified:
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/c \
ommons/jexl3/internal/Interpreter.java?rev=1758541&r1=1758540&r2=1758541&view=diff \
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java \
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Interpreter.java \
Wed Aug 31 08:03:57 2016 @@ -1701,37 +1701,37 @@ public class Interpreter extends \
Interpr throw new JexlException.Cancel(node);
}
final JexlOperator operator = node != null && node.jjtGetParent() instanceof \
ASTArrayAccess
- ? JexlOperator.ARRAY_GET : \
JexlOperator.PROPERTY_GET; + ? JexlOperator.ARRAY_GET : \
JexlOperator.PROPERTY_GET;
Object result = operators.tryOverload(node, operator, object, attribute);
if (result != JexlEngine.TRY_FAILED) {
return result;
}
- // attempt to reuse last executor cached in volatile JexlNode.value
- if (node != null && cache) {
- Object cached = node.jjtGetValue();
- if (cached instanceof JexlPropertyGet) {
- JexlPropertyGet vg = (JexlPropertyGet) cached;
- Object value = vg.tryInvoke(object, attribute);
- if (!vg.tryFailed(value)) {
- return value;
+ Exception xcause = null;
+ try {
+ // attempt to reuse last executor cached in volatile JexlNode.value
+ if (node != null && cache) {
+ Object cached = node.jjtGetValue();
+ if (cached instanceof JexlPropertyGet) {
+ JexlPropertyGet vg = (JexlPropertyGet) cached;
+ Object value = vg.tryInvoke(object, attribute);
+ if (!vg.tryFailed(value)) {
+ return value;
+ }
}
}
- }
- // resolve that property
- Exception xcause = null;
- List<PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
- JexlPropertyGet vg = uberspect.getPropertyGet(resolvers, object, attribute);
- if (vg != null) {
- try {
+ // resolve that property
+ List<PropertyResolver> resolvers = uberspect.getResolvers(operator, \
object); + JexlPropertyGet vg = uberspect.getPropertyGet(resolvers, \
object, attribute); + if (vg != null) {
Object value = vg.invoke(object);
// cache executor in volatile JexlNode.value
if (node != null && cache && vg.isCacheable()) {
node.jjtSetValue(vg);
}
return value;
- } catch (Exception xany) {
- xcause = xany;
}
+ } catch (Exception xany) {
+ xcause = xany;
}
// lets fail
if (node != null) {
@@ -1775,39 +1775,39 @@ public class Interpreter extends Interpr
if (result != JexlEngine.TRY_FAILED) {
return;
}
- // attempt to reuse last executor cached in volatile JexlNode.value
- if (node != null && cache) {
- Object cached = node.jjtGetValue();
- if (cached instanceof JexlPropertySet) {
- JexlPropertySet setter = (JexlPropertySet) cached;
- Object eval = setter.tryInvoke(object, attribute, value);
- if (!setter.tryFailed(eval)) {
- return;
+ Exception xcause = null;
+ try {
+ // attempt to reuse last executor cached in volatile JexlNode.value
+ if (node != null && cache) {
+ Object cached = node.jjtGetValue();
+ if (cached instanceof JexlPropertySet) {
+ JexlPropertySet setter = (JexlPropertySet) cached;
+ Object eval = setter.tryInvoke(object, attribute, value);
+ if (!setter.tryFailed(eval)) {
+ return;
+ }
}
}
- }
- Exception xcause = null;
- List<PropertyResolver> resolvers = uberspect.getResolvers(operator, object);
- JexlPropertySet vs = uberspect.getPropertySet(resolvers, object, attribute, \
value);
- // if we can't find an exact match, narrow the value argument and try again
- if (vs == null) {
- // replace all numbers with the smallest type that will fit
- Object[] narrow = {value};
- if (arithmetic.narrowArguments(narrow)) {
- vs = uberspect.getPropertySet(resolvers, object, attribute, \
narrow[0]); + List<PropertyResolver> resolvers = \
uberspect.getResolvers(operator, object); + JexlPropertySet vs = \
uberspect.getPropertySet(resolvers, object, attribute, value); + // if we \
can't find an exact match, narrow the value argument and try again + if \
(vs == null) { + // replace all numbers with the smallest type that \
will fit + Object[] narrow = {value};
+ if (arithmetic.narrowArguments(narrow)) {
+ vs = uberspect.getPropertySet(resolvers, object, attribute, \
narrow[0]); + }
}
- }
- if (vs != null) {
- try {
+ if (vs != null) {
// cache executor in volatile JexlNode.value
vs.invoke(object, value);
if (node != null && cache && vs.isCacheable()) {
node.jjtSetValue(vs);
}
return;
- } catch (Exception xany) {
- xcause = xany;
}
+ } catch (Exception xany) {
+ xcause = xany;
}
// lets fail
if (node != null) {
Modified: commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java?rev=1758541&r1=1758540&r2=1758541&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java \
(original)
+++ commons/proper/jexl/trunk/src/main/java/org/apache/commons/jexl3/internal/Operators.java \
Wed Aug 31 08:03:57 2016 @@ -71,17 +71,17 @@ public class Operators {
if (operators != null && operators.overloads(operator)) {
final JexlArithmetic arithmetic = interpreter.arithmetic;
final boolean cache = interpreter.cache;
- if (cache) {
- Object cached = node.jjtGetValue();
- if (cached instanceof JexlMethod) {
- JexlMethod me = (JexlMethod) cached;
- Object eval = me.tryInvoke(operator.getMethodName(), arithmetic, \
args);
- if (!me.tryFailed(eval)) {
- return eval;
+ try {
+ if (cache) {
+ Object cached = node.jjtGetValue();
+ if (cached instanceof JexlMethod) {
+ JexlMethod me = (JexlMethod) cached;
+ Object eval = me.tryInvoke(operator.getMethodName(), \
arithmetic, args); + if (!me.tryFailed(eval)) {
+ return eval;
+ }
}
}
- }
- try {
JexlMethod vm = operators.getOperator(operator, args);
if (vm != null) {
Object result = vm.invoke(arithmetic, args);
Modified: commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java?rev=1758541&r1=1758540&r2=1758541&view=diff
==============================================================================
--- commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java \
(original)
+++ commons/proper/jexl/trunk/src/test/java/org/apache/commons/jexl3/IssuesTest.java \
Wed Aug 31 08:03:57 2016 @@ -1263,4 +1263,32 @@ public class IssuesTest extends \
JexlTest
Assert.assertTrue(NullPointerException.class.equals(th.getClass()));
}
}
+
+ @Test
+ public void test217() throws Exception {
+ JexlEvalContext jc = new JexlEvalContext();
+ jc.set("foo", new int[]{0, 1, 2, 42});
+ JexlEngine jexl;
+ JexlScript e;
+ Object r;
+ jexl = new JexlBuilder().strict(false).silent(false).create();
+ e = jexl.createScript("foo[3]");
+ r = e.execute(jc);
+ Assert.assertEquals(42, r);
+
+ // cache and fail?
+ jc.set("foo", new int[]{0, 1});
+ jc.setStrict(true);
+ try {
+ r = e.execute(jc);
+ Assert.fail("should have thrown an exception");
+ } catch(JexlException xjexl) {
+ Throwable th = xjexl.getCause();
+ Assert.assertTrue(ArrayIndexOutOfBoundsException.class.equals(th.getClass()));
+ }
+ //
+ jc.setStrict(false);
+ r = e.execute(jc);
+ Assert.assertNull("oob adverted", r);
+ }
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic