Skip to content

Commit 4753de5

Browse files
authored
Avoid NPE when merging trailers in GrpcExceptionHandledServerCall
This commit adds a null check on the trailers returns by the status exception in `GrpcExceptionHandledServerCall` and only merges the exceptions trailers when they are non-null. Fixes #229 Signed-off-by: Andrey Litvitski <[email protected]>
1 parent b3eb9c2 commit 4753de5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

spring-grpc-core/src/main/java/org/springframework/grpc/server/exception/GrpcExceptionHandledServerCall.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ public void close(Status status, Metadata trailers) {
3636
if (status.getCode() == Status.Code.UNKNOWN && status.getCause() != null) {
3737
final Throwable cause = status.getCause();
3838
final StatusException statusException = this.exceptionHandler.handleException(cause);
39-
trailers.merge(statusException.getTrailers());
39+
Metadata statusExceptionTrailers = statusException.getTrailers();
40+
if (statusExceptionTrailers != null) {
41+
trailers.merge(statusExceptionTrailers);
42+
}
4043
super.close(statusException.getStatus(), trailers);
4144
}
4245
else {

0 commit comments

Comments
 (0)