Author: markt
Date: Thu Oct 23 13:50:18 2014
New Revision: 1633810

URL: http://svn.apache.org/r1633810
Log:
Allow the same class to be added to an instance of javax.el.ImportHandler more 
than once without triggering an error. The second and subsequent calls for the 
same class will be ignored.

Modified:
    tomcat/trunk/java/javax/el/ImportHandler.java
    tomcat/trunk/test/javax/el/TestImportHandler.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/javax/el/ImportHandler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ImportHandler.java?rev=1633810&r1=1633809&r2=1633810&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/ImportHandler.java (original)
+++ tomcat/trunk/java/javax/el/ImportHandler.java Thu Oct 23 13:50:18 2014
@@ -118,12 +118,19 @@ public class ImportHandler {
         String simpleName = clazz.getSimpleName();
         Class<?> conflict = clazzes.get(simpleName);
 
-        if (conflict != null) {
-            throw new ELException(Util.message(null,
-                    "importHandler.ambiguousImport", name, 
conflict.getName()));
+        if (conflict == null) {
+            // No conflict - add it
+            clazzes.put(simpleName, clazz);
+        } else {
+            // Check for a duplicate
+            if (conflict.equals(clazz)) {
+                // This is a duplicate.
+                // NO-OP
+            } else {
+                throw new ELException(Util.message(null,
+                        "importHandler.ambiguousImport", name, 
conflict.getName()));
+            }
         }
-
-        clazzes.put(simpleName, clazz);
     }
 
 

Modified: tomcat/trunk/test/javax/el/TestImportHandler.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TestImportHandler.java?rev=1633810&r1=1633809&r2=1633810&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TestImportHandler.java (original)
+++ tomcat/trunk/test/javax/el/TestImportHandler.java Thu Oct 23 13:50:18 2014
@@ -167,6 +167,23 @@ public class TestImportHandler {
 
 
     /**
+     * Import duplicate classes (i.e. the same class twice).
+     */
+    @Test
+    public void testImportClass04() {
+        ImportHandler handler = new ImportHandler();
+
+        handler.importClass("org.apache.tomcat.util.res.StringManager");
+        handler.importClass("org.apache.tomcat.util.res.StringManager");
+
+        Class<?> result = handler.resolveClass("StringManager");
+
+        Assert.assertEquals(StringManager.class, result);
+    }
+
+
+
+    /**
      * Import an invalid package.
      */
     @Test(expected=ELException.class)

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1633810&r1=1633809&r2=1633810&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Oct 23 13:50:18 2014
@@ -214,6 +214,12 @@
         Improve handling of invalid input to
         <code>javax.el.ImportHandler.resolveClass()</code>. (markt)
       </fix>
+      <fix>
+        Allow the same class to be added to an instance of
+        <code>javax.el.ImportHandler</code> more than once without triggering
+        an error. The second and subsequent calls for the same class will be
+        ignored. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to