This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 1ef2b68a582084e645ec3c9a6cc1366cfedef45e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 20 20:20:59 2024 +0000

    Fix BZ 69447 notFoundClassResources should allow for external resources
---
 .../catalina/loader/WebappClassLoaderBase.java     | 53 ++++++++++++----------
 webapps/docs/changelog.xml                         |  6 +++
 2 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java 
b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index 86f705fd9a..a34223a0b7 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -632,6 +632,12 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
 
         checkStateForClassLoading(name);
 
+        if (name == null) {
+            throw new ClassNotFoundException("null");
+        }
+
+        String path = binaryNameToPath(name, true);
+
         // Ask our superclass to locate this class, if possible
         // (throws ClassNotFoundException if it is not found)
         Class<?> clazz = null;
@@ -639,34 +645,38 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
             if (log.isTraceEnabled()) {
                 log.trace("      findClassInternal(" + name + ")");
             }
-            try {
-                clazz = findClassInternal(name);
-            } catch (RuntimeException e) {
-                if (log.isTraceEnabled()) {
-                    log.trace("      -->RuntimeException Rethrown", e);
-                }
-                throw e;
-            }
-            if (clazz == null && hasExternalRepositories) {
+            if (!notFoundClassResources.contains(path)) {
                 try {
-                    clazz = super.findClass(name);
+                    clazz = findClassInternal(name, path);
                 } catch (RuntimeException e) {
                     if (log.isTraceEnabled()) {
                         log.trace("      -->RuntimeException Rethrown", e);
                     }
                     throw e;
                 }
+                if (clazz == null && hasExternalRepositories) {
+                    try {
+                        clazz = super.findClass(name);
+                    } catch (RuntimeException e) {
+                        if (log.isTraceEnabled()) {
+                            log.trace("      -->RuntimeException Rethrown", e);
+                        }
+                        throw e;
+                    }
+                }
             }
         } catch (ClassNotFoundException e) {
             if (log.isTraceEnabled()) {
                 log.trace("    --> Passing on ClassNotFoundException");
             }
+            notFoundClassResources.add(path);
             throw e;
         }
         if (clazz == null) {
             if (log.isTraceEnabled()) {
                 log.trace("    --> Returning ClassNotFoundException");
             }
+            notFoundClassResources.add(path);
             throw new ClassNotFoundException(name);
         }
 
@@ -1979,11 +1989,6 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
      *
      * @return the loaded class, or null if the class isn't found
      */
-    /*
-     * The use of getPackage() is appropriate given that the code is checking 
if the package is sealed. Therefore,
-     * parent class loaders need to be checked.
-     */
-    @SuppressWarnings("deprecation")
     protected Class<?> findClassInternal(String name) {
 
         checkStateForResourceLoading(name);
@@ -1993,17 +1998,23 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
         }
         String path = binaryNameToPath(name, true);
 
+        return findClassInternal(name, path);
+    }
+
+
+    /*
+     * The use of getPackage() is appropriate given that the code is checking 
if the package is sealed. Therefore,
+     * parent class loaders need to be checked.
+     */
+    @SuppressWarnings("deprecation")
+    private Class<?> findClassInternal(String name, String path) {
         ResourceEntry entry = resourceEntries.get(path);
         WebResource resource = null;
 
         if (entry == null) {
-            if (notFoundClassResources.contains(path)) {
-                return null;
-            }
             resource = resources.getClassLoaderResource(path);
 
             if (!resource.exists()) {
-                notFoundClassResources.add(path);
                 return null;
             }
 
@@ -2036,14 +2047,10 @@ public abstract class WebappClassLoaderBase extends 
URLClassLoader
             }
 
             if (resource == null) {
-                if (notFoundClassResources.contains(path)) {
-                    return null;
-                }
                 resource = resources.getClassLoaderResource(path);
             }
 
             if (!resource.exists()) {
-                notFoundClassResources.add(path);
                 return null;
             }
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index c1bf93447e..0713842f63 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -167,6 +167,12 @@
         <code>Cache-Control</code> headers in the <code>ExpiresFilter</code>.
         Based on pull request <pr>777</pr> by Chenjp. (markt)
       </fix>
+      <fix>
+        <bug>69447</bug>: Update the support for caching classes the web
+        application class loader cannot find to take account of classes loaded
+        from external repositories. Prior to this fix, these classes could be
+        incorrectly marked as not found. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">


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

Reply via email to