mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 14:09:25 +00:00
SPR-8001 Recognize case when MultipartRequest is null and argument is of type MultipartFile and raise helpful exception.
git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4714 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
+15
-13
@@ -136,7 +136,10 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
||||
}
|
||||
}
|
||||
|
||||
checkMissingRequiredValue(arg, partName, parameter);
|
||||
if (arg == null) {
|
||||
handleMissingValue(partName, parameter);
|
||||
}
|
||||
|
||||
return arg;
|
||||
}
|
||||
|
||||
@@ -170,19 +173,18 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM
|
||||
}
|
||||
|
||||
/**
|
||||
* Raises a {@link ServletRequestBindingException} if the method parameter is required
|
||||
* and the resolved argument value is null.
|
||||
* Invoked if the resolved argument value is {@code null}. The default implementation raises
|
||||
* a {@link ServletRequestBindingException} if the method parameter is required.
|
||||
* @param partName the name used to look up the request part
|
||||
* @param param the method argument
|
||||
*/
|
||||
protected void checkMissingRequiredValue(Object argumentValue, String partName, MethodParameter parameter)
|
||||
throws ServletRequestBindingException {
|
||||
if (argumentValue == null) {
|
||||
RequestPart annot = parameter.getParameterAnnotation(RequestPart.class);
|
||||
boolean isRequired = (annot != null) ? annot.required() : true;
|
||||
if (isRequired) {
|
||||
String paramType = parameter.getParameterType().getName();
|
||||
throw new ServletRequestBindingException(
|
||||
"Missing request part '" + partName + "' for method parameter type [" + paramType + "]");
|
||||
}
|
||||
protected void handleMissingValue(String partName, MethodParameter param) throws ServletRequestBindingException {
|
||||
RequestPart annot = param.getParameterAnnotation(RequestPart.class);
|
||||
boolean isRequired = (annot != null) ? annot.required() : true;
|
||||
if (isRequired) {
|
||||
String paramType = param.getParameterType().getName();
|
||||
throw new ServletRequestBindingException(
|
||||
"Missing request part '" + partName + "' for method parameter type [" + paramType + "]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user