Skip to content

Commit

Permalink
fix: prevent NPE when checking requester pays status (googleapis#850)
Browse files Browse the repository at this point in the history
Fixes a NullPointerException introduced in googleapis#841 which occured when trying
to check the the requesterPays status of a file while authenticated with an
invalid service account.

Refs: googleapis#849, googleapis#841
  • Loading branch information
lbergelson committed Mar 9, 2022
1 parent 5be0066 commit ce50209
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -967,10 +967,12 @@ public boolean requesterPays(String bucketName) {
Boolean isRP = storage.get(bucketName).requesterPays();
return isRP != null && isRP.booleanValue();
} catch (StorageException ex) {
if (ex.getReason().equals("userProjectMissing")) {
if ("userProjectMissing".equals(ex.getReason())) {
return true;
// fallback to checking the error code and error message.
} else if (ex.getCode() == 400 && ex.getMessage().contains("requester pays")) {
} else if (ex.getCode() == 400
&& ex.getMessage() != null
&& ex.getMessage().contains("requester pays")) {
return true;
}
throw ex;
Expand Down

0 comments on commit ce50209

Please sign in to comment.