Skip to content

Commit

Permalink
fix: prevent NPE when checking requester pays status (#850)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lbergelson authored Mar 9, 2022
1 parent 5be0066 commit ce50209
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
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.