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 2017/09/06 15:58:54 UTC
svn commit: r1807495 - in
/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal:
BooleanGetExecutor.java DuckGetExecutor.java DuckSetExecutor.java
MapGetExecutor.java MapSetExecutor.java
Author: henrib
Date: Wed Sep 6 15:58:54 2017
New Revision: 1807495
URL: http://svn.apache.org/viewvc?rev=1807495&view=rev
Log:
JEXL-239:
backport of JEXL-221 checks (from JEXL3 to JEXL2)
Modified:
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/BooleanGetExecutor.java
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckGetExecutor.java
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckSetExecutor.java
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapGetExecutor.java
commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapSetExecutor.java
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/BooleanGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/BooleanGetExecutor.java?rev=1807495&r1=1807494&r2=1807495&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/BooleanGetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/BooleanGetExecutor.java Wed Sep 6 15:58:54 2017
@@ -47,7 +47,7 @@ public final class BooleanGetExecutor ex
throws IllegalAccessException, InvocationTargetException {
return method == null ? null : method.invoke(obj, (Object[]) null);
}
-
+
/** {@inheritDoc} */
@Override
public Object tryExecute(Object obj, Object key) {
@@ -75,7 +75,7 @@ public final class BooleanGetExecutor ex
*@return the method if found, null otherwise
*/
static java.lang.reflect.Method discover(Introspector is, final Class<?> clazz, String property) {
- java.lang.reflect.Method m = PropertyGetExecutor.discoverGet(is, "is", clazz, property);
+ java.lang.reflect.Method m = property != null? PropertyGetExecutor.discoverGet(is, "is", clazz, property) : null;
return (m != null && m.getReturnType() == Boolean.TYPE) ? m : null;
}
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckGetExecutor.java?rev=1807495&r1=1807494&r2=1807495&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckGetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckGetExecutor.java Wed Sep 6 15:58:54 2017
@@ -67,10 +67,12 @@ public final class DuckGetExecutor exten
/** {@inheritDoc} */
@Override
public Object tryExecute(Object obj, Object key) {
- if (obj != null && method != null
+ if (obj != null
+ && objectClass.equals(obj.getClass())
// ensure method name matches the property name
- && property.equals(key)
- && objectClass.equals(obj.getClass())) {
+ && method != null
+ && ((property == null && key == null)
+ || (property != null && property.equals(key)))) {
try {
Object[] args = {property};
return method.invoke(obj, args);
@@ -78,6 +80,8 @@ public final class DuckGetExecutor exten
return TRY_FAILED; // fail
} catch (IllegalAccessException xill) {
return TRY_FAILED;// fail
+ } catch (IllegalArgumentException xarg) {
+ return TRY_FAILED;// fail
}
}
return TRY_FAILED;
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckSetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckSetExecutor.java?rev=1807495&r1=1807494&r2=1807495&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckSetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/DuckSetExecutor.java Wed Sep 6 15:58:54 2017
@@ -32,7 +32,7 @@ import java.lang.reflect.InvocationTarge
public final class DuckSetExecutor extends AbstractExecutor.Set {
/** The property. */
private final Object property;
-
+
/**
* Creates an instance.
*@param is the introspector
@@ -65,10 +65,11 @@ public final class DuckSetExecutor exten
/** {@inheritDoc} */
@Override
public Object tryExecute(Object obj, Object key, Object value) {
- if (obj != null && method != null
- // ensure method name matches the property name
- && property.equals(key)
- && objectClass.equals(obj.getClass())) {
+ if (obj != null
+ && objectClass.equals(obj.getClass())
+ && method != null
+ && ((property != null && property.equals(key))
+ || (property == null && key == null))) {
try {
Object[] args = {property, value};
method.invoke(obj, args);
@@ -77,6 +78,8 @@ public final class DuckSetExecutor exten
return TRY_FAILED; // fail
} catch (IllegalAccessException xill) {
return TRY_FAILED;// fail
+ } catch (IllegalArgumentException xarg) {
+ return TRY_FAILED;// fail
}
}
return TRY_FAILED;
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapGetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapGetExecutor.java?rev=1807495&r1=1807494&r2=1807495&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapGetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapGetExecutor.java Wed Sep 6 15:58:54 2017
@@ -46,7 +46,7 @@ public final class MapGetExecutor extend
public Object getTargetProperty() {
return property;
}
-
+
/**
* Get the property from the map.
* @param obj the map.
@@ -62,11 +62,13 @@ public final class MapGetExecutor extend
/** {@inheritDoc} */
@Override
public Object tryExecute(final Object obj, Object key) {
- if (obj != null && method != null
+ if (obj != null
+ && method != null
&& objectClass.equals(obj.getClass())
- && (key == null || property.getClass().equals(key.getClass()))) {
+ && ((property == null && key == null)
+ || (property != null && key != null && property.getClass().equals(key.getClass())))) {
@SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
- final Map<Object,?> map = (Map<Object, ?>) obj;
+ final Map<Object, ?> map = (Map<Object, ?>) obj;
return map.get(key);
}
return TRY_FAILED;
Modified: commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapSetExecutor.java
URL: http://svn.apache.org/viewvc/commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapSetExecutor.java?rev=1807495&r1=1807494&r2=1807495&view=diff
==============================================================================
--- commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapSetExecutor.java (original)
+++ commons/proper/jexl/branches/2.0/src/main/java/org/apache/commons/jexl2/internal/MapSetExecutor.java Wed Sep 6 15:58:54 2017
@@ -45,7 +45,7 @@ public final class MapSetExecutor extend
public Object getTargetProperty() {
return property;
}
-
+
/** {@inheritDoc} */
@Override
public Object execute(final Object obj, Object value)
@@ -59,9 +59,11 @@ public final class MapSetExecutor extend
/** {@inheritDoc} */
@Override
public Object tryExecute(final Object obj, Object key, Object value) {
- if (obj != null && method != null
+ if (obj != null
+ && method != null
&& objectClass.equals(obj.getClass())
- && (key == null || property.getClass().equals(key.getClass()))) {
+ && ((property == null && key == null)
+ || (property != null && key != null && property.getClass().equals(key.getClass())))) {
@SuppressWarnings("unchecked") // ctor only allows Map instances - see discover() method
final Map<Object,Object> map = ((Map<Object, Object>) obj);
map.put(key, value);