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


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

commit 785ff2c575fc0b10a9b1ceb2ca6f995d76ecf1cf
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 cdead016df..45152d0840 100644
--- a/java/org/apache/catalina/loader/WebappLoader.java
+++ b/java/org/apache/catalina/loader/WebappLoader.java
@@ -22,9 +22,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;
 
@@ -43,7 +43,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;
@@ -504,10 +503,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;
                 }
@@ -520,8 +523,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.length() > 0) {
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 82cca92df2..0ff45c5ad9 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