Skip to content

fix(auth): add missing @Nullable annotations across credential types and providers - #14153

Closed
lqiu96 wants to merge 1 commit into
fix_auth_issue_14147_auditfrom
fix_auth_credential_types_nullability
Closed

fix(auth): add missing @Nullable annotations across credential types and providers#14153
lqiu96 wants to merge 1 commit into
fix_auth_issue_14147_auditfrom
fix_auth_credential_types_nullability

Conversation

@lqiu96

@lqiu96 lqiu96 commented Aug 20, 2026

Copy link
Copy Markdown
Member

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

  1. fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore #14150: fix(auth): fix JSpecify nullability in UserAuthorizer and TokenStore (resolves JSpecify incompatibility #14147)
  2. This PR (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

Description

Following the migration of google-auth-library-java to @NullMarked, an audit of all credential types, credential providers, and token utilities identified several methods that can accept or return null in standard usage patterns.

This PR adds @Nullable annotations to the following non-builder surfaces:

  • IdTokenProvider: targetAudience parameter in idTokenWithAudience(...)Option and Option#getOptionTargetAudience() return type.
  • UserAuthorizer: getCredentials return type, getCredentialsFromCallback parameters, getAuthorizationUrl parameters (userId, state).
  • UserCredentials: constructor clientId and clientSecret parameters (and corresponding getter returns), which are nullable for 3-legged scenarios and user credential definitions.
  • ServiceAccountCredentials / ServiceAccountJwtAccessCredentials: nullable serviceAccountUser constructor parameter and getters, privateKeyId, privateKey, clientEmail, clientId where optional.
  • ExternalAccountCredentials & subclasses (AwsCredentials, IdentityPoolCredentials, PluggableAuthCredentials, ExternalAccountAuthorizedUserCredentials): nullable constructor parameters and getters for optional parameters (workforcePoolUserProject, serviceAccountImpersonationUrl, quotaProjectId, subjectToken, etc.).
  • DownscopedCredentials & ImpersonatedCredentials: nullable optional fields and constructors.
  • GdchCredentials: nullable constructor parameters and getters for optional endpoints/tokens.
  • Token refresh utilities: OAuth2CredentialsWithRefresh, RefreshHandler, DefaultTokenRefresher, SecureSessionAgent.

@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 systematically adds @Nullable annotations across various credential classes, builders, and utility methods in the google-auth-library-java library to improve nullness analysis and JSpecify compliance. The review feedback points out a few instances in ExternalAccountCredentials, GoogleCredentials, and UserCredentials where the @Nullable annotation was placed before the method modifiers instead of directly on the return type. Correcting these placements will ensure consistency with the rest of the codebase and proper JSpecify compliance.

return tokenUrl;
}

@Nullable

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.

medium

For JSpecify compliance and consistency with other changes in this PR (such as in AwsCredentials.java), the @Nullable annotation should be placed on the return type itself rather than before the method modifiers.

Please update it to:

public @Nullable String getTokenInfoUrl() {

*
* @return the project id for a Credential type
*/
@Nullable

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.

medium

For JSpecify compliance and consistency, the @Nullable annotation should be placed on the return type itself rather than before the method modifiers.

Please update it to:

public @Nullable String getProjectId() {

*
* @return refresh token
*/
@Nullable

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.

medium

For JSpecify compliance and consistency, the @Nullable annotation should be placed on the return type itself rather than before the method modifiers.

Please update it to:

public final @Nullable String getRefreshToken() {

@lqiu96
lqiu96 force-pushed the fix_auth_issue_14147_audit branch from e42cd96 to 4d28828 Compare August 20, 2026 20:54
@lqiu96
lqiu96 force-pushed the fix_auth_credential_types_nullability branch from a364201 to fbe5519 Compare August 20, 2026 20:55
@lqiu96
lqiu96 force-pushed the fix_auth_issue_14147_audit branch from c51c2b2 to be8b8db Compare August 20, 2026 21:03
@lqiu96
lqiu96 force-pushed the fix_auth_credential_types_nullability branch from fbe5519 to f0b8fc9 Compare August 20, 2026 21:04
@lqiu96 lqiu96 closed this Aug 20, 2026
lqiu96 added a commit that referenced this pull request Aug 20, 2026
…14150)

This PR is **part 1 of 3** in a stacked series of JSpecify nullability
fixes for `google-auth-library-java`:
1. **This PR (#14150)**: `fix(auth): fix JSpecify nullability in
UserAuthorizer and TokenStore` (resolves #14147)
2. #14153: `fix(auth): add missing @nullable annotations across
credential types and providers`
3. #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.

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

1 participant