From 85188b8dfea94a3523d6ab6a1dd6bdbe4bb47ac3 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 13 May 2019 13:28:07 +0200 Subject: [PATCH] Avoid expensive assertions in web resource resolution Closes gh-22955 --- .../resource/ResourceUrlEncodingFilter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index e6def68acea..cf3f16c7663 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -30,7 +30,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.lang.Nullable; -import org.springframework.util.Assert; import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.util.UrlPathHelper; @@ -87,7 +86,6 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { initLookupPath((ResourceUrlProvider) value); } } - } private void initLookupPath(ResourceUrlProvider urlProvider) { @@ -97,10 +95,12 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { String requestUri = pathHelper.getRequestUri(this); String lookupPath = pathHelper.getLookupPathForRequest(this); this.indexLookupPath = requestUri.lastIndexOf(lookupPath); - Assert.isTrue(this.indexLookupPath != -1, () -> - "Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " + - "Does the path have invalid encoded characters " + - "for characterEncoding=" + getRequest().getCharacterEncoding() + "?"); + if (this.indexLookupPath == -1) { + throw new IllegalStateException( + "Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + "'. " + + "Does the path have invalid encoded characters for characterEncoding '" + + getRequest().getCharacterEncoding() + "'?"); + } this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath); if ("/".equals(lookupPath) && !"/".equals(requestUri)) { String contextPath = pathHelper.getContextPath(this); @@ -116,7 +116,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { public String resolveUrlPath(String url) { if (this.resourceUrlProvider == null) { logger.trace("ResourceUrlProvider not available via request attribute " + - "ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR"); + ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR); return null; } if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) {