@@ -93,7 +93,16 @@ public class IdentityPoolCredentials extends ExternalAccountCredentials {
9393 this .metricsHeaderValue = URL_METRICS_HEADER_VALUE ;
9494 } else if (credentialSource .credentialSourceType
9595 == IdentityPoolCredentialSourceType .CERTIFICATE ) {
96- this .subjectTokenSupplier = createCertificateSubjectTokenSupplier (builder , credentialSource );
96+ try {
97+ this .subjectTokenSupplier =
98+ createCertificateSubjectTokenSupplier (builder , credentialSource );
99+ } catch (IOException e ) {
100+ throw new RuntimeException (
101+ // Wrap IOException in RuntimeException because constructors cannot throw checked
102+ // exceptions.
103+ "Failed to initialize IdentityPoolCredentials from certificate source due to an I/O error." ,
104+ e );
105+ }
97106 this .metricsHeaderValue = CERTIFICATE_METRICS_HEADER_VALUE ;
98107 } else {
99108 throw new IllegalArgumentException ("Source type not supported." );
@@ -145,24 +154,15 @@ public static Builder newBuilder(IdentityPoolCredentials identityPoolCredentials
145154 }
146155
147156 private IdentityPoolSubjectTokenSupplier createCertificateSubjectTokenSupplier (
148- Builder builder , IdentityPoolCredentialSource credentialSource ) {
149- try {
150- // Configure the mTLS transport with the x509 keystore.
151- X509Provider x509Provider = getX509Provider (builder , credentialSource );
152- KeyStore mtlsKeyStore = x509Provider .getKeyStore ();
153- this .transportFactory = new MtlsHttpTransportFactory (mtlsKeyStore );
154-
155- // Initialize the subject token supplier with the certificate path.
156- credentialSource .setCredentialLocation (x509Provider .getCertificatePath ());
157- return new CertificateIdentityPoolSubjectTokenSupplier (credentialSource );
158-
159- } catch (IOException e ) {
160- throw new RuntimeException (
161- // Wrap IOException in RuntimeException because constructors cannot throw checked
162- // exceptions.
163- "Failed to initialize IdentityPoolCredentials from certificate source due to an I/O error." ,
164- e );
165- }
157+ Builder builder , IdentityPoolCredentialSource credentialSource ) throws IOException {
158+ // Configure the mTLS transport with the x509 keystore.
159+ X509Provider x509Provider = getX509Provider (builder , credentialSource );
160+ KeyStore mtlsKeyStore = x509Provider .getKeyStore ();
161+ this .transportFactory = new MtlsHttpTransportFactory (mtlsKeyStore );
162+
163+ // Initialize the subject token supplier with the certificate path.
164+ credentialSource .setCredentialLocation (x509Provider .getCertificatePath ());
165+ return new CertificateIdentityPoolSubjectTokenSupplier (credentialSource );
166166 }
167167
168168 private X509Provider getX509Provider (
0 commit comments