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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 1931f52cc8 Fix BZ 69837 - corrupted class path from Loader on Windows
1931f52cc8 is described below

commit 1931f52cc820e6f5674e8c993c0930d499e2873a
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Oct 9 10:36:00 2025 +0100

    Fix BZ 69837 - corrupted class path from Loader on Windows
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=69837
---
 java/org/apache/catalina/loader/WebappLoader.java | 18 ++++++++++--------
 webapps/docs/changelog.xml                        |  4 ++++
 2 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/catalina/loader/WebappLoader.java 
b/java/org/apache/catalina/loader/WebappLoader.java
index fcd7b1ce81..1ed39f81ff 100644
--- a/java/org/apache/catalina/loader/WebappLoader.java
+++ b/java/org/apache/catalina/loader/WebappLoader.java
@@ -23,9 +23,9 @@ import java.io.File;
 import java.io.FilePermission;
 import java.io.IOException;
 import java.lang.reflect.Constructor;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
-import java.nio.charset.StandardCharsets;
 
 import javax.management.ObjectName;
 import javax.servlet.ServletContext;
@@ -40,7 +40,6 @@ import org.apache.catalina.util.ToStringUtil;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.ExceptionUtils;
-import org.apache.tomcat.util.buf.UDecoder;
 import org.apache.tomcat.util.compat.JreCompat;
 import org.apache.tomcat.util.modeler.Registry;
 import org.apache.tomcat.util.res.StringManager;
@@ -571,10 +570,14 @@ public class WebappLoader extends LifecycleMBeanBase 
implements Loader, Property
             URL[] repositories = ((URLClassLoader) loader).getURLs();
             for (URL url : repositories) {
                 String repository = url.toString();
-                if (repository.startsWith("file://")) {
-                    repository = UDecoder.URLDecode(repository.substring(7), 
StandardCharsets.UTF_8);
-                } else if (repository.startsWith("file:")) {
-                    repository = UDecoder.URLDecode(repository.substring(5), 
StandardCharsets.UTF_8);
+                if (repository.startsWith("file:")) {
+                    // Let the JRE handle all the edge cases for URL to path 
conversion.
+                    try {
+                        File f = new File(url.toURI());
+                        repository = f.getAbsolutePath();
+                    } catch (URISyntaxException e) {
+                        // Can't convert from URL to URI. Treat as non-file 
URL and skip.
+                    }
                 } else {
                     continue;
                 }
@@ -587,8 +590,7 @@ public class WebappLoader extends LifecycleMBeanBase 
implements Loader, Property
                 classpath.append(repository);
             }
         } else if (loader == ClassLoader.getSystemClassLoader()) {
-            // Java 9 onwards. The internal class loaders no longer extend
-            // URLCLassLoader
+            // From Java 9 the internal class loaders no longer extend 
URLCLassLoader
             String cp = System.getProperty("java.class.path");
             if (cp != null && !cp.isEmpty()) {
                 if (classpath.length() > 0) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 1225461091..44fc7cbe44 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -116,6 +116,10 @@
         <code>RemoteAddValve</code> in favour of the
         <code>RemoteCIDRFilter</code> and <code>RemoteCIDRValve</code>. (markt)
       </update>
+      <fix>
+        <bug>69837</bug>: Fix corruption of the class path generated by the
+        Loader when running on Windows. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="WebSocket">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to