Skip to content

Commit d93cdde

Browse files
committed
fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore
1 parent be8b8db commit d93cdde

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/UserAuthorizer.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.net.URL;
5050
import java.util.ArrayList;
5151
import java.util.Collection;
52+
import java.util.Collections;
5253
import java.util.Date;
5354
import java.util.List;
5455
import java.util.Map;
@@ -289,7 +290,7 @@ public UserCredentials getCredentials(String userId) throws IOException {
289290
* @throws IOException An error from the server API call to get the tokens.
290291
*/
291292
public UserCredentials getCredentialsFromCode(String code, @Nullable URI baseUri) throws IOException {
292-
return getCredentialsFromCode(code, baseUri, null);
293+
return getCredentialsFromCode(code, baseUri, Collections.emptyMap());
293294
}
294295

295296
/**
@@ -305,6 +306,9 @@ public UserCredentials getCredentialsFromCode(String code, @Nullable URI baseUri
305306
public UserCredentials getCredentialsFromCode(
306307
String code, @Nullable URI baseUri, @Nullable Map<String, String> additionalParameters)
307308
throws IOException {
309+
if (additionalParameters == null) {
310+
additionalParameters = Collections.emptyMap();
311+
}
308312
TokenResponseWithConfig tokenResponseWithConfig =
309313
getCredentialsFromCodeInternal(code, baseUri, additionalParameters);
310314
return UserCredentials.newBuilder()
@@ -331,6 +335,9 @@ public UserCredentials getCredentialsFromCode(
331335
*/
332336
public TokenResponseWithConfig getTokenResponseFromAuthCodeExchange(
333337
String code, @Nullable URI callbackUri, @Nullable Map<String, String> additionalParameters) throws IOException {
338+
if (additionalParameters == null) {
339+
additionalParameters = Collections.emptyMap();
340+
}
334341
return getCredentialsFromCodeInternal(code, callbackUri, additionalParameters);
335342
}
336343

@@ -451,7 +458,7 @@ protected void monitorCredentials(String userId, UserCredentials credentials) {
451458
}
452459

453460
private TokenResponseWithConfig getCredentialsFromCodeInternal(
454-
String code, @Nullable URI baseUri, @Nullable Map<String, String> additionalParameters) throws IOException {
461+
String code, @Nullable URI baseUri, Map<String, String> additionalParameters) throws IOException {
455462
Preconditions.checkNotNull(code);
456463
URI resolvedCallbackUri = getCallbackUri(baseUri);
457464

@@ -461,10 +468,8 @@ private TokenResponseWithConfig getCredentialsFromCodeInternal(
461468
tokenData.put("redirect_uri", resolvedCallbackUri);
462469
tokenData.put("grant_type", "authorization_code");
463470

464-
if (additionalParameters != null) {
465-
for (Map.Entry<String, String> entry : additionalParameters.entrySet()) {
466-
tokenData.put(entry.getKey(), entry.getValue());
467-
}
471+
for (Map.Entry<String, String> entry : additionalParameters.entrySet()) {
472+
tokenData.put(entry.getKey(), entry.getValue());
468473
}
469474

470475
if (pkce != null) {

0 commit comments

Comments
 (0)