Skip to content

Commit 0a6a606

Browse files
committed
GH-1491: Fix Possible NPE
1 parent 158d5cd commit 0a6a606

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

spring-rabbit/src/main/java/org/springframework/amqp/rabbit/annotation/RabbitListenerAnnotationBeanPostProcessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.lang.reflect.AnnotatedElement;
2020
import java.lang.reflect.Method;
21-
import java.lang.reflect.Type;
2221
import java.nio.charset.Charset;
2322
import java.nio.charset.StandardCharsets;
2423
import java.util.ArrayList;
@@ -100,6 +99,7 @@
10099
import org.springframework.util.CollectionUtils;
101100
import org.springframework.util.ReflectionUtils;
102101
import org.springframework.util.StringUtils;
102+
import org.springframework.validation.BindingResult;
103103
import org.springframework.validation.ObjectError;
104104
import org.springframework.validation.Validator;
105105

@@ -1055,11 +1055,15 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
10551055
}
10561056
catch (MethodArgumentNotValidException ex) {
10571057
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+
}
10631067
}
10641068
}
10651069
throw ex;

0 commit comments

Comments
 (0)