From e89e0ccfeeec9f8d2722df99357a21b0d1ae503a Mon Sep 17 00:00:00 2001 From: Larry Safran <107004254+larry-safran@users.noreply.github.com> Date: Tue, 25 Apr 2023 10:26:13 -0700 Subject: [PATCH] Refactor so that calculation happens in constructor rather than checking for a null value to lazily initialize it. (#10101) Fixes b/277276312 --- .../auth/GoogleAuthLibraryCallCredentials.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java index 2a414e792d..26e7364ea9 100644 --- a/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java +++ b/auth/src/main/java/io/grpc/auth/GoogleAuthLibraryCallCredentials.java @@ -63,7 +63,7 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials private Metadata lastHeaders; private Map> lastMetadata; - private Boolean requiresSpecificExecutor; + private final boolean requiresSpecificExecutor; public GoogleAuthLibraryCallCredentials(Credentials creds) { this(creds, jwtHelper); @@ -85,6 +85,13 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials } this.requirePrivacy = requirePrivacy; this.creds = creds; + + // Cache the value so we only need to try to load the class once + if (APP_ENGINE_CREDENTIALS_CLASS == null) { + requiresSpecificExecutor = false; + } else { + requiresSpecificExecutor = APP_ENGINE_CREDENTIALS_CLASS.isInstance(creds); + } } @Override @@ -377,15 +384,6 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials */ @Override public boolean isSpecificExecutorRequired() { - // Cache the value so we only need to try to load the class once - if (requiresSpecificExecutor == null) { - if (APP_ENGINE_CREDENTIALS_CLASS == null) { - requiresSpecificExecutor = Boolean.FALSE; - } else { - requiresSpecificExecutor = APP_ENGINE_CREDENTIALS_CLASS.isInstance(creds); - } - } - return requiresSpecificExecutor; }