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 4b2d8d7045 Fix BZ 66541 - Improve handling of URLs for cached resources 4b2d8d7045 is described below commit 4b2d8d70454980687d36aff1b6a0353d005f5c8d 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 07f479e062..f4894c7172 100644 --- a/java/org/apache/catalina/webresources/CachedResource.java +++ b/java/org/apache/catalina/webresources/CachedResource.java @@ -461,6 +461,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 34d05bf62d..92f17fbe23 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 51039b7e2f..ac14b072c3 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -151,6 +151,14 @@ be skipped when generating a response to a <code>TRACE</code> request. This aligns with 11.0.x. (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