diff --git a/runtime/src/main/scala/akka/grpc/GrpcServiceException.scala b/runtime/src/main/scala/akka/grpc/GrpcServiceException.scala index 341af487c..433eb0bc4 100644 --- a/runtime/src/main/scala/akka/grpc/GrpcServiceException.scala +++ b/runtime/src/main/scala/akka/grpc/GrpcServiceException.scala @@ -7,7 +7,7 @@ package akka.grpc import io.grpc.{ Status, StatusRuntimeException } import akka.annotation.ApiMayChange import akka.grpc.scaladsl.{ Metadata, MetadataBuilder } -import akka.grpc.internal.{ GrpcMetadataImpl, JavaMetadataImpl, RichGrpcMetadataImpl } +import akka.grpc.internal.{ JavaMetadataImpl, RichGrpcMetadataImpl } import com.google.protobuf.any.Any import io.grpc.protobuf.StatusProto @@ -39,7 +39,9 @@ object GrpcServiceException { val statusRuntimeException = StatusProto.toStatusRuntimeException(status.build) - new GrpcServiceException(statusRuntimeException.getStatus, new GrpcMetadataImpl(statusRuntimeException.getTrailers)) + new GrpcServiceException( + statusRuntimeException.getStatus, + new RichGrpcMetadataImpl(statusRuntimeException.getStatus, statusRuntimeException.getTrailers)) } private def toJavaProto(scalaPbSource: com.google.protobuf.any.Any): com.google.protobuf.Any = { @@ -50,7 +52,13 @@ object GrpcServiceException { } def apply(ex: StatusRuntimeException): GrpcServiceException = { - new GrpcServiceException(ex.getStatus, new RichGrpcMetadataImpl(ex.getStatus, ex.getTrailers)) + ex.getTrailers match { + case null => + new GrpcServiceException(ex.getStatus) + case trailers => + new GrpcServiceException(ex.getStatus, new RichGrpcMetadataImpl(ex.getStatus, trailers)) + } + } } diff --git a/runtime/src/main/scala/akka/grpc/internal/MetadataImpl.scala b/runtime/src/main/scala/akka/grpc/internal/MetadataImpl.scala index e8c27916f..20a310dcd 100644 --- a/runtime/src/main/scala/akka/grpc/internal/MetadataImpl.scala +++ b/runtime/src/main/scala/akka/grpc/internal/MetadataImpl.scala @@ -91,6 +91,7 @@ import scalapb.{ GeneratedMessage, GeneratedMessageCompanion } */ @InternalApi class GrpcMetadataImpl(delegate: io.grpc.Metadata) extends Metadata { + require(delegate != null, "Metadata delegate must be present") private lazy val map = delegate.keys.iterator.asScala.map(key => key -> getEntries(key)).toMap override def getText(key: String): Option[String] =