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 2024/11/20 20:28:42 UTC

(tomcat) branch 10.1.x updated (7dcb261c80 -> 90daec2efe)

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

markt pushed a change to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


    from 7dcb261c80 Add missing quotes for etag
     new ae8381c311 Avoid throw - catch - re-throw for CNFE
     new 90daec2efe Fix BZ 69447 notFoundClassResources should allow for external resources

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../catalina/loader/WebappClassLoaderBase.java     | 79 ++++++++++++----------
 webapps/docs/changelog.xml                         |  6 ++
 2 files changed, 49 insertions(+), 36 deletions(-)


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


(tomcat) 02/02: Fix BZ 69447 notFoundClassResources should allow for external resources

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 90daec2efea24d6998ac615e9b86f02457532176
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     | 69 ++++++++++++----------
 webapps/docs/changelog.xml                         |  6 ++
 2 files changed, 44 insertions(+), 31 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index 488e3c037f..7a8946e0a3 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -773,6 +773,12 @@ public abstract class WebappClassLoaderBase extends URLClassLoader
 
         checkStateForClassLoading(name);
 
+        if (name == null) {
+            throw new ClassNotFoundException("null");
+        }
+
+        String path = binaryNameToPath(name, true);
+
         // (1) Permission to define this class when using a SecurityManager
         if (securityManager != null) {
             int i = name.lastIndexOf('.');
@@ -798,25 +804,14 @@ public abstract class WebappClassLoaderBase extends URLClassLoader
             if (log.isTraceEnabled()) {
                 log.trace("      findClassInternal(" + name + ")");
             }
-            try {
-                if (securityManager != null) {
-                    PrivilegedAction<Class<?>> dp = new PrivilegedFindClassByName(name);
-                    clazz = AccessController.doPrivileged(dp);
-                } else {
-                    clazz = findClassInternal(name);
-                }
-            } catch (AccessControlException ace) {
-                log.warn(sm.getString("webappClassLoader.securityException", name, ace.getMessage()), ace);
-                throw new ClassNotFoundException(name, ace);
-            } 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);
+                    if (securityManager != null) {
+                        PrivilegedAction<Class<?>> dp = new PrivilegedFindClassByName(name);
+                        clazz = AccessController.doPrivileged(dp);
+                    } else {
+                        clazz = findClassInternal(name);
+                    }
                 } catch (AccessControlException ace) {
                     log.warn(sm.getString("webappClassLoader.securityException", name, ace.getMessage()), ace);
                     throw new ClassNotFoundException(name, ace);
@@ -826,17 +821,32 @@ public abstract class WebappClassLoaderBase extends URLClassLoader
                     }
                     throw e;
                 }
+                if (clazz == null && hasExternalRepositories) {
+                    try {
+                        clazz = super.findClass(name);
+                    } catch (AccessControlException ace) {
+                        log.warn(sm.getString("webappClassLoader.securityException", name, ace.getMessage()), ace);
+                        throw new ClassNotFoundException(name, ace);
+                    } 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);
         }
 
@@ -2197,11 +2207,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);
@@ -2211,17 +2216,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;
             }
 
@@ -2254,14 +2265,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 e340fc7087..e5d027d0d7 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -159,6 +159,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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


(tomcat) 01/02: Avoid throw - catch - re-throw for CNFE

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ae8381c311543098148babf20fb4c4b7cf92b433
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Nov 20 20:15:44 2024 +0000

    Avoid throw - catch - re-throw for CNFE
---
 java/org/apache/catalina/loader/WebappClassLoaderBase.java | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappClassLoaderBase.java b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
index fcab37c9b6..488e3c037f 100644
--- a/java/org/apache/catalina/loader/WebappClassLoaderBase.java
+++ b/java/org/apache/catalina/loader/WebappClassLoaderBase.java
@@ -827,18 +827,18 @@ public abstract class WebappClassLoaderBase extends URLClassLoader
                     throw e;
                 }
             }
-            if (clazz == null) {
-                if (log.isTraceEnabled()) {
-                    log.trace("    --> Returning ClassNotFoundException");
-                }
-                throw new ClassNotFoundException(name);
-            }
         } catch (ClassNotFoundException e) {
             if (log.isTraceEnabled()) {
                 log.trace("    --> Passing on ClassNotFoundException");
             }
             throw e;
         }
+        if (clazz == null) {
+            if (log.isTraceEnabled()) {
+                log.trace("    --> Returning ClassNotFoundException");
+            }
+            throw new ClassNotFoundException(name);
+        }
 
         // Return the class we have located
         if (log.isTraceEnabled()) {


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