Skip to content

Commit 9ed9d13

Browse files
authored
fix: npe in createFrom (#746)
* fix: npe in create-from * address NPE issue * revert test it * address unit tests
1 parent 25ea236 commit 9ed9d13

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/BlobWriteChannel.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.cloud.RetryHelper;
2626
import com.google.cloud.WriteChannel;
2727
import com.google.cloud.storage.spi.v1.StorageRpc;
28+
import com.google.common.collect.Maps;
2829
import java.net.URL;
2930
import java.util.Map;
3031
import java.util.concurrent.Callable;
@@ -77,7 +78,9 @@ private long getRemotePosition() {
7778
}
7879

7980
private StorageObject getRemoteStorageObject() {
80-
return getOptions().getStorageRpcV1().get(getEntity().toPb(), null);
81+
return getOptions()
82+
.getStorageRpcV1()
83+
.get(getEntity().toPb(), Maps.newEnumMap(StorageRpc.Option.class));
8184
}
8285

8386
private StorageException unrecoverableState(

google-cloud-storage/src/test/java/com/google/cloud/storage/BlobWriteChannelTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import com.google.cloud.storage.spi.StorageRpcFactory;
4141
import com.google.cloud.storage.spi.v1.StorageRpc;
4242
import com.google.common.collect.ImmutableMap;
43+
import com.google.common.collect.Maps;
4344
import java.io.IOException;
4445
import java.math.BigInteger;
4546
import java.net.MalformedURLException;
@@ -333,9 +334,10 @@ public void testWriteWithRetryAndObjectMetadata() throws IOException {
333334
.andThrow(socketClosedException);
334335
expect(storageRpcMock.getCurrentUploadOffset(eq(UPLOAD_ID))).andReturn(-1L);
335336
expect(storageRpcMock.getCurrentUploadOffset(eq(UPLOAD_ID))).andReturn(-1L);
336-
expect(storageRpcMock.get(BLOB_INFO.toPb(), null)).andThrow(socketClosedException);
337+
expect(storageRpcMock.get(BLOB_INFO.toPb(), Maps.newEnumMap(StorageRpc.Option.class)))
338+
.andThrow(socketClosedException);
337339
expect(storageRpcMock.getCurrentUploadOffset(eq(UPLOAD_ID))).andReturn(-1L);
338-
expect(storageRpcMock.get(BLOB_INFO.toPb(), null))
340+
expect(storageRpcMock.get(BLOB_INFO.toPb(), Maps.newEnumMap(StorageRpc.Option.class)))
339341
.andReturn(BLOB_INFO.toPb().setSize(BigInteger.valueOf(MIN_CHUNK_SIZE)));
340342
replay(storageRpcMock);
341343
writer = new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);
@@ -485,7 +487,7 @@ public void testWriteWithLastFlushRetryChunkButCompleted() throws IOException {
485487
eq(true)))
486488
.andThrow(socketClosedException);
487489
expect(storageRpcMock.getCurrentUploadOffset(eq(UPLOAD_ID))).andReturn(-1L);
488-
expect(storageRpcMock.get(BLOB_INFO.toPb(), null))
490+
expect(storageRpcMock.get(BLOB_INFO.toPb(), Maps.newEnumMap(StorageRpc.Option.class)))
489491
.andReturn(BLOB_INFO.toPb().setSize(BigInteger.valueOf(MIN_CHUNK_SIZE)));
490492
replay(storageRpcMock);
491493
writer = new BlobWriteChannel(options, BLOB_INFO, EMPTY_RPC_OPTIONS);

0 commit comments

Comments
 (0)