Skip to content

fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore - #14150

Merged
lqiu96 merged 2 commits into
mainfrom
fix_auth_issue_14147_audit
Aug 20, 2026
Merged

fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore#14150
lqiu96 merged 2 commits into
mainfrom
fix_auth_issue_14147_audit

Conversation

@lqiu96

@lqiu96 lqiu96 commented Aug 20, 2026

Copy link
Copy Markdown
Member

This PR is part 1 of 3 in a stacked series of JSpecify nullability fixes for google-auth-library-java:

  1. This PR (fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore #14150): fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore (resolves JSpecify incompatibility #14147)
  2. fix(auth): add missing @Nullable annotations across credential types and providers #14153: fix(auth): add missing @Nullable annotations across credential types and providers
  3. fix(auth): annotate builder fields, setters, and getters as @Nullable across credential builders #14154: fix(auth): annotate builder fields, setters, and getters as @Nullable across credential builders

Fixes #14147

Description

In google-auth-library-java, classes were recently annotated with @NullMarked at the class level. This PR specifically addresses the incompatibilities reported in #14147:

  1. TokenStore#load and MemoryTokensStorage#load: Annotates the return type of load(String id) with @Nullable, as null is the expected result when no token data is found for a given identifier.
  2. UserAuthorizer#getAuthorizationUrl and UserAuthorizer#getAndStoreCredentialsFromCode: Annotates the baseUri parameter with @Nullable across getAuthorizationUrl, getAndStoreCredentialsFromCode, getCredentialsFromCode, getTokenResponseFromAuthCodeExchange, and getCallbackUri, as baseUri is optional and only required when using relative callback URIs.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lqiu96

lqiu96 commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lqiu96
lqiu96 force-pushed the fix_auth_issue_14147_audit branch from beb4e50 to e42cd96 Compare August 20, 2026 20:41
@lqiu96 lqiu96 changed the title fix(auth): add missing @Nullable annotations across google-auth-library-java fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore Aug 20, 2026
@lqiu96
lqiu96 force-pushed the fix_auth_issue_14147_audit branch 5 times, most recently from 89e4fa8 to f83bcaa Compare August 20, 2026 21:23
@lqiu96
lqiu96 force-pushed the fix_auth_issue_14147_audit branch from f83bcaa to ece0440 Compare August 20, 2026 21:30
Comment on lines +203 to +205
@Nullable String userId,
@Nullable String state,
@Nullable URI baseUri,

@lqiu96 lqiu96 Aug 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these annotations because there of the null checks below (L215 and L220)

Comment on lines -246 to -248
if (tokenStore == null) {
throw new IllegalStateException("Method cannot be called if token store is not specified.");
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor creates a default one if builder passes in null

@lqiu96
lqiu96 requested a review from whowes August 20, 2026 21:34
@lqiu96

lqiu96 commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@lqiu96
lqiu96 marked this pull request as ready for review August 20, 2026 21:35
@lqiu96
lqiu96 requested review from a team as code owners August 20, 2026 21:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@lqiu96
lqiu96 enabled auto-merge (squash) August 20, 2026 21:54
@lqiu96
lqiu96 merged commit 0d5fac0 into main Aug 20, 2026
300 checks passed
@lqiu96
lqiu96 deleted the fix_auth_issue_14147_audit branch August 20, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSpecify incompatibility

2 participants