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

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


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

commit 95cbfa4f38b1c57a5f42d45ba2577d7f4fdb7b54
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 8627aac52e..5c8183e2e9 100644
--- a/java/org/apache/catalina/loader/WebappLoader.java
+++ b/java/org/apache/catalina/loader/WebappLoader.java
@@ -20,9 +20,9 @@ import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeSupport;
 import java.io.File;
 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;
 
@@ -41,7 +41,6 @@ import org.apache.tomcat.jakartaee.ClassConverter;
 import org.apache.tomcat.jakartaee.EESpecProfile;
 import org.apache.tomcat.jakartaee.EESpecProfiles;
 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;
@@ -467,10 +466,14 @@ public class WebappLoader extends LifecycleMBeanBase 
implements Loader {
             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;
                 }
@@ -483,8 +486,7 @@ public class WebappLoader extends LifecycleMBeanBase 
implements Loader {
                 classpath.append(repository);
             }
         } else if (loader == ClassLoader.getSystemClassLoader()) {
-            // From Java 9 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.isEmpty()) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 5c996e96b0..bb5b478a39 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -122,6 +122,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="Coyote">


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

Reply via email to