|
18 | 18 |
|
19 | 19 | import java.lang.reflect.AnnotatedElement; |
20 | 20 | import java.lang.reflect.Method; |
21 | | -import java.lang.reflect.Type; |
22 | 21 | import java.nio.charset.Charset; |
23 | 22 | import java.nio.charset.StandardCharsets; |
24 | 23 | import java.util.ArrayList; |
|
100 | 99 | import org.springframework.util.CollectionUtils; |
101 | 100 | import org.springframework.util.ReflectionUtils; |
102 | 101 | import org.springframework.util.StringUtils; |
| 102 | +import org.springframework.validation.BindingResult; |
103 | 103 | import org.springframework.validation.ObjectError; |
104 | 104 | import org.springframework.validation.Validator; |
105 | 105 |
|
@@ -1055,11 +1055,15 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr |
1055 | 1055 | } |
1056 | 1056 | catch (MethodArgumentNotValidException ex) { |
1057 | 1057 | if (message.getPayload().equals(Optional.empty())) { |
1058 | | - Type type = parameter.getGenericParameterType(); |
1059 | | - List<ObjectError> allErrors = ex.getBindingResult().getAllErrors(); |
1060 | | - if (allErrors.size() == 1 |
1061 | | - && allErrors.get(0).getDefaultMessage().equals("Payload value must not be empty")) { |
1062 | | - return Optional.empty(); |
| 1058 | + BindingResult bindingResult = ex.getBindingResult(); |
| 1059 | + if (bindingResult != null) { |
| 1060 | + List<ObjectError> allErrors = bindingResult.getAllErrors(); |
| 1061 | + if (allErrors.size() == 1) { |
| 1062 | + String defaultMessage = allErrors.get(0).getDefaultMessage(); |
| 1063 | + if ("Payload value must not be empty".equals(defaultMessage)) { |
| 1064 | + return Optional.empty(); |
| 1065 | + } |
| 1066 | + } |
1063 | 1067 | } |
1064 | 1068 | } |
1065 | 1069 | throw ex; |
|
0 commit comments