Skip to content

Commit 6ef5c87

Browse files
authored
fix: prevent NPE when checking requester pays status (#850)
Fixes a NullPointerException introduced in #841 which occured when trying to check the the requesterPays status of a file while authenticated with an invalid service account. Refs: #849, #841
1 parent d18b018 commit 6ef5c87

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

java-storage-nio/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/CloudStorageFileSystemProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -967,10 +967,12 @@ public boolean requesterPays(String bucketName) {
967967
Boolean isRP = storage.get(bucketName).requesterPays();
968968
return isRP != null && isRP.booleanValue();
969969
} catch (StorageException ex) {
970-
if (ex.getReason().equals("userProjectMissing")) {
970+
if ("userProjectMissing".equals(ex.getReason())) {
971971
return true;
972972
// fallback to checking the error code and error message.
973-
} else if (ex.getCode() == 400 && ex.getMessage().contains("requester pays")) {
973+
} else if (ex.getCode() == 400
974+
&& ex.getMessage() != null
975+
&& ex.getMessage().contains("requester pays")) {
974976
return true;
975977
}
976978
throw ex;

0 commit comments

Comments
 (0)