Repository navigation
Conversation
…count credentials
There was a problem hiding this comment.
Code Review
This pull request ensures that the universeDomain is correctly propagated when creating JWT credentials in both ServiceAccountCredentials and ServiceAccountJwtAccessCredentials, and adds corresponding unit tests to verify this behavior. The feedback suggests a minor improvement in ServiceAccountCredentials to use java.io.UncheckedIOException instead of IllegalStateException when wrapping the checked IOException in getUniverseDomainOrThrow(), which is more idiomatic in Java.
| private String getUniverseDomainOrThrow() { | ||
| try { | ||
| return getUniverseDomain(); | ||
| } catch (IOException e) { | ||
| throw new IllegalStateException("Failed to retrieve universe domain.", e); | ||
| } | ||
| } |
There was a problem hiding this comment.
When wrapping a checked IOException in a runtime exception, it is more idiomatic in Java 8+ to use java.io.UncheckedIOException instead of IllegalStateException. This provides a more specific exception type for I/O-related failures and allows callers to easily catch and handle it specifically. Ensure that the original exception is preserved as the cause to maintain the exception chain.
| private String getUniverseDomainOrThrow() { | |
| try { | |
| return getUniverseDomain(); | |
| } catch (IOException e) { | |
| throw new IllegalStateException("Failed to retrieve universe domain.", e); | |
| } | |
| } | |
| private String getUniverseDomainOrThrow() { | |
| try { | |
| return getUniverseDomain(); | |
| } catch (IOException e) { | |
| throw new java.io.UncheckedIOException("Failed to retrieve universe domain.", e); | |
| } | |
| } |
References
- When catching an exception and throwing a new exception, preserve the original exception as the cause to maintain the exception chain and aid in debugging.
Follow-up to #15176 to propagate
universeDomainwhen constructingJwtCredentialsfrom service account credentials:ServiceAccountCredentials.jwtWithClaims()andcreateSelfSignedJwtCredentials()to pass the credential'suniverseDomaininto the constructedJwtCredentials(wrapping checkedIOExceptionfromgetUniverseDomain()inIllegalStateException).ServiceAccountJwtAccessCredentialsto initializeuniverseDomainbeforecreateCache()and passuniverseDomainincreateCache()andjwtWithClaims().ServiceAccountCredentialsTestandServiceAccountJwtAccessCredentialsTest.