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 2019/12/11 22:13:05 UTC

[commons-jexl] branch master updated: JEXL-298: size/empty operators overloads results shall not be coerced Task #JEXL-298 - Unable to call 'empty' and 'size' member methods with parameters

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 7f1336e  JEXL-298: size/empty operators overloads results shall not be coerced Task #JEXL-298 - Unable to call 'empty' and 'size' member methods with parameters
7f1336e is described below

commit 7f1336e81d1b84ffe53d53a408380e5cfd94d91c
Author: henrib <he...@apache.org>
AuthorDate: Wed Dec 11 23:12:34 2019 +0100

    JEXL-298: size/empty operators overloads results shall not be coerced
    Task #JEXL-298 - Unable to call 'empty' and 'size' member methods with parameters
---
 .../apache/commons/jexl3/internal/Operators.java   | 64 +++++++++++-----------
 1 file changed, 33 insertions(+), 31 deletions(-)

diff --git a/src/main/java/org/apache/commons/jexl3/internal/Operators.java b/src/main/java/org/apache/commons/jexl3/internal/Operators.java
index ae8b4ec..7698cb0 100644
--- a/src/main/java/org/apache/commons/jexl3/internal/Operators.java
+++ b/src/main/java/org/apache/commons/jexl3/internal/Operators.java
@@ -342,26 +342,27 @@ public class Operators {
      * @param object the object to check the emptyness of
      * @return the evaluation result
      */
-    protected boolean empty(JexlNode node, Object object) {
+    protected Object empty(JexlNode node, Object object) {
         if (object == null) {
             return true;
         }
         Object result = tryOverload(node, JexlOperator.EMPTY, object);
-        if (result == JexlEngine.TRY_FAILED) {
-            final JexlArithmetic arithmetic = interpreter.arithmetic;
-            result = arithmetic.isEmpty(object, null);
-            if (result == null) {
-                final JexlUberspect uberspect = interpreter.uberspect;
-                result = false;
-                // check if there is an isEmpty method on the object that returns a
-                // boolean and if so, just use it
-                JexlMethod vm = uberspect.getMethod(object, "isEmpty", Interpreter.EMPTY_PARAMS);
-                if (returnsBoolean(vm)) {
-                    try {
-                        result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
-                    } catch (Exception xany) {
-                        interpreter.operatorError(node, JexlOperator.EMPTY, xany);
-                    }
+        if (result != JexlEngine.TRY_FAILED) {
+            return result;
+        }
+        final JexlArithmetic arithmetic = interpreter.arithmetic;
+        result = arithmetic.isEmpty(object, null);
+        if (result == null) {
+            final JexlUberspect uberspect = interpreter.uberspect;
+            result = false;
+            // check if there is an isEmpty method on the object that returns a
+            // boolean and if so, just use it
+            JexlMethod vm = uberspect.getMethod(object, "isEmpty", Interpreter.EMPTY_PARAMS);
+            if (returnsBoolean(vm)) {
+                try {
+                    result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
+                } catch (Exception xany) {
+                    interpreter.operatorError(node, JexlOperator.EMPTY, xany);
                 }
             }
         }
@@ -377,25 +378,26 @@ public class Operators {
      * @param object the object to get the size of
      * @return the evaluation result
      */
-    protected int size(JexlNode node, Object object) {
+    protected Object size(JexlNode node, Object object) {
         if (object == null) {
             return 0;
         }
         Object result = tryOverload(node, JexlOperator.SIZE, object);
-        if (result == JexlEngine.TRY_FAILED) {
-            final JexlArithmetic arithmetic = interpreter.arithmetic;
-            result = arithmetic.size(object, null);
-            if (result == null) {
-                final JexlUberspect uberspect = interpreter.uberspect;
-                // check if there is a size method on the object that returns an
-                // integer and if so, just use it
-                JexlMethod vm = uberspect.getMethod(object, "size", Interpreter.EMPTY_PARAMS);
-                if (returnsInteger(vm)) {
-                    try {
-                        result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
-                    } catch (Exception xany) {
-                        interpreter.operatorError(node, JexlOperator.SIZE, xany);
-                    }
+        if (result != JexlEngine.TRY_FAILED) {
+            return result;
+        }
+        final JexlArithmetic arithmetic = interpreter.arithmetic;
+        result = arithmetic.size(object, null);
+        if (result == null) {
+            final JexlUberspect uberspect = interpreter.uberspect;
+            // check if there is a size method on the object that returns an
+            // integer and if so, just use it
+            JexlMethod vm = uberspect.getMethod(object, "size", Interpreter.EMPTY_PARAMS);
+            if (returnsInteger(vm)) {
+                try {
+                    result = vm.invoke(object, Interpreter.EMPTY_PARAMS);
+                } catch (Exception xany) {
+                    interpreter.operatorError(node, JexlOperator.SIZE, xany);
                 }
             }
         }