From e767905f4a323484d5fe22a77a824be11f14399c Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Wed, 6 Jul 2022 13:06:01 -0700 Subject: [PATCH] okhttp: Fix AsyncSink.close() NPE This fixes a regression introduced in e96d0477. The NullPointerException only happens on client-side when some other error occurred during handshaking. I tried to add a test, but SerializingExecutor catches+logs the exception and the expected behavior in the circumstance is that close() is a noop. So the NPE was entirely benign other than annoying log messages. --- okhttp/src/main/java/io/grpc/okhttp/AsyncSink.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/okhttp/src/main/java/io/grpc/okhttp/AsyncSink.java b/okhttp/src/main/java/io/grpc/okhttp/AsyncSink.java index 33247a68d0..faf1b7e301 100644 --- a/okhttp/src/main/java/io/grpc/okhttp/AsyncSink.java +++ b/okhttp/src/main/java/io/grpc/okhttp/AsyncSink.java @@ -208,7 +208,7 @@ final class AsyncSink implements Sink { @Override public void run() { try { - if (buffer.size() > 0) { + if (sink != null && buffer.size() > 0) { sink.write(buffer, buffer.size()); } } catch (IOException e) {