pjfanning opened a new pull request, #920:
URL: https://github.com/apache/pekko-grpc/pull/920

   ### Motivation
   A `StatusRuntimeException` created without trailers (e.g. `new 
StatusRuntimeException(Status.UNAVAILABLE)`) has `null` trailers. 
`GrpcServiceException(ex)` and the javadsl `GrpcExceptionHandler` wrapped them 
in a `GrpcMetadataImpl`, which failed with a `NullPointerException` in `asList` 
when the trailers were written to the response. The request then completed with 
an HTTP 500 instead of the gRPC status (akka/akka-grpc#1854).
   
   `GrpcServiceException(code, message, details)` also used a plain 
`GrpcMetadataImpl`, so its metadata was not a `MetadataStatus`.
   
   ### Modification
   Port of akka/akka-grpc#1855 (Akka gRPC 2.4.0, Apache 2.0 since its change 
date, 2026-10-24):
   - `GrpcServiceException(ex)` uses empty metadata when the exception has no 
trailers.
   - `GrpcServiceException(code, message, details)` uses `RichGrpcMetadataImpl`.
   - `GrpcMetadataImpl` requires a non-null delegate.
   
   Pekko change on top of upstream: the javadsl `GrpcExceptionHandler` falls 
back to empty metadata, as the scaladsl handler already does. Upstream left the 
javadsl handler as it was, so with the new `require` it would fail while 
mapping the exception.
   
   ### Result
   A `StatusRuntimeException` without trailers maps to a gRPC status response 
with either DSL.
   
   ### Tests
   - New `GrpcServiceExceptionSpec` (new test, upstream has none). All 3 tests 
fail without the fix: 2 with the NPE, and 1 because the metadata is not a 
`MetadataStatus`. All 3 pass with the fix.
   - `sbt runtime/test`: 192 passed
   - `sbt runtime/mimaReportBinaryIssues`: passed
   - `scalafmt --mode diff-ref=upstream/main` run
   
   ### References
   Refs akka/akka-grpc#1855, akka/akka-grpc#1854
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to