Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE when creating a Path with a bucket that doesn't exist. #857

Closed
lbergelson opened this issue Mar 11, 2022 · 3 comments · Fixed by #860
Closed

NPE when creating a Path with a bucket that doesn't exist. #857

lbergelson opened this issue Mar 11, 2022 · 3 comments · Fixed by #860
Assignees
Labels
api: storage Issues related to the googleapis/java-storage-nio API. status: investigating The issue is under investigation, which is determined to be non-trivial.

Comments

@lbergelson
Copy link
Contributor

Paths.get(new Uri(A_PATH_TO_A_BUCKET_THAT_DOESNT_EXIST)) crashes with a NullPointerException if autoDetectRequesterPays = true.

Environment details

  1. cloud nio
  2. OS type and version: all
  3. Java version: all
  4. version(s): current and probably previous

Steps to reproduce

  1. autoDetectRequesterPays = true
  2. Create a path to a gs://bucket that doesn't exist
  3. NPE

Code example

    public void testBucketDoesntExist() throws IOException, URISyntaxException {
        CloudStorageConfiguration config = CloudStorageConfiguration.builder()
                .autoDetectRequesterPays(true)
                .userProject(YOUR_PROJECT_NAME)
                .build();
        CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(config);
        Paths.get(new URI("gs://abuckethatdoesntexist"));
    }

Stack trace

java.lang.NullPointerException
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.requesterPays(CloudStorageFileSystemProvider.java:967)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.<init>(CloudStorageFileSystem.java:209)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.newFileSystem(CloudStorageFileSystemProvider.java:263)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.getFileSystem(CloudStorageFileSystemProvider.java:225)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.getPath(CloudStorageFileSystemProvider.java:271)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.getPath(CloudStorageFileSystemProvider.java:86)
	at java.nio.file.Paths.get(Paths.java:143)
	at org.broadinstitute.hellbender.utils.gcs.BucketUtilsUnitTest.testBucketDoesntExist(BucketUtilsUnitTest.java:351)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
	at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584)
	at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172)
	at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
	at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804)
	at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
	
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage-nio API. label Mar 11, 2022
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 12, 2022
@cojenco cojenco added the status: investigating The issue is under investigation, which is determined to be non-trivial. label Mar 14, 2022
@cojenco cojenco removed the triage me I really want to be triaged. label Mar 14, 2022
@sydney-munro
Copy link
Contributor

ah I see what is happening here. In CloudStorageFileSystemProvider.java L967

Boolean isRP = storage.get(bucketName).requesterPays();

We try and access the value for requester pays without validating that the bucket exists.

@sydney-munro
Copy link
Contributor

I am going to bring this up with the team as we should be giving a more useful error message such as an illegal state exception or perhaps just return false/null if the bucket does not exist.

lbergelson added a commit to lbergelson/java-storage-nio that referenced this issue Mar 15, 2022
Fixes a NullPointerException when creating a Path object with a bucket
that doesn't exist. This only occurred when autoDetectRequesterPays = true.

Refs: googleapis#857
@lbergelson
Copy link
Contributor Author

@sydney-munro Yeah, it's a silly bug. I opened a PR with a potential solution.

lbergelson added a commit to lbergelson/java-storage-nio that referenced this issue Mar 15, 2022
Fixes a NullPointerException when creating a Path object with a bucket
that doesn't exist. This only occurred when autoDetectRequesterPays = true.

Refs: googleapis#857
gcf-merge-on-green bot pushed a commit that referenced this issue Mar 17, 2022
Fixes a NullPointerException when creating a Path object with a bucket
that doesn't exist. This only occurred when autoDetectRequesterPays = true.

Refs: #857

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
- [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/java-storage-nio/issues/new/choose) before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)

Fixes #857☕️

If you write sample code, please follow the [samples format](
https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
lbergelson added a commit to broadinstitute/gatk that referenced this issue Mar 18, 2022
* The previous attempt to fix requester pays didn't fix it in many cases.
This incorporates a newer version of the NIO library with several patches to fix
edge cases we were hitting.
  * googleapis/java-storage-nio#850
  * googleapis/java-storage-nio#856
  * googleapis/java-storage-nio#857
* upgrade com.google.cloud:google-cloud-nio:0.123.23 ->0.123.25
* fixes #7716
lbergelson added a commit to broadinstitute/gatk that referenced this issue Mar 18, 2022
* The previous attempt to fix requester pays didn't fix it in many cases.
This incorporates a newer version of the NIO library with several patches to fix
edge cases we were hitting.
  * googleapis/java-storage-nio#849
  * googleapis/java-storage-nio#856
  * googleapis/java-storage-nio#857
* upgrade com.google.cloud:google-cloud-nio:0.123.23 ->0.123.25
* fixes #7716
lbergelson added a commit to broadinstitute/gatk that referenced this issue Mar 18, 2022
* The previous attempt to fix requester pays didn't fix it in many cases.
This incorporates a newer version of the NIO library with several patches to fix
edge cases we were hitting.
  * googleapis/java-storage-nio#849
  * googleapis/java-storage-nio#856
  * googleapis/java-storage-nio#857
* upgrade com.google.cloud:google-cloud-nio:0.123.23 ->0.123.25
* fixes #7716
droazen added a commit to broadinstitute/gatk that referenced this issue Apr 7, 2022
* The previous attempt to fix requester pays didn't fix it in many cases.
This incorporates a newer version of the NIO library with several patches to fix
edge cases we were hitting.
  * googleapis/java-storage-nio#849
  * googleapis/java-storage-nio#856
  * googleapis/java-storage-nio#857
* upgrade com.google.cloud:google-cloud-nio:0.123.23 ->0.123.25

fixes #7716

Co-authored-by: David Roazen <droazen@broadinstitute.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage-nio API. status: investigating The issue is under investigation, which is determined to be non-trivial.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants