Skip to content

NPE in requesterPays check if credentials don't match provided user project #849

@lbergelson

Description

@lbergelson

The last release introduced a new NullPointerException when trying to use an invalid service account to access a requester pays bucket. The null pointer hides the actual cause of the error which makes it hard to debug. (Although the cause is not particularly clear from the original error message anyway)

Expect to see something like this:

Error getting access token for service account: 400 Bad Request
POST https://oauth2.googleapis.com/token
{"error":"invalid_grant","error_description":"Invalid JWT Signature."}, iss: 806222273987-uilktks3j6i7962rp0v7nusveer58497@developer.gserviceaccount.com
com.google.cloud.storage.StorageException: Error getting access token for service account: 400 Bad Request
....

But instead you get


java.lang.NullPointerException
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.requesterPays(CloudStorageFileSystemProvider.java:970)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.<init>(CloudStorageFileSystem.java:209)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:196)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:164)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:154)
	at org.broadinstitute.hellbender.utils.gcs.BucketUtils.getPathOnGcs(BucketUtils.java:410)
	at org.broadinstitute.hellbender.utils.io.IOUtils.getPath(IOUtils.java:773)
	at org.broadinstitute.hellbender.utils.gcs.BucketUtilsUnitTest.throwNPE(BucketUtilsUnitTest.java:421)

Environment details

  1. Cloud NIO
  2. OS type and version: all
  3. Java version: all
  4. version(s): 0.123.23

Steps to reproduce

  1. Attempt to check requester pays status of a bucket under these conditions:
    • correctly formatted but revoked service account credentials
    • autoDetectRequesterPays = true
  2. NPE

Code example

    @Test
    public void throwNPE() throws IOException {
            CloudStorageFileSystemProvider.setDefaultCloudStorageConfiguration(
                    CloudStorageConfiguration.builder()
                    .autoDetectRequesterPays(true)
                    .userProject("ANY_PROJECT_NAME")
                    .build());
            CloudStorageFileSystemProvider.setStorageOptions(
                    StorageOptions.newBuilder()
                            .setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream(INVALID_KEY)))
                            .build()
            );
            final Path path = IOUtils.getPath(FILE_IN_REQUESTER_PAYS_BUCKET);
    }

Stack trace

java.lang.NullPointerException
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider.requesterPays(CloudStorageFileSystemProvider.java:970)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.<init>(CloudStorageFileSystem.java:209)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:196)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:164)
	at com.google.cloud.storage.contrib.nio.CloudStorageFileSystem.forBucket(CloudStorageFileSystem.java:154)
	at org.broadinstitute.hellbender.utils.gcs.BucketUtils.getPathOnGcs(BucketUtils.java:410)
	at org.broadinstitute.hellbender.utils.io.IOUtils.getPath(IOUtils.java:773)
	at org.broadinstitute.hellbender.utils.gcs.BucketUtilsUnitTest.throwNPE(BucketUtilsUnitTest.java:421)
	...

Metadata

Metadata

Assignees

Labels

api: storageIssues related to the googleapis/java-storage-nio API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions