Skip to content

Commit 85188b8

Browse files
committed
Avoid expensive assertions in web resource resolution
Closes gh-22955
1 parent 8ab0f63 commit 85188b8

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.apache.commons.logging.LogFactory;
3131

3232
import org.springframework.lang.Nullable;
33-
import org.springframework.util.Assert;
3433
import org.springframework.web.filter.GenericFilterBean;
3534
import org.springframework.web.util.UrlPathHelper;
3635

@@ -87,7 +86,6 @@ public void setAttribute(String name, Object value) {
8786
initLookupPath((ResourceUrlProvider) value);
8887
}
8988
}
90-
9189
}
9290

9391
private void initLookupPath(ResourceUrlProvider urlProvider) {
@@ -97,10 +95,12 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
9795
String requestUri = pathHelper.getRequestUri(this);
9896
String lookupPath = pathHelper.getLookupPathForRequest(this);
9997
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
100-
Assert.isTrue(this.indexLookupPath != -1, () ->
101-
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " +
102-
"Does the path have invalid encoded characters " +
103-
"for characterEncoding=" + getRequest().getCharacterEncoding() + "?");
98+
if (this.indexLookupPath == -1) {
99+
throw new IllegalStateException(
100+
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + "'. " +
101+
"Does the path have invalid encoded characters for characterEncoding '" +
102+
getRequest().getCharacterEncoding() + "'?");
103+
}
104104
this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);
105105
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
106106
String contextPath = pathHelper.getContextPath(this);
@@ -116,7 +116,7 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
116116
public String resolveUrlPath(String url) {
117117
if (this.resourceUrlProvider == null) {
118118
logger.trace("ResourceUrlProvider not available via request attribute " +
119-
"ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR");
119+
ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR);
120120
return null;
121121
}
122122
if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) {

0 commit comments

Comments
 (0)