Fix regression in previous fix for https://issues.apache.org/bugzilla/show_bug.cgi...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Oct 2008 16:19:01 +0000 (16:19 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Fri, 3 Oct 2008 16:19:01 +0000 (16:19 +0000)
Patch provided by Nils Eckert.

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

java/org/apache/el/lang/ELSupport.java
test/org/apache/el/lang/TestELSupport.java

index 51e3649..d65a6b3 100644 (file)
@@ -224,18 +224,18 @@ public class ELSupport {
                 return ((BigDecimal) number).toBigInteger();
             }
             if (number instanceof BigInteger) {
-                return new BigInteger(number.toString());
+                return number;
             }
             return BigInteger.valueOf(number.longValue());
         }
         if (BigDecimal.class.equals(type)) {
             if (number instanceof BigDecimal) {
-                return new BigDecimal(number.toString());
+                return number;
             }
             if (number instanceof BigInteger) {
                 return new BigDecimal((BigInteger) number);
             }
-            return new BigDecimal(number.doubleValue());
+            return new BigDecimal(number.toString());
         }
         if (Byte.TYPE == type || Byte.class.equals(type)) {
             return new Byte(number.byteValue());
@@ -341,7 +341,7 @@ public class ELSupport {
     public final static Object coerceToType(final Object obj, final Class type)
             throws IllegalArgumentException {
         if (type == null || Object.class.equals(type) ||
-                (obj != null && type.equals(obj.getClass()))) {
+                (obj != null && type.isAssignableFrom(obj.getClass()))) {
             return obj;
         }
         if (String.class.equals(type)) {
@@ -356,9 +356,6 @@ public class ELSupport {
         if (Boolean.class.equals(type) || Boolean.TYPE == type) {
             return coerceToBoolean(obj);
         }
-        if (obj != null && type.isAssignableFrom(obj.getClass())) {
-            return obj;
-        }
         if (type.isEnum()) {
             return coerceToEnum(obj, type);
         }
index c824b19..0563e78 100644 (file)
@@ -56,6 +56,12 @@ public class TestELSupport extends TestCase {
         testIsSame(Float.valueOf(0.123456F));
     }
 
+    public void testCoerceIntegerToNumber() {
+        Integer input = 4390241;
+        Object output = ELSupport.coerceToType(input, Number.class);
+        assertEquals(input, output);
+    }
+
     private static void testIsSame(Object value) {
         assertEquals(value, ELSupport.coerceToNumber(value, value.getClass()));
     }