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 a98c781268 Additional fix with test cases for BZ 69623
a98c781268 is described below

commit a98c781268d4e70bd16fbf27bd48de3b08fb5165
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Jan 7 15:10:25 2026 +0000

    Additional fix with test cases for BZ 69623
    
    Calls to ClassLoader.getResource().getContent() failed when made from
    within a web application with resource caching enabled if the target
    resource was packaged in a JAR file.
    https://bz.apache.org/bugzilla/show_bug.cgi?id=69623
---
 .../catalina/webresources/CachedResource.java      |   5 +++
 .../catalina/loader/TestVirtualWebappLoader.java   |   4 +--
 .../catalina/webresources/TestCachedResource.java  |  35 +++++++++++++++++++++
 test/webapp/WEB-INF/classes/bug69623-a.mdd         |   1 +
 test/webapp/WEB-INF/lib/bug69623-lib.jar           | Bin 0 -> 517 bytes
 webapps/docs/changelog.xml                         |  10 ++++++
 6 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/webresources/CachedResource.java 
b/java/org/apache/catalina/webresources/CachedResource.java
index 6bdd117002..a86f9fd504 100644
--- a/java/org/apache/catalina/webresources/CachedResource.java
+++ b/java/org/apache/catalina/webresources/CachedResource.java
@@ -663,5 +663,10 @@ public class CachedResource implements WebResource {
             return ((JarURLConnection) 
resourceURL.openConnection()).getJarFile();
         }
 
+        @Override
+        public String getContentType() {
+            // "content/unknown" is the value used by 
sun.net.www.URLConnection. It is used here for consistency.
+            return Objects.requireNonNullElse(getResource().getMimeType(), 
"content/unknown");
+        }
     }
 }
diff --git a/test/org/apache/catalina/loader/TestVirtualWebappLoader.java 
b/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
index 67bf9f17eb..02796d426c 100644
--- a/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
+++ b/test/org/apache/catalina/loader/TestVirtualWebappLoader.java
@@ -86,7 +86,7 @@ public class TestVirtualWebappLoader extends TomcatBaseTest {
 
         loader.start();
         String[] repos = loader.getLoaderRepositories();
-        Assert.assertEquals(5, repos.length);
+        Assert.assertEquals(6, repos.length);
         loader.stop();
 
         repos = loader.getLoaderRepositories();
@@ -95,7 +95,7 @@ public class TestVirtualWebappLoader extends TomcatBaseTest {
         // no leak
         loader.start();
         repos = loader.getLoaderRepositories();
-        Assert.assertEquals(5, repos.length);
+        Assert.assertEquals(6, repos.length);
 
         // clear loader
         ctx.setLoader(null);
diff --git a/test/org/apache/catalina/webresources/TestCachedResource.java 
b/test/org/apache/catalina/webresources/TestCachedResource.java
index 158b31d530..237dd8169f 100644
--- a/test/org/apache/catalina/webresources/TestCachedResource.java
+++ b/test/org/apache/catalina/webresources/TestCachedResource.java
@@ -16,6 +16,7 @@
  */
 package org.apache.catalina.webresources;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.InputStream;
 import java.net.JarURLConnection;
@@ -131,4 +132,38 @@ public class TestCachedResource extends TomcatBaseTest {
             Assert.assertNotNull(is);
         }
     }
+
+
+    @Test
+    public void testGetContentWebInfClasses() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        File docBase = new File("test/webapp");
+        Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
+        tomcat.start();
+
+        URL url = 
ctx.getLoader().getClassLoader().getResource("bug69623-a.mdd");
+        Object o = url.getContent();
+        /*
+         * Could test the actual content but a non-null return without an 
exception is enough to demonstrate the bug has
+         * not occurred.
+         */
+        Assert.assertTrue(o instanceof ByteArrayInputStream);
+    }
+
+
+    @Test
+    public void testGetContentWebInfLib() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        File docBase = new File("test/webapp");
+        Context ctx = tomcat.addWebapp("/test", docBase.getAbsolutePath());
+        tomcat.start();
+
+        URL url = 
ctx.getLoader().getClassLoader().getResource("bug69623-b.mdd");
+        Object o = url.getContent();
+        /*
+         * Could test the actual content but a non-null return without an 
exception is enough to demonstrate the bug has
+         * not occurred.
+         */
+        Assert.assertTrue(o instanceof ByteArrayInputStream);
+    }
 }
diff --git a/test/webapp/WEB-INF/classes/bug69623-a.mdd 
b/test/webapp/WEB-INF/classes/bug69623-a.mdd
new file mode 100644
index 0000000000..a9c234eede
--- /dev/null
+++ b/test/webapp/WEB-INF/classes/bug69623-a.mdd
@@ -0,0 +1 @@
+This is a test file for https://bz.apache.org/bugzilla/show_bug.cgi?id=69623
\ No newline at end of file
diff --git a/test/webapp/WEB-INF/lib/bug69623-lib.jar 
b/test/webapp/WEB-INF/lib/bug69623-lib.jar
new file mode 100644
index 0000000000..1be5365199
Binary files /dev/null and b/test/webapp/WEB-INF/lib/bug69623-lib.jar differ
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 42de3058bb..32a92c098f 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,16 @@
   issues do not "pop up" wrt. others).
 -->
 <section name="Tomcat 11.0.16 (markt)" rtext="in development">
+  <subsection name="Catalina">
+    <changelog>
+      <fix>
+        <bug>69623</bug>: Additional fix for the long standing regression that
+        meant that calls to <code>ClassLoader.getResource().getContent()</code>
+        failed when made from within a web application with resource caching
+        enabled if the target resource was packaged in a JAR file. (markt)
+      </fix>
+    </changelog>
+  </subsection>
   <subsection name="Coyote">
     <changelog>
       <fix>


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

Reply via email to