File tree Expand file tree Collapse file tree 6 files changed +49
-2
lines changed
java/org/apache/catalina/webresources Expand file tree Collapse file tree 6 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -663,5 +663,10 @@ public JarFile getJarFile() throws IOException {
663663 return ((JarURLConnection ) resourceURL .openConnection ()).getJarFile ();
664664 }
665665
666+ @ Override
667+ public String getContentType () {
668+ // "content/unknown" is the value used by sun.net.www.URLConnection. It is used here for consistency.
669+ return Objects .requireNonNullElse (getResource ().getMimeType (), "content/unknown" );
670+ }
666671 }
667672}
Original file line number Diff line number Diff line change @@ -86,7 +86,7 @@ public void testStartInternal() throws Exception {
8686
8787 loader .start ();
8888 String [] repos = loader .getLoaderRepositories ();
89- Assert .assertEquals (5 , repos .length );
89+ Assert .assertEquals (6 , repos .length );
9090 loader .stop ();
9191
9292 repos = loader .getLoaderRepositories ();
@@ -95,7 +95,7 @@ public void testStartInternal() throws Exception {
9595 // no leak
9696 loader .start ();
9797 repos = loader .getLoaderRepositories ();
98- Assert .assertEquals (5 , repos .length );
98+ Assert .assertEquals (6 , repos .length );
9999
100100 // clear loader
101101 ctx .setLoader (null );
Original file line number Diff line number Diff line change 1616 */
1717package org .apache .catalina .webresources ;
1818
19+ import java .io .ByteArrayInputStream ;
1920import java .io .File ;
2021import java .io .InputStream ;
2122import java .net .JarURLConnection ;
@@ -131,4 +132,38 @@ public void testDirectoryListingsDir() throws Exception {
131132 Assert .assertNotNull (is );
132133 }
133134 }
135+
136+
137+ @ Test
138+ public void testGetContentWebInfClasses () throws Exception {
139+ Tomcat tomcat = getTomcatInstance ();
140+ File docBase = new File ("test/webapp" );
141+ Context ctx = tomcat .addWebapp ("/test" , docBase .getAbsolutePath ());
142+ tomcat .start ();
143+
144+ URL url = ctx .getLoader ().getClassLoader ().getResource ("bug69623-a.mdd" );
145+ Object o = url .getContent ();
146+ /*
147+ * Could test the actual content but a non-null return without an exception is enough to demonstrate the bug has
148+ * not occurred.
149+ */
150+ Assert .assertTrue (o instanceof ByteArrayInputStream );
151+ }
152+
153+
154+ @ Test
155+ public void testGetContentWebInfLib () throws Exception {
156+ Tomcat tomcat = getTomcatInstance ();
157+ File docBase = new File ("test/webapp" );
158+ Context ctx = tomcat .addWebapp ("/test" , docBase .getAbsolutePath ());
159+ tomcat .start ();
160+
161+ URL url = ctx .getLoader ().getClassLoader ().getResource ("bug69623-b.mdd" );
162+ Object o = url .getContent ();
163+ /*
164+ * Could test the actual content but a non-null return without an exception is enough to demonstrate the bug has
165+ * not occurred.
166+ */
167+ Assert .assertTrue (o instanceof ByteArrayInputStream );
168+ }
134169}
Original file line number Diff line number Diff line change 1+ This is a test file for https://bz.apache.org/bugzilla/show_bug.cgi?id=69623
Original file line number Diff line number Diff line change 191191 to <code >true</code >. (markt)
192192 </update >
193193 <!-- Entries for backport and removal before 12.0.0-M1 below this line -->
194+ <fix >
195+ <bug >69623</bug >: Additional fix for the long standing regression that
196+ meant that calls to <code >ClassLoader.getResource().getContent()</code >
197+ failed when made from within a web application with resource caching
198+ enabled if the target resource was packaged in a JAR file. (markt)
199+ </fix >
194200 </changelog >
195201 </subsection >
196202 <subsection name =" Coyote" >
You can’t perform that action at this time.
0 commit comments