diff --git a/java/google/registry/bigquery/BigqueryConnection.java b/java/google/registry/bigquery/BigqueryConnection.java index 2d2bf765a..7d7ac381b 100644 --- a/java/google/registry/bigquery/BigqueryConnection.java +++ b/java/google/registry/bigquery/BigqueryConnection.java @@ -676,7 +676,7 @@ public class BigqueryConnection implements AutoCloseable { bigquery.datasets().get(getProjectId(), datasetName).execute(); return true; } catch (GoogleJsonResponseException e) { - if (e.getDetails().getCode() == 404) { + if (e.getDetails() != null && e.getDetails().getCode() == 404) { return false; } throw e; @@ -689,7 +689,7 @@ public class BigqueryConnection implements AutoCloseable { bigquery.tables().get(getProjectId(), datasetName, tableName).execute(); return true; } catch (GoogleJsonResponseException e) { - if (e.getDetails().getCode() == 404) { + if (e.getDetails() != null && e.getDetails().getCode() == 404) { return false; } throw e; diff --git a/java/google/registry/bigquery/BigqueryJobFailureException.java b/java/google/registry/bigquery/BigqueryJobFailureException.java index 503238d61..99a68285d 100644 --- a/java/google/registry/bigquery/BigqueryJobFailureException.java +++ b/java/google/registry/bigquery/BigqueryJobFailureException.java @@ -30,15 +30,20 @@ public final class BigqueryJobFailureException extends RuntimeException { /** Delegate {@link IOException} errors, checking for {@link GoogleJsonResponseException} */ public static BigqueryJobFailureException create(IOException cause) { if (cause instanceof GoogleJsonResponseException) { - return create(((GoogleJsonResponseException) cause).getDetails()); + return create((GoogleJsonResponseException) cause); } else { return new BigqueryJobFailureException(cause.getMessage(), cause, null, null); } } /** Create an error for JSON server response errors. */ - public static BigqueryJobFailureException create(GoogleJsonError error) { - return new BigqueryJobFailureException(error.getMessage(), null, null, error); + public static BigqueryJobFailureException create(GoogleJsonResponseException cause) { + GoogleJsonError err = cause.getDetails(); + if (err != null) { + return new BigqueryJobFailureException(err.getMessage(), null, null, err); + } else { + return new BigqueryJobFailureException(cause.getMessage(), cause, null, null); + } } /** Create an error from a failed job. */ diff --git a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java index 5a9e61f95..e3f0469cf 100644 --- a/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java +++ b/java/google/registry/dns/writer/clouddns/CloudDnsWriter.java @@ -19,7 +19,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static google.registry.model.EppResourceUtils.loadByForeignKey; import static google.registry.util.DomainNameUtils.getSecondLevelDomain; -import com.google.api.client.googleapis.json.GoogleJsonError.ErrorInfo; +import com.google.api.client.googleapis.json.GoogleJsonError; import com.google.api.client.googleapis.json.GoogleJsonResponseException; import com.google.api.services.dns.Dns; import com.google.api.services.dns.model.Change; @@ -390,12 +390,12 @@ public class CloudDnsWriter extends BaseDnsWriter { try { dnsConnection.changes().create(projectId, zoneName, change).execute(); } catch (GoogleJsonResponseException e) { - List errors = e.getDetails().getErrors(); + GoogleJsonError err = e.getDetails(); // We did something really wrong here, just give up and re-throw - if (errors.size() > 1) { + if (err == null || err.getErrors().size() > 1) { throw new RuntimeException(e); } - String errorReason = errors.get(0).getReason(); + String errorReason = err.getErrors().get(0).getReason(); if (RETRYABLE_EXCEPTION_REASONS.contains(errorReason)) { throw new ZoneStateException(errorReason); diff --git a/java/google/registry/export/UpdateSnapshotViewAction.java b/java/google/registry/export/UpdateSnapshotViewAction.java index cd2622b19..1927702ff 100644 --- a/java/google/registry/export/UpdateSnapshotViewAction.java +++ b/java/google/registry/export/UpdateSnapshotViewAction.java @@ -138,7 +138,7 @@ public class UpdateSnapshotViewAction implements Runnable { .update(ref.getProjectId(), ref.getDatasetId(), ref.getTableId(), table) .execute(); } catch (GoogleJsonResponseException e) { - if (e.getDetails().getCode() == 404) { + if (e.getDetails() != null && e.getDetails().getCode() == 404) { bigquery.tables().insert(ref.getProjectId(), ref.getDatasetId(), table).execute(); } else { logger.atWarning().withCause(e).log( diff --git a/java/google/registry/groups/DirectoryGroupsConnection.java b/java/google/registry/groups/DirectoryGroupsConnection.java index 5cf0f35ed..37e1f6b1f 100644 --- a/java/google/registry/groups/DirectoryGroupsConnection.java +++ b/java/google/registry/groups/DirectoryGroupsConnection.java @@ -95,7 +95,9 @@ public class DirectoryGroupsConnection implements GroupsConnection { // If the member is already in the group, ignore the error, get the existing member, and // return it. GoogleJsonError err = e.getDetails(); - if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) { + if (err == null) { + throw e; + } else if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) { logger.atInfo().withCause(e).log( "Creating group %s during addition of member %s because the group doesn't exist.", groupKey, email); @@ -169,7 +171,8 @@ public class DirectoryGroupsConnection implements GroupsConnection { return createdGroup; } catch (GoogleJsonResponseException e) { // Ignore the error thrown if the group already exists. - if (e.getDetails().getCode() == SC_CONFLICT + if (e.getDetails() != null + && e.getDetails().getCode() == SC_CONFLICT && e.getDetails().getMessage().equals("Entity already exists.")) { logger.atInfo().withCause(e).log( "Could not create group %s because it already exists.", groupKey); @@ -204,7 +207,8 @@ public class DirectoryGroupsConnection implements GroupsConnection { "%s is a member of the group %s. Got reply: %s", memberEmail, groupKey, getReply); return true; } catch (GoogleJsonResponseException e) { - if (ERROR_MESSAGES_MEMBER_NOT_FOUND.contains(e.getDetails().getMessage())) { + if (e.getDetails() != null + && ERROR_MESSAGES_MEMBER_NOT_FOUND.contains(e.getDetails().getMessage())) { // This means the "get" request failed because the email wasn't part of the group. // This is expected behavior for any visitor that isn't a support group member. logger.atInfo().log(