Skip to content

Commit ed3df72

Browse files
committed
Avoid expensive assertions in web resource resolution
Closes gh-22955
1 parent 9ad9025 commit ed3df72

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public void setAttribute(String name, Object value) {
8484
initLookupPath((ResourceUrlProvider) value);
8585
}
8686
}
87-
8887
}
8988

9089
private void initLookupPath(ResourceUrlProvider urlProvider) {
@@ -94,10 +93,12 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
9493
String requestUri = pathHelper.getRequestUri(this);
9594
String lookupPath = pathHelper.getLookupPathForRequest(this);
9695
this.indexLookupPath = requestUri.lastIndexOf(lookupPath);
97-
Assert.isTrue(this.indexLookupPath != -1,
98-
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + ". " +
99-
"Does the path have invalid encoded characters " +
100-
"for characterEncoding=" + getRequest().getCharacterEncoding() + "?");
96+
if (this.indexLookupPath == -1) {
97+
throw new IllegalStateException(
98+
"Failed to find lookupPath '" + lookupPath + "' within requestUri '" + requestUri + "'. " +
99+
"Does the path have invalid encoded characters for characterEncoding '" +
100+
getRequest().getCharacterEncoding() + "'?");
101+
}
101102
this.prefixLookupPath = requestUri.substring(0, this.indexLookupPath);
102103
if ("/".equals(lookupPath) && !"/".equals(requestUri)) {
103104
String contextPath = pathHelper.getContextPath(this);
@@ -112,7 +113,7 @@ private void initLookupPath(ResourceUrlProvider urlProvider) {
112113
public String resolveUrlPath(String url) {
113114
if (this.resourceUrlProvider == null) {
114115
logger.trace("ResourceUrlProvider not available via request attribute " +
115-
"ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR");
116+
ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR);
116117
return null;
117118
}
118119
if (this.indexLookupPath != null && url.startsWith(this.prefixLookupPath)) {

0 commit comments

Comments
 (0)