Always use MethodArgumentNotValidException(MethodParameter, BindingResult) constructor
gh-23846 introduced a new MethodArgumentNotValidException(Executable, BindingResult) constructor that can be advantageously replaced by using MethodArgumentNotValidException(MethodParameter, BindingResult) in ModelAttributeMethodProcessor. This commit updates ModelAttributeMethodProcessor accordingly, and deprecates MethodArgumentNotValidException(Executable, BindingResult) in favor of MethodArgumentNotValidException(MethodParameter, BindingResult). Closes gh-30558
This commit is contained in:
@@ -75,7 +75,9 @@ public class MethodArgumentNotValidException extends BindException implements Er
|
||||
* @param executable the executable that failed validation
|
||||
* @param bindingResult the results of the validation
|
||||
* @since 6.0.5
|
||||
* @deprecated in favor of {@link #MethodArgumentNotValidException(MethodParameter, BindingResult)}
|
||||
*/
|
||||
@Deprecated(since = "6.0.10", forRemoval = true)
|
||||
public MethodArgumentNotValidException(Executable executable, BindingResult bindingResult) {
|
||||
super(bindingResult);
|
||||
this.parameter = null;
|
||||
|
||||
@@ -341,7 +341,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol
|
||||
BindingResult result = binder.getBindingResult();
|
||||
ObjectError error = new ObjectError(ctor.getName(), cause.getMessage());
|
||||
result.addError(error);
|
||||
throw new MethodArgumentNotValidException(ctor, result);
|
||||
throw new MethodArgumentNotValidException(parameter, result);
|
||||
}
|
||||
else {
|
||||
throw ex;
|
||||
|
||||
Reference in New Issue
Block a user