FakeStorageRpc: NPE on copying file
domrde opened this issue · 0 comments
domrde commented
Environment details
- FakeStorageRpc
- OS type and version: macOS 11.6.5
- Java version: 11
- google-cloud-nio version(s): 0.123.27
Steps to reproduce
If you use LocalStorageHelper
to create a storage, and create a file in it using
storage.create(BlobInfo.newBuilder(sourceBucket, sourcePath).build(), content);
It will be stored in FakeStorageRpc
with null
generation. If you try to copy some other file to overwrite the original one using
final var request = CopyRequest.newBuilder()
.setSource(BlobId.of(sourceBucket, sourcePath))
.setTarget(BlobId.of(destinationBucket, destinationPath))
.build();
storage.copy(request)
.getResult();
You'll get a NullPointerException
in the following FakeStorageRpc
's code
long generation = 1;
if (metadata.containsKey(destKey)) {
generation = metadata.get(destKey).getGeneration() + 1;
}
since metadata.get(destKey).getGeneration()
is null
. Checking the generation for nullability before the increment, like it is done in write
method, should solve the issue.
Stack trace
Caused by: java.lang.NullPointerException
at com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc.openRewrite(FakeStorageRpc.java:416)
at com.google.cloud.storage.StorageImpl.lambda$copy$22(StorageImpl.java:511)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:103)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.Retrying.run(Retrying.java:51)