This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 5f653b1bad Fix BZ 66541 - Improve handling of URLs for cached resources 5f653b1bad is described below commit 5f653b1bad0d64b5ed3efe7bb41a28da952fe5ad 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 dfb6b186d9..3e8629aac4 100644 --- a/res/spotbugs/filter-false-positives.xml +++ b/res/spotbugs/filter-false-positives.xml @@ -883,6 +883,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 10ab299e6c..afab168f00 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -146,6 +146,14 @@ Add support code for custom user attributes in <code>RealmBase</code>. Based on code from <pr>473</pr> by Carsten Klein. (remm) </update> + <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