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

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 71160c5aa2 EL spec requires remainder() rather than mod()
71160c5aa2 is described below

commit 71160c5aa2fe0b331d48443294d0371980f746ab
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Aug 31 20:49:29 2022 +0100

    EL spec requires remainder() rather than mod()
---
 java/org/apache/el/lang/ELArithmetic.java     | 2 +-
 test/org/apache/el/lang/TestELArithmetic.java | 8 ++++++++
 webapps/docs/changelog.xml                    | 6 ++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/el/lang/ELArithmetic.java 
b/java/org/apache/el/lang/ELArithmetic.java
index 65194cc2e3..70538619c0 100644
--- a/java/org/apache/el/lang/ELArithmetic.java
+++ b/java/org/apache/el/lang/ELArithmetic.java
@@ -113,7 +113,7 @@ public abstract class ELArithmetic {
 
         @Override
         protected Number mod(Number num0, Number num1) {
-            return ((BigInteger) num0).mod((BigInteger) num1);
+            return ((BigInteger) num0).remainder((BigInteger) num1);
         }
 
         @Override
diff --git a/test/org/apache/el/lang/TestELArithmetic.java 
b/test/org/apache/el/lang/TestELArithmetic.java
index 800d8ea6d4..fd9ec2c029 100644
--- a/test/org/apache/el/lang/TestELArithmetic.java
+++ b/test/org/apache/el/lang/TestELArithmetic.java
@@ -94,6 +94,14 @@ public class TestELArithmetic {
         Assert.assertEquals(Long.valueOf(0), result);
     }
 
+    @Test
+    public void testMod03() {
+        ELProcessor processor = new ELProcessor();
+        // Large so BigInteger rather than Long is used internally
+        BigInteger result = processor.eval("1 % -9999999999999999999");
+        Assert.assertEquals(BigInteger.valueOf(1), result);
+    }
+
     @Test
     public void testUnaryMinus01() {
         ELProcessor processor = new ELProcessor();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index e43b8f5c60..17818032ed 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -244,6 +244,12 @@
         error when invoking a static method on an instance of the class rather
         than directly on the class. (markt)
       </fix>
+      <fix>
+        Use <code>BigInteger.remainder()</code> rather than
+        <code>BigInteger.mod()</code> when performing the modulus operation for
+        instances of <code>BigInteger</code> as part of an EL expression.
+        (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to