From 5f21c7ca0840183687fe29a5775fb407c160432d Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Fri, 16 Feb 2024 17:05:42 -0800 Subject: [PATCH] check stream != null before close --- .../cloud/storage/GapicUnbufferedReadableByteChannel.java | 6 ++++-- .../main/java/com/google/cloud/storage/GrpcStorageImpl.java | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java index 67891dbc28..24246d73f9 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java @@ -144,8 +144,10 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { if (hasRemaining(bfl)) { leftovers = bfl; } else { - stream.close(); - stream = null; + if(stream != null) { + stream.close(); + stream = null; + } } } else { complete = true; diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java index 67292ebc1a..2b86c82fba 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageImpl.java @@ -111,7 +111,6 @@ import java.util.stream.StreamSupport; import com.google.storage.v2.stub.GrpcStorageCallableFactory; -import com.google.storage.v2.stub.GrpcStorageStub; import io.grpc.*; import io.grpc.protobuf.ProtoUtils; import io.grpc.protobuf.lite.ProtoLiteUtils;