Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 64de23a

Browse files
authoredJul 10, 2020
fix: handle malformed backend responses. (#522)
When you delete a policy tag from a column in BigQuery, rather than eliding the policyTag message entirely, it will return an empty message (with no name field). This change treats such responses as equivalent to no PolicyTag message being present.
1 parent f77e74e commit 64de23a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/PolicyTags.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags toPb() {
6060

6161
static PolicyTags fromPb(
6262
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags tagPb) {
63-
return newBuilder().setNames(tagPb.getNames()).build();
63+
// Treat a PolicyTag message without a Names subfield as invalid.
64+
if (tagPb.getNames() != null) {
65+
return newBuilder().setNames(tagPb.getNames()).build();
66+
}
67+
return null;
6468
}
6569
}

‎google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/PolicyTagsTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertNotEquals;
21+
import static org.junit.Assert.assertNull;
2122

2223
import com.google.common.collect.ImmutableList;
2324
import java.util.List;
@@ -46,6 +47,13 @@ public void testBuilder() {
4647
assertNotEquals(POLICY_TAGS, POLICIES);
4748
}
4849

50+
@Test
51+
public void testWithoutNames() {
52+
com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags PARTIALTAG =
53+
new com.google.api.services.bigquery.model.TableFieldSchema.PolicyTags();
54+
assertNull(PolicyTags.fromPb(PARTIALTAG));
55+
}
56+
4957
@Test
5058
public void testFromAndPb() {
5159
assertEquals(POLICY_TAGS, PolicyTags.fromPb(POLICY_TAGS.toPb()));

0 commit comments

Comments
 (0)
Failed to load comments.