Address review comments
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 13 Feb 2010 19:22:02 +0000 (19:22 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sat, 13 Feb 2010 19:22:02 +0000 (19:22 +0000)
Don't use toString() to try and co-erce any old object to an Enum - the spec only mentions String

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

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

index f627aa3..6cee357 100644 (file)
@@ -185,9 +185,15 @@ public class ELSupport {
         if (type.isAssignableFrom(obj.getClass())) {
             return (Enum<?>) obj;
         }
+        
+        if (!(obj instanceof String)) {
+            throw new ELException(MessageFactory.get("error.convert",
+                    obj, obj.getClass(), type));
+        }
+
         Enum<?> result;
         try {
-             result = Enum.valueOf(type, obj.toString());
+             result = Enum.valueOf(type, (String) obj);
         } catch (IllegalArgumentException iae) {
             throw new ELException(MessageFactory.get("error.convert",
                     obj, obj.getClass(), type));
index 4b1eed6..be4a0e6 100644 (file)
@@ -92,9 +92,10 @@ public class TestELSupport extends TestCase {
         Object output = null;
         try {
             output = ELSupport.coerceToEnum(TestEnumA.VALA1, TestEnumC.class);
-        } finally {
-            assertEquals(TestEnumC.VALA1, output);
+        } catch (ELException ele) {
+            // Ignore
         }
+        assertNull(output);
     }
 
     private static void testIsSame(Object value) {