Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=47371
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 5 May 2011 13:39:09 +0000 (13:39 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 5 May 2011 13:39:09 +0000 (13:39 +0000)
Correctly coerce the empty string to zero when used as an operand in EL arithmetic.
Patch provided by gbt.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1099789 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/el/lang/ELArithmetic.java
test/org/apache/el/lang/TestELArithmetic.java
webapps/docs/changelog.xml

index 7ae39f0..f0bb5b3 100644 (file)
@@ -394,13 +394,12 @@ public abstract class ELArithmetic {
         if (isNumber(obj)) {
             return coerce((Number) obj);
         }
-        if (obj instanceof String) {
-            return coerce((String) obj);
-        }
         if (obj == null || "".equals(obj)) {
             return coerce(ZERO);
         }
-
+        if (obj instanceof String) {
+            return coerce((String) obj);
+        }
         if (obj instanceof Character) {
             return coerce(Short.valueOf((short) ((Character) obj).charValue()));
         }
index 305630b..c2dfd7f 100644 (file)
@@ -49,4 +49,9 @@ public class TestELArithmetic extends TestCase {
         assertEquals("1.1",
                 String.valueOf(ELArithmetic.mod(a, b)));
     }
+
+    public void testBug47371() throws Exception {
+        assertEquals("1",
+                String.valueOf(ELArithmetic.add("", Integer.valueOf(1))));
+    }
 }
index 506f1d6..9d5d777 100644 (file)
   </subsection>
   <subsection name="Jasper">
     <changelog>
+      <fix>
+        <bug><47371/bug>: Correctly coerce the empty string to zero when used as
+        an operand in EL arithmetic. Patch provided by gbt. (markt)
+      </fix>
       <add>
         Label JSP/tag file line and column numbers when reporting errors since
         it may not be immediately obvious what the numbers represent. (markt)