You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2015/03/05 14:55:20 UTC

svn commit: r1664347 - in /tomcat/trunk: java/javax/el/ImportHandler.java test/javax/el/TestImportHandler.java test/util/a/ test/util/a/Foo.java test/util/b/ test/util/b/Foo.java

Author: markt
Date: Thu Mar  5 13:55:19 2015
New Revision: 1664347

URL: http://svn.apache.org/r1664347
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=57135
When using the EL ImportHandler, import of a package should only import the public, concrete classes.

Added:
    tomcat/trunk/test/util/a/
    tomcat/trunk/test/util/a/Foo.java   (with props)
    tomcat/trunk/test/util/b/
    tomcat/trunk/test/util/b/Foo.java   (with props)
Modified:
    tomcat/trunk/java/javax/el/ImportHandler.java
    tomcat/trunk/test/javax/el/TestImportHandler.java

Modified: tomcat/trunk/java/javax/el/ImportHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/ImportHandler.java?rev=1664347&r1=1664346&r2=1664347&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/ImportHandler.java (original)
+++ tomcat/trunk/java/javax/el/ImportHandler.java Thu Mar  5 13:55:19 2015
@@ -51,7 +51,7 @@ public class ImportHandler {
         String className = name.substring(0, lastPeriod);
         String fieldOrMethodName = name.substring(lastPeriod + 1);
 
-        Class<?> clazz = findClass(className);
+        Class<?> clazz = findClass(className, true);
 
         if (clazz == null) {
             throw new ELException(Util.message(
@@ -150,7 +150,7 @@ public class ImportHandler {
         // Search the class imports
         String className = classNames.get(name);
         if (className != null) {
-            Class<?> clazz = findClass(className);
+            Class<?> clazz = findClass(className, true);
             if (clazz != null) {
                 clazzes.put(className, clazz);
                 return clazz;
@@ -161,7 +161,7 @@ public class ImportHandler {
         // (which correctly triggers an error)
         for (String p : packageNames) {
             className = p + '.' + name;
-            Class<?> clazz = findClass(className);
+            Class<?> clazz = findClass(className, false);
             if (clazz != null) {
                 if (result != null) {
                     throw new ELException(Util.message(null,
@@ -188,7 +188,7 @@ public class ImportHandler {
     }
 
 
-    private Class<?> findClass(String name) {
+    private Class<?> findClass(String name, boolean throwException) {
         Class<?> clazz;
         ClassLoader cl = Thread.currentThread().getContextClassLoader();
         try {
@@ -201,8 +201,12 @@ public class ImportHandler {
         int modifiers = clazz.getModifiers();
         if (!Modifier.isPublic(modifiers) || Modifier.isAbstract(modifiers) ||
                 Modifier.isInterface(modifiers)) {
-            throw new ELException(Util.message(
-                    null, "importHandler.invalidClass", name));
+            if (throwException) {
+                throw new ELException(Util.message(
+                        null, "importHandler.invalidClass", name));
+            } else {
+                return null;
+            }
         }
 
         return clazz;

Modified: tomcat/trunk/test/javax/el/TestImportHandler.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TestImportHandler.java?rev=1664347&r1=1664346&r2=1664347&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TestImportHandler.java (original)
+++ tomcat/trunk/test/javax/el/TestImportHandler.java Thu Mar  5 13:55:19 2015
@@ -255,4 +255,19 @@ public class TestImportHandler {
             }
         }
     }
+
+
+    /**
+     * Package imports with conflicts due to non-public classes should not
+     * conflict.
+     */
+    @Test
+    public void testBug57135() {
+        ImportHandler importHandler = new ImportHandler();
+
+        importHandler.importPackage("util.a");
+        importHandler.importPackage("util.b");
+
+        importHandler.resolveClass("Foo");
+    }
 }

Added: tomcat/trunk/test/util/a/Foo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/util/a/Foo.java?rev=1664347&view=auto
==============================================================================
--- tomcat/trunk/test/util/a/Foo.java (added)
+++ tomcat/trunk/test/util/a/Foo.java Thu Mar  5 13:55:19 2015
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package util.a;
+
+/**
+ * Tester class used for {@link javax.el.TestImportHandler}.
+ */
+class Foo {
+}

Propchange: tomcat/trunk/test/util/a/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/util/b/Foo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/util/b/Foo.java?rev=1664347&view=auto
==============================================================================
--- tomcat/trunk/test/util/b/Foo.java (added)
+++ tomcat/trunk/test/util/b/Foo.java Thu Mar  5 13:55:19 2015
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package util.b;
+
+/**
+ * Tester class used for {@link javax.el.TestImportHandler}.
+ */
+public class Foo {
+}

Propchange: tomcat/trunk/test/util/b/Foo.java
------------------------------------------------------------------------------
    svn:eol-style = native



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