Skip to content

Commit 008425d

Browse files
committed
removed catch block
1 parent b7903d0 commit 008425d

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

oauth2_http/java/com/google/auth/mtls/X509Provider.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,10 @@ private WorkloadCertificateConfiguration getWorkloadCertificateConfiguration()
144144
try {
145145
if (!isFile(certConfig)) {
146146
// Path will be put in the message from the catch block below
147-
throw new IOException("File does not exist.");
147+
throw new CertificateSourceUnavailableException("File does not exist.");
148148
}
149149
certConfigStream = createInputStream(certConfig);
150150
return WorkloadCertificateConfiguration.fromCertificateConfigurationStream(certConfigStream);
151-
} catch (Exception e) {
152-
// Although it is also the cause, the message of the caught exception can have very
153-
// important information for diagnosing errors, so include its message in the
154-
// outer exception message also.
155-
throw new CertificateSourceUnavailableException(
156-
String.format(
157-
"Error reading certificate configuration file value '%s': %s",
158-
certConfig.getPath(), e.getMessage()),
159-
e);
160151
} finally {
161152
if (certConfigStream != null) {
162153
certConfigStream.close();

oauth2_http/javatests/com/google/auth/mtls/X509ProviderTest.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package com.google.auth.mtls;
3333

3434
import static org.junit.Assert.assertTrue;
35+
import static org.junit.Assert.fail;
3536

3637
import java.io.ByteArrayInputStream;
3738
import java.io.File;
@@ -45,6 +46,7 @@
4546
import java.security.cert.CertificateFactory;
4647
import java.util.HashMap;
4748
import java.util.Map;
49+
import net.bytebuddy.pool.TypePool.Resolution.Illegal;
4850
import org.junit.Assert;
4951
import org.junit.Test;
5052

@@ -88,14 +90,10 @@ public class X509ProviderTest {
8890
public void x509Provider_fileDoesntExist_throws() {
8991
String certConfigPath = "badfile.txt";
9092
X509Provider testProvider = new TestX509Provider(certConfigPath);
91-
String expectedErrorMessage =
92-
String.format(
93-
"Error reading certificate configuration file value '%s': File does not exist.",
94-
certConfigPath);
93+
String expectedErrorMessage = "File does not exist.";
9594

9695
CertificateSourceUnavailableException exception =
97-
Assert.assertThrows(
98-
CertificateSourceUnavailableException.class, () -> testProvider.getKeyStore());
96+
Assert.assertThrows(CertificateSourceUnavailableException.class, () -> testProvider.getKeyStore());
9997
assertTrue(exception.getMessage().contains(expectedErrorMessage));
10098
}
10199

@@ -107,11 +105,11 @@ public void x509Provider_emptyFile_throws() {
107105
testProvider.addFile(certConfigPath, certConfigStream);
108106
String expectedErrorMessage =
109107
String.format(
110-
"Error reading certificate configuration file value '%s': no JSON input found",
108+
"no JSON input found",
111109
certConfigPath);
112110

113-
IOException exception =
114-
Assert.assertThrows(IOException.class, () -> testProvider.getKeyStore());
111+
IllegalArgumentException exception =
112+
Assert.assertThrows(IllegalArgumentException.class, () -> testProvider.getKeyStore());
115113
assertTrue(exception.getMessage().contains(expectedErrorMessage));
116114
}
117115

0 commit comments

Comments
 (0)