This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new b3a6834ede Fix static resources in a JAR file when using a bloom filter. b3a6834ede is described below commit b3a6834ede794b638f790c74a4da89fb442d8372 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Jun 12 13:24:21 2024 +0100 Fix static resources in a JAR file when using a bloom filter. Based on pull request #730 provided by bergander. --- .../webresources/AbstractArchiveResourceSet.java | 6 ++++-- .../webresources/TestAbstractArchiveResourceSet.java | 17 +++++++++++++++++ test/webresources/static-resources.jar | Bin 0 -> 823 bytes webapps/docs/changelog.xml | 5 +++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java index b34738834c..ec1ddd15cd 100644 --- a/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java +++ b/java/org/apache/catalina/webresources/AbstractArchiveResourceSet.java @@ -205,8 +205,10 @@ public abstract class AbstractArchiveResourceSet extends AbstractResourceSet { * If jarContents reports that this resource definitely does not contain the path, we can end this method and * move on to the next jar. */ - if (jarContents != null && !jarContents.mightContainResource(path, webAppMount)) { - return new EmptyResource(root, path); + if (jarContents != null && + !jarContents.mightContainResource(getInternalPath().isEmpty() ? path : getInternalPath() + path, + webAppMount)) { + return new EmptyResource(root, path); } /* diff --git a/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java index acaff361d5..47fdc7c97f 100644 --- a/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java +++ b/test/org/apache/catalina/webresources/TestAbstractArchiveResourceSet.java @@ -78,6 +78,23 @@ public class TestAbstractArchiveResourceSet { Assert.assertNull(getJarContents(jarResourceSet)); } + @Test + public void testBloomFilterWithJarResource() throws Exception { + WebResourceRoot root = new TesterWebResourceRoot(); + + root.setArchiveIndexStrategy(WebResourceRoot.ArchiveIndexStrategy.BLOOM.name()); + + File file = new File("test/webresources/static-resources.jar"); + + JarResourceSet jarResourceSet = new JarResourceSet(root, "/", file.getAbsolutePath(), "/META-INF/resources"); + jarResourceSet.getArchiveEntries(false); + Assert.assertNotNull(getJarContents(jarResourceSet)); + + WebResource r1 = jarResourceSet.getResource("/index.html"); + Assert.assertTrue(r1.isFile()); + + } + private JarContents getJarContents(Object target) throws IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException { Field field = AbstractArchiveResourceSet.class.getDeclaredField("jarContents"); diff --git a/test/webresources/static-resources.jar b/test/webresources/static-resources.jar new file mode 100644 index 0000000000..8403903010 Binary files /dev/null and b/test/webresources/static-resources.jar differ diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 8d5b6fc599..589bd0e6e6 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -128,6 +128,11 @@ instances of <code>LinkageError</code> to be reported as <code>ClassNotFoundException</code>. (markt) </fix> + <fix> + Ensure that static resources deployed via a JAR file remain accessible + when the context is configured to use a bloom filter. Based on pull + request <pr>730</pr> provided by bergander. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org