Skip to content

Commit 83612b6

Browse files
committed
chore: Throw IOException on validateUniverseDomain
1 parent 7a0b3fa commit 83612b6

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

google-api-client/src/main/java/com/google/api/client/googleapis/services/AbstractGoogleClient.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,24 @@ private String determineEndpoint(Builder builder) {
147147
* from the google-auth-library. If the HttpRequestInitializer is not used, the configured
148148
* Universe Domain is validated against the Google Default Universe (GDU): `googleapis.com`.
149149
*
150-
* @throws IllegalStateException if the configured Universe Domain does not match the Universe
151-
* Domain in the Credentials
150+
* @throws IOException if the configured Universe Domain does not match the Universe Domain in the
151+
* Credentials or there is an error reading the Universe Domain from the credentials
152152
*/
153-
public void validateUniverseDomain() {
153+
public void validateUniverseDomain() throws IOException {
154154
String expectedUniverseDomain;
155-
try {
156-
if (!(httpRequestInitializer instanceof HttpCredentialsAdapter)) {
157-
expectedUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
158-
} else {
159-
Credentials credentials =
160-
((HttpCredentialsAdapter) httpRequestInitializer).getCredentials();
161-
expectedUniverseDomain = credentials.getUniverseDomain();
162-
}
163-
if (!expectedUniverseDomain.equals(getUniverseDomain())) {
164-
throw new IllegalStateException(
165-
String.format(
166-
"The configured universe domain (%s) does not match the universe domain found"
167-
+ " in the credentials (%s). If you haven't configured the universe domain"
168-
+ " explicitly, `googleapis.com` is the default.",
169-
getUniverseDomain(), expectedUniverseDomain));
170-
}
171-
} catch (IOException e) {
172-
throw new IllegalStateException(
173-
"Unable to retrieve the Universe Domain from the Credentials.", e);
155+
if (!(httpRequestInitializer instanceof HttpCredentialsAdapter)) {
156+
expectedUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
157+
} else {
158+
Credentials credentials = ((HttpCredentialsAdapter) httpRequestInitializer).getCredentials();
159+
expectedUniverseDomain = credentials.getUniverseDomain();
160+
}
161+
if (!expectedUniverseDomain.equals(getUniverseDomain())) {
162+
throw new IOException(
163+
String.format(
164+
"The configured universe domain (%s) does not match the universe domain found"
165+
+ " in the credentials (%s). If you haven't configured the universe domain"
166+
+ " explicitly, `googleapis.com` is the default.",
167+
getUniverseDomain(), expectedUniverseDomain));
174168
}
175169
}
176170

google-api-client/src/test/java/com/google/api/client/googleapis/services/AbstractGoogleClientTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,17 +351,18 @@ public void validateUniverseDomain_invalidUniverseDomain() throws IOException {
351351
.setApplicationName(applicationName)
352352
.build();
353353
assertThrows(
354-
IllegalStateException.class,
354+
IOException.class,
355355
new ThrowingRunnable() {
356356
@Override
357-
public void run() {
357+
public void run() throws IOException {
358358
client.validateUniverseDomain();
359359
}
360360
});
361361
}
362362

363363
@Test
364-
public void validateUniverseDomain_notUsingHttpCredentialsAdapter_defaultUniverseDomain() {
364+
public void validateUniverseDomain_notUsingHttpCredentialsAdapter_defaultUniverseDomain()
365+
throws IOException {
365366
String rootUrl = "https://test.googleapis.com/";
366367
String applicationName = "Test Application";
367368
String servicePath = "test/";
@@ -398,10 +399,10 @@ public void validateUniverseDomain_notUsingHttpCredentialsAdapter_customUniverse
398399
.setUniverseDomain(universeDomain)
399400
.build();
400401
assertThrows(
401-
IllegalStateException.class,
402+
IOException.class,
402403
new ThrowingRunnable() {
403404
@Override
404-
public void run() {
405+
public void run() throws IOException {
405406
client.validateUniverseDomain();
406407
}
407408
});

0 commit comments

Comments
 (0)