This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 2e2dc849ca Review "11ef7a700d82aaed0d8a48f172f0056aedb27ed3"
2e2dc849ca is described below
commit 2e2dc849ca78ff096700575424f8e5d871bdf34b
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 | 46 +++++++++++++++++++++++++++
java/org/apache/el/lang/ELArithmetic.java | 13 ++++++--
test/org/apache/el/lang/TestELArithmetic.java | 19 +++++++++++
3 files changed, 75 insertions(+), 3 deletions(-)
diff --git a/java/org/apache/el/LocalStrings.properties
b/java/org/apache/el/LocalStrings.properties
index 4085b91edf..1983c88554 100644
--- a/java/org/apache/el/LocalStrings.properties
+++ b/java/org/apache/el/LocalStrings.properties
@@ -23,6 +23,52 @@ error.add=Cannot add [{0}] to [{1}]
error.convert=Cannot convert [{0}] of type [{1}] to [{2}]
error.compare=Cannot compare [{0}] to [{1}]
error.compare.null=Unable to compare null with non-null object
+<<<<<<< HEAD
+=======
+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}]
+error.noFunctionMapperTarget=FunctionMapper target cannot be null
+error.noVariableMapperTarget=VariableMapper target cannot be null
+error.nullLocalName=Local name cannot be null
+error.nullMethod=Method cannot be null
+error.unreachable.base=Target Unreachable, identifier [{0}] resolved to null
+error.unreachable.property=Target Unreachable, [{0}] returned null
+error.resolver.unhandled=ELResolver did not handle type: [{0}] with property
of [{1}]
+error.resolver.unhandled.null=ELResolver cannot handle a null base Object with
identifier [{0}]
+error.invoke.wrongParams=The method [{0}] was called with [{1}] parameter(s)
when it expected [{2}]
+error.invoke.tooFewParams=The method [{0}] was called with [{1}] parameter(s)
when it expected at least [{2}]
+
+# ValueExpressionLiteral
+error.value.literal.write=ValueExpression is a literal and not writable: [{0}]
+
+# ExpressionFactoryImpl
+error.null=Expression cannot be null
+error.mixed=Expression cannot contain both ''#{...}'' and ''${...}'' : [{0}]
+error.method=Not a valid MethodExpression : [{0}]
+error.method.nullParms=Parameter types cannot be null
+error.value.expectedType=Expected type cannot be null
+
+# ExpressionBuilder
+error.parseFail=Failed to parse the expression [{0}]
+
+# ValueSetVisitor
+error.syntax.set=Illegal Syntax for Set Operation
+
+# ReflectionUtil
+error.method.notfound=Method not found: {0}.{1}({2})
+error.method.ambiguous=Unable to find unambiguous method: {0}.{1}({2})
+
+# ValidatingVisitor
+error.fnMapper.null=Expression uses functions, but no FunctionMapper was
provided
+error.fnMapper.method=Function [{0}] not found
+error.fnMapper.paramcount=Function [{0}] specifies [{1}] params, but [{2}]
were declared
+
+# ExpressionImpl
+>>>>>>> e9db1637c4 (Review "11ef7a700d82aaed0d8a48f172f0056aedb27ed3")
error.context.null=ELContext was null
error.convert=Cannot convert [{0}] of type [{1}] to [{2}]
error.divide=Cannot divide [{0}] by [{1}]
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]