We are seeing a possible race condition around credential refresh. We use the following code in an integration test suite to fetch OAuth2 tokens:
GoogleCredentials credentials = ...;
try {
if (forceRefresh) {
credentials.refresh();
} else {
credentials.getRequestMetadata();
}
AccessToken token = credentials.getAccessToken();
return token.getTokenValue();
} catch (IOException e) {
throw new RuntimeException(e);
}
We expect the credentials to contain a valid access token at the end of the if-else block. However, our tests intermittently fail by throwing a NullPointerException at token.getTokenValue(). Any thoughts on what might be going on here? What should we do to ensure that getAccessToken() always returns a non-null value?
Note: In the failing tests, forceRefresh has been set to false. So it should execute the credentials.getRequestMetadata() path.
Reactions are currently unavailable
We are seeing a possible race condition around credential refresh. We use the following code in an integration test suite to fetch OAuth2 tokens:
We expect the credentials to contain a valid access token at the end of the if-else block. However, our tests intermittently fail by throwing a NullPointerException at token.getTokenValue(). Any thoughts on what might be going on here? What should we do to ensure that getAccessToken() always returns a non-null value?
Note: In the failing tests, forceRefresh has been set to false. So it should execute the credentials.getRequestMetadata() path.