Issue
In Java gRPC, are the generated RPC service methods guaranteed not to return a null value?
For example, with this service definition:
service MyExample {
rpc MyExampleCall (MyExampleRequest) returns (MyExampleResponse);
}
... I might have Java calling code like this:
class RandomApp {
MyExampleServiceBlockingStub stub;
void randomMethod() {
var request = MyExampleRequest.newBuilder().build();
var response = stub.myExampleCall(request);
if (response == null) {
...
...
} else {
...
...
}
}
}
For Protocol Buffers, no Protobuf methods accept or return nulls unless otherwise specified.
And, if that also extends to gRPC Java generated code, I imagine I can avoid null-handling code like in my example above.
So, I'm just looking for an explicit answer to my question.
Solution
This is more gRPC semantics than Protobuf semantics; and yes, it is reasonable to assume response will never be null
, although you should have exception handling around the call.
Answered By - San P
Answer Checked By - Marilyn (JavaFixing Volunteer)