aboutsummaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorEric Gribkoff <ericgribkoff@google.com>2017-10-02 12:35:13 -0700
committerGitHub <noreply@github.com>2017-10-02 12:35:13 -0700
commitb02645b49f7e0caab3014e2b637c5d4a3fac068b (patch)
tree4c47bde0686596b760ea12204ab39840f6a6cbfe /auth
parent02466744bbe238403bfe16ae5ba337436ac71b7f (diff)
downloadgrpc-grpc-java-b02645b49f7e0caab3014e2b637c5d4a3fac068b.tar.gz
auth: remove use of JDK7 ReflectiveOperationException
Diffstat (limited to 'auth')
-rw-r--r--auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java33
1 files changed, 25 insertions, 8 deletions
diff --git a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java
index 7f3265d5a..0f4b3e964 100644
--- a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java
+++ b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java
@@ -28,6 +28,7 @@ import io.grpc.MethodDescriptor;
import io.grpc.Status;
import io.grpc.StatusException;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
@@ -184,13 +185,19 @@ final class GoogleAuthLibraryCallCredentials implements CallCredentials {
} catch (ClassNotFoundException ex) {
return null;
}
+ Exception caughtException;
try {
return new JwtHelper(rawServiceAccountClass, loader);
- } catch (ReflectiveOperationException ex) {
+ } catch (ClassNotFoundException ex) {
+ caughtException = ex;
+ } catch (NoSuchMethodException ex) {
+ caughtException = ex;
+ }
+ if (caughtException != null) {
// Failure is a bug in this class, but we still choose to gracefully recover
- log.log(Level.WARNING, "Failed to create JWT helper. This is unexpected", ex);
- return null;
+ log.log(Level.WARNING, "Failed to create JWT helper. This is unexpected", caughtException);
}
+ return null;
}
@VisibleForTesting
@@ -204,7 +211,7 @@ final class GoogleAuthLibraryCallCredentials implements CallCredentials {
private final Method getPrivateKeyId;
public JwtHelper(Class<?> rawServiceAccountClass, ClassLoader loader)
- throws ReflectiveOperationException {
+ throws ClassNotFoundException, NoSuchMethodException {
serviceAccountClass = rawServiceAccountClass.asSubclass(Credentials.class);
getScopes = serviceAccountClass.getMethod("getScopes");
getClientId = serviceAccountClass.getMethod("getClientId");
@@ -222,6 +229,7 @@ final class GoogleAuthLibraryCallCredentials implements CallCredentials {
if (!serviceAccountClass.isInstance(creds)) {
return creds;
}
+ Exception caughtException;
try {
creds = serviceAccountClass.cast(creds);
Collection<?> scopes = (Collection<?>) getScopes.invoke(creds);
@@ -234,12 +242,21 @@ final class GoogleAuthLibraryCallCredentials implements CallCredentials {
getClientEmail.invoke(creds),
getPrivateKey.invoke(creds),
getPrivateKeyId.invoke(creds));
- } catch (ReflectiveOperationException ex) {
+ } catch (IllegalAccessException ex) {
+ caughtException = ex;
+ } catch (InvocationTargetException ex) {
+ caughtException = ex;
+ } catch (InstantiationException ex) {
+ caughtException = ex;
+ }
+ if (caughtException != null) {
// Failure is a bug in this class, but we still choose to gracefully recover
- log.log(Level.WARNING,
- "Failed converting service account credential to JWT. This is unexpected", ex);
- return creds;
+ log.log(
+ Level.WARNING,
+ "Failed converting service account credential to JWT. This is unexpected",
+ caughtException);
}
+ return creds;
}
}
}