Skip to content
Browse files
fix: do not throw NPE from BigQueryImpl.testIamPermissions (#1596)
Fix for issue where `BigQueryImpl.testIamPermissions` will throw a NullPointerException if the caller does not have any of the permissions being checked.

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]( before writing your code!  That way we can discuss the change, evaluate designs, and agree on the general idea
- [X] Ensure the tests and linter pass
- [X] Code coverage does not decrease (if any source code was changed)
- [X] Appropriate docs were updated (if necessary)

Fixes #1595 ☕️
  • Loading branch information
rculbertson committed Sep 20, 2021
1 parent e384f5a commit 4251b19f5b240b907aa5fc6d0cc64026245714cf
@@ -1495,7 +1495,9 @@ public call()
return ImmutableList.copyOf(response.getPermissions());
return response.getPermissions() == null
? ImmutableList.of()
: ImmutableList.copyOf(response.getPermissions());
} catch (RetryHelperException e) {
throw BigQueryException.translateAndThrow(e);
@@ -2766,4 +2766,21 @@ public void testTestIamPermissions() {
assertEquals(perms, grantedPermissions);
verify(bigqueryRpcMock).testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS);

public void testTestIamPermissionsWhenNoPermissionsGranted() {
final String resourceId =
String.format("projects/%s/datasets/%s/tables/%s", PROJECT, DATASET, TABLE);
final List<String> checkedPermissions = ImmutableList.<String>of("foo", "bar", "baz");
// If caller has no permissions, TestIamPermissionsResponse.permissions will be null
final response =
when(bigqueryRpcMock.testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS))
bigquery = options.getService();
List<String> perms = bigquery.testIamPermissions(TABLE_ID, checkedPermissions);
assertEquals(perms, ImmutableList.of());
verify(bigqueryRpcMock).testIamPermissions(resourceId, checkedPermissions, EMPTY_RPC_OPTIONS);

0 comments on commit 4251b19

Please sign in to comment.