Refactor so that calculation happens in constructor rather than checking for a null value to lazily initialize it. (#10101)

Fixes b/277276312
This commit is contained in:
Larry Safran 2023-04-25 10:26:13 -07:00 committed by GitHub
parent c4c9939887
commit e89e0ccfee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 10 deletions

View File

@ -63,7 +63,7 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials
private Metadata lastHeaders; private Metadata lastHeaders;
private Map<String, List<String>> lastMetadata; private Map<String, List<String>> lastMetadata;
private Boolean requiresSpecificExecutor; private final boolean requiresSpecificExecutor;
public GoogleAuthLibraryCallCredentials(Credentials creds) { public GoogleAuthLibraryCallCredentials(Credentials creds) {
this(creds, jwtHelper); this(creds, jwtHelper);
@ -85,6 +85,13 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials
} }
this.requirePrivacy = requirePrivacy; this.requirePrivacy = requirePrivacy;
this.creds = creds; 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 @Override
@ -377,15 +384,6 @@ final class GoogleAuthLibraryCallCredentials extends io.grpc.CallCredentials
*/ */
@Override @Override
public boolean isSpecificExecutorRequired() { 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; return requiresSpecificExecutor;
} }