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 3bc67dcb JEXL-373: null is 0 for '++/--' in lenient arithmetic mode
3bc67dcb is described below

commit 3bc67dcb6d5071a359768b84f47797aa36d67d18
Author: henrib <hen...@apache.org>
AuthorDate: Sun Jun 12 17:22:31 2022 +0200

    JEXL-373: null is 0 for '++/--' in lenient arithmetic mode
---
 src/main/java/org/apache/commons/jexl3/JexlArithmetic.java   |  2 +-
 .../org/apache/commons/jexl3/ArithmeticOperatorTest.java     | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java 
b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index b9236c3c..1ca2bd42 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -743,7 +743,7 @@ public class JexlArithmetic {
     protected Object increment(Object val, int incr) {
         if (val == null) {
             controlNullOperand();
-            return null;
+            return incr;
         }
         if (val instanceof Integer) {
             return ((Integer) val) + incr;
diff --git a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java 
b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
index ab7db95b..1cc3e86b 100644
--- a/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
+++ b/src/test/java/org/apache/commons/jexl3/ArithmeticOperatorTest.java
@@ -584,5 +584,17 @@ public class ArithmeticOperatorTest extends JexlTestCase {
         Assert.assertEquals("y0", y0, y.get(0));
     }
 
+    @Test
+    public void testIncrementOperatorOnNull() throws Exception {
+        final JexlEngine jexl = new JexlBuilder().strict(false).create();
+        JexlScript script;
+        Object result;
+        script = jexl.createScript("var i = null; ++i");
+        result = script.execute(null);
+        Assert.assertEquals(1, result);
+        script = jexl.createScript("var i = null; --i");
+        result = script.execute(null);
+        Assert.assertEquals(-1, result);
+    }
 
 }

Reply via email to