Skip to content

Commit ecc22f7

Browse files
committed
DispatcherServet.checkMultipart considers MultipartException cause as well
Issue: SPR-15178
1 parent 7d3fcaa commit ecc22f7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -1091,7 +1091,7 @@ protected HttpServletRequest checkMultipart(HttpServletRequest request) throws M
10911091
logger.debug("Request is already a MultipartHttpServletRequest - if not in a forward, " +
10921092
"this typically results from an additional MultipartFilter in web.xml");
10931093
}
1094-
else if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) instanceof MultipartException) {
1094+
else if (hasMultipartException(request) ) {
10951095
logger.debug("Multipart resolution failed for current request before - " +
10961096
"skipping re-resolution for undisturbed error rendering");
10971097
}
@@ -1103,6 +1103,20 @@ else if (request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE) instanceof Mul
11031103
return request;
11041104
}
11051105

1106+
/**
1107+
* Check "javax.servlet.error.exception" attribute for a multipart exception.
1108+
*/
1109+
private boolean hasMultipartException(HttpServletRequest request) {
1110+
Throwable error = (Throwable) request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE);
1111+
while (error != null) {
1112+
if (error instanceof MultipartException) {
1113+
return true;
1114+
}
1115+
error = error.getCause();
1116+
}
1117+
return false;
1118+
}
1119+
11061120
/**
11071121
* Clean up any resources used by the given multipart request (if any).
11081122
* @param request current HTTP request

0 commit comments

Comments
 (0)