stub: Add null check for responseObserver (#10083)

* stub:Add null check for responseObserver

Fixes #10064
This commit is contained in:
Larry Safran 2023-04-25 13:35:39 -07:00 committed by GitHub
parent e89e0ccfee
commit 9d1e089c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View File

@ -73,6 +73,7 @@ public final class ClientCalls {
*/
public static <ReqT, RespT> void asyncUnaryCall(
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
checkNotNull(responseObserver, "responseObserver");
asyncUnaryRequestCall(call, req, responseObserver, false);
}
@ -86,6 +87,7 @@ public final class ClientCalls {
*/
public static <ReqT, RespT> void asyncServerStreamingCall(
ClientCall<ReqT, RespT> call, ReqT req, StreamObserver<RespT> responseObserver) {
checkNotNull(responseObserver, "responseObserver");
asyncUnaryRequestCall(call, req, responseObserver, true);
}
@ -102,6 +104,7 @@ public final class ClientCalls {
public static <ReqT, RespT> StreamObserver<ReqT> asyncClientStreamingCall(
ClientCall<ReqT, RespT> call,
StreamObserver<RespT> responseObserver) {
checkNotNull(responseObserver, "responseObserver");
return asyncStreamingRequestCall(call, responseObserver, false);
}
@ -116,6 +119,7 @@ public final class ClientCalls {
*/
public static <ReqT, RespT> StreamObserver<ReqT> asyncBidiStreamingCall(
ClientCall<ReqT, RespT> call, StreamObserver<RespT> responseObserver) {
checkNotNull(responseObserver, "responseObserver");
return asyncStreamingRequestCall(call, responseObserver, true);
}

View File

@ -503,6 +503,50 @@ public class ClientCallsTest {
assertThat(requests).isEmpty();
}
@Test
public void checkForNullInAsyncUnaryCall() {
NoopClientCall<Integer, String> call = new NoopClientCall<>();
try {
ClientCalls.asyncUnaryCall(call, Integer.valueOf(1), null);
fail("Should have gotten an exception for the null responseObserver");
} catch (NullPointerException e) {
assertEquals("responseObserver", e.getMessage());
}
}
@Test
public void checkForNullInBidiCall() {
NoopClientCall<Integer, String> call = new NoopClientCall<>();
try {
ClientCalls.asyncBidiStreamingCall(call, null);
fail("Should have gotten an exception for the null responseObserver");
} catch (NullPointerException e) {
assertEquals("responseObserver", e.getMessage());
}
}
@Test
public void checkForNullInClientStreamCall() {
NoopClientCall<Integer, String> call = new NoopClientCall<>();
try {
ClientCalls.asyncClientStreamingCall(call, null);
fail("Should have gotten an exception for the null responseObserver");
} catch (NullPointerException e) {
assertEquals("responseObserver", e.getMessage());
}
}
@Test
public void checkForNullInServerStreamCall() {
NoopClientCall<Integer, String> call = new NoopClientCall<>();
try {
ClientCalls.asyncServerStreamingCall(call, Integer.valueOf(1), null);
fail("Should have gotten an exception for the null responseObserver");
} catch (NullPointerException e) {
assertEquals("responseObserver", e.getMessage());
}
}
@Test
public void callStreamObserverPropagatesFlowControlRequestsToCall()
throws Exception {