fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore - #14150
Conversation
There was a problem hiding this comment.
Code Review
This pull request comprehensively adds @nullable annotations across various credential and utility classes in the google-auth-library-java library to improve null safety and static analysis. While these changes are beneficial, several issues were identified where the new nullability annotations introduce potential bugs or contradictions. Specifically, in AccessToken.java and ClientSideCredentialAccessBoundaryFactory.java, dereferencing newly nullable fields (expirationTimeMillis and universeDomain) without null checks can lead to NullPointerExceptions. Additionally, in GdchCredentials.java, annotating apiAudience as @nullable is misleading because the method explicitly rejects null values.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces @Nullable annotations across various credential and utility classes (such as AppEngineCredentials, ClientSideCredentialAccessBoundaryFactory, Credentials, AccessToken, AwsCredentials, ComputeEngineCredentials, IdTokenCredentials, UserAuthorizer, and others) to improve null-safety under @NullMarked contexts. It also adds unit tests in UserAuthorizerTest to verify behavior with null arguments. Feedback on the changes highlights two null-safety issues: a potential NullPointerException in ClientSideCredentialAccessBoundaryFactory due to calling .equals() on the newly nullable universeDomain field, and a nullability mismatch in IdTokenCredentials where the nullable targetAudience is passed to a method expecting a non-null argument.
beb4e50 to
e42cd96
Compare
89e4fa8 to
f83bcaa
Compare
f83bcaa to
ece0440
Compare
| @Nullable String userId, | ||
| @Nullable String state, | ||
| @Nullable URI baseUri, |
There was a problem hiding this comment.
Added these annotations because there of the null checks below (L215 and L220)
| if (tokenStore == null) { | ||
| throw new IllegalStateException("Method cannot be called if token store is not specified."); | ||
| } |
There was a problem hiding this comment.
constructor creates a default one if builder passes in null
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces nullability annotations (@nullable) across MemoryTokensStorage, TokenStore, and UserAuthorizer to improve null safety, simplifies map operations using Map.putAll(), and adds corresponding unit tests for null base URIs. The feedback suggests avoiding the reassignment of the additionalParameters method parameter in getCredentialsFromCode and getTokenResponseFromAuthCodeExchange by utilizing a local variable instead.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This PR is part 1 of 3 in a stacked series of JSpecify nullability fixes for
google-auth-library-java:fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore(resolves JSpecify incompatibility #14147)fix(auth): add missing @Nullable annotations across credential types and providersfix(auth): annotate builder fields, setters, and getters as @Nullable across credential buildersFixes #14147
Description
In
google-auth-library-java, classes were recently annotated with@NullMarkedat the class level. This PR specifically addresses the incompatibilities reported in #14147:TokenStore#loadandMemoryTokensStorage#load: Annotates the return type ofload(String id)with@Nullable, asnullis the expected result when no token data is found for a given identifier.UserAuthorizer#getAuthorizationUrlandUserAuthorizer#getAndStoreCredentialsFromCode: Annotates thebaseUriparameter with@NullableacrossgetAuthorizationUrl,getAndStoreCredentialsFromCode,getCredentialsFromCode,getTokenResponseFromAuthCodeExchange, andgetCallbackUri, asbaseUriis optional and only required when using relative callback URIs.