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 1997d2f62e Fix BZ 66541 - Improve handling of URLs for cached resources 1997d2f62e is described below commit 1997d2f62eb87db7c81e0136862cef4ca31c4fe5 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Mar 23 14:50:17 2023 +0000 Fix BZ 66541 - Improve handling of URLs for cached resources Improve handling for cached resources for resources that use custom URL schemes. The scheme specific equals() and hashcode() algorithms, if present, will now be used for URLs for these resources. This addresses a potential performance issue with some OSGi custom URL schemes that can trigger potentially slow DNS lookups in some configurations. --- .../catalina/webresources/CachedResource.java | 34 ++++++++++++++++++++++ res/spotbugs/filter-false-positives.xml | 9 ++++++ webapps/docs/changelog.xml | 8 +++++ 3 files changed, 51 insertions(+) diff --git a/java/org/apache/catalina/webresources/CachedResource.java b/java/org/apache/catalina/webresources/CachedResource.java index 80937068dc..8cd119752a 100644 --- a/java/org/apache/catalina/webresources/CachedResource.java +++ b/java/org/apache/catalina/webresources/CachedResource.java @@ -456,6 +456,40 @@ public class CachedResource implements WebResource { return constructedURL.openConnection(); } } + + /** + * {@inheritDoc} + * <p> + * We don't know what the requirements are for equals for the wrapped resourceURL so if u1 is the wrapped + * resourceURL, delegate to the resourceURL and it's handler. Otherwise, use the default implementation from + * URLStreamHandler. + */ + @Override + protected boolean equals(URL u1, URL u2) { + // Deliberate use of == + if (resourceURL == u1) { + return resourceURL.equals(u2); + } + // Not the original resourceURL. Use the default implementation from URLStreamHandler. + return super.equals(u1, u2); + } + + /** + * {@inheritDoc} + * <p> + * We don't know what the requirements are for hashcode for the wrapped resourceURL so if u1 is the wrapped + * resourceURL, delegate to the resourceURL and it's handler. Otherwise, use the default implementation from + * URLStreamHandler. + */ + @Override + protected int hashCode(URL u) { + // Deliberate use of == + if (resourceURL == u) { + return resourceURL.hashCode(); + } + // Not the original resourceURL. Use the default implementation from URLStreamHandler. + return super.hashCode(u); + } } diff --git a/res/spotbugs/filter-false-positives.xml b/res/spotbugs/filter-false-positives.xml index 7febcbb7bf..b9c6f0b7cc 100644 --- a/res/spotbugs/filter-false-positives.xml +++ b/res/spotbugs/filter-false-positives.xml @@ -886,6 +886,15 @@ </Or> <Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY"/> </Match> + <Match> + <!-- Delegation to URL methods is deliberate --> + <Class name="org.apache.catalina.webresources.CachedResource"/> + <Or> + <Method name="equals"/> + <Method name="hashCode"/> + </Or> + <Bug pattern="DMI_BLOCKING_METHODS_ON_URL"/> + </Match> <Match> <!-- Class lock is not an instance lock --> <Class name="org.apache.catalina.webresources.TomcatURLStreamHandlerFactory"/> diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index a33c5beae6..f6b86f7021 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -166,6 +166,14 @@ This aligns with the current draft of the Servlet 6.1 specification. (markt) </fix> + <fix> + <bug>66541</bug>: Improve handling for cached resources for resources + that use custom URL schemes. The scheme specific <code>equals()</code> + and <code>hashcode()</code> algorithms, if present, will now be used for + URLs for these resources. This addresses a potential performance issue + with some OSGi custom URL schemes that can trigger potentially slow DNS + lookups in some configurations. (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