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

markt-asf 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 e9db1637c4 Review "11ef7a700d82aaed0d8a48f172f0056aedb27ed3"
e9db1637c4 is described below

commit e9db1637c4071671e6fc6c169791476e703de680
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Nov 5 13:32:47 2026 +0000

    Review "11ef7a700d82aaed0d8a48f172f0056aedb27ed3"
    
    Multiplication also needed handling
---
 java/org/apache/el/LocalStrings.properties    |  1 +
 java/org/apache/el/lang/ELArithmetic.java     | 13 ++++++++++---
 test/org/apache/el/lang/TestELArithmetic.java | 19 +++++++++++++++++++
 3 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/java/org/apache/el/LocalStrings.properties 
b/java/org/apache/el/LocalStrings.properties
index 37b938c156..f661b59831 100644
--- a/java/org/apache/el/LocalStrings.properties
+++ b/java/org/apache/el/LocalStrings.properties
@@ -23,6 +23,7 @@ error.compare=Cannot compare [{0}] to [{1}]
 error.compare.null=Unable to compare null with non-null object
 error.divide=Cannot divide [{0}] by [{1}]
 error.mod=Cannot compute [{0}] modulo [{1}]
+error.multiply=Cannot multiply [{0}] by [{1}]
 error.subtract=Cannot subtract [{1}] from [{0}]
 error.function=Problems calling function [{0}]
 error.invalidMethodExpression=Not a valid method expression [{0}]
diff --git a/java/org/apache/el/lang/ELArithmetic.java 
b/java/org/apache/el/lang/ELArithmetic.java
index c8f9997005..e5f3c0b18f 100644
--- a/java/org/apache/el/lang/ELArithmetic.java
+++ b/java/org/apache/el/lang/ELArithmetic.java
@@ -431,6 +431,9 @@ public abstract class ELArithmetic {
      * @param obj1 The second factor
      *
      * @return The result of the multiplication
+     *
+     * @throws ELException if the operands cannot be coerced to numbers or if 
the multiplication cannot be computed,
+     *                     for example overflow with extreme BigDecimal values
      */
     public static Number multiply(final Object obj0, final Object obj1) {
         final ELArithmetic delegate = findDelegate(obj0, obj1);
@@ -438,10 +441,14 @@ public abstract class ELArithmetic {
             return Long.valueOf(0);
         }
 
-        Number num0 = delegate.coerce(obj0);
-        Number num1 = delegate.coerce(obj1);
+        try {
+            Number num0 = delegate.coerce(obj0);
+            Number num1 = delegate.coerce(obj1);
 
-        return delegate.multiply(num0, num1);
+            return delegate.multiply(num0, num1);
+        } catch (ArithmeticException ae) {
+            throw new ELException(MessageFactory.get("error.multiply", obj0, 
obj1), ae);
+        }
     }
 
     private static ELArithmetic findDelegate(final Object obj0, final Object 
obj1) {
diff --git a/test/org/apache/el/lang/TestELArithmetic.java 
b/test/org/apache/el/lang/TestELArithmetic.java
index 8c1d0acbad..a24bf24302 100644
--- a/test/org/apache/el/lang/TestELArithmetic.java
+++ b/test/org/apache/el/lang/TestELArithmetic.java
@@ -202,6 +202,25 @@ public class TestELArithmetic {
         assertELException("subtract", () -> ELArithmetic.subtract((Object) 
extreme, (Object) Long.valueOf(1)));
     }
 
+    @Test
+    public void testBigDecimalMultiplyOverflowThrowsELException() {
+        // BigDecimal.multiply() declares ArithmeticException when the sum of 
the scales is outside the range of an
+        // int. The failure must surface as ELException.
+        BigDecimal extreme = new BigDecimal(BigInteger.ONE, Integer.MAX_VALUE);
+        assertELException("multiply", () -> ELArithmetic.multiply((Object) 
extreme, (Object) extreme));
+    }
+
+    @Test
+    public void 
testBigDecimalMultiplyOverflowFromExpressionThrowsELException() {
+        ELProcessor processor = new ELProcessor();
+        try {
+            processor.eval("1e999999999 * 1e999999999 * 1e999999999");
+            Assert.fail("Expected ELException");
+        } catch (ELException expected) {
+            Assert.assertTrue(expected.getCause() instanceof 
ArithmeticException);
+        }
+    }
+
     private static class TesterNumberOddToString extends Number {
 
         private static final long serialVersionUID = 1L;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to