Skip to content

fix(auth): annotate builder fields, setters, and getters as @Nullable across credential builders - #14154

Closed
lqiu96 wants to merge 1 commit into
fix_auth_credential_types_nullabilityfrom
fix_auth_builder_nullability
Closed

fix(auth): annotate builder fields, setters, and getters as @Nullable across credential builders#14154
lqiu96 wants to merge 1 commit into
fix_auth_credential_types_nullabilityfrom
fix_auth_builder_nullability

Conversation

@lqiu96

@lqiu96 lqiu96 commented Aug 20, 2026

Copy link
Copy Markdown
Member

This PR is part 3 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. fix(auth): add missing @Nullable annotations across credential types and providers #14153: fix(auth): add missing @Nullable annotations across credential types and providers
  3. This PR (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

In @NullMarked credential classes and their corresponding Builder nested classes, fields that default to null before setter invocation, or represent optional configuration (such as optional tokens, transport factories, quotas, boundary rules, audiences, scopes, or endpoints), were unannotated, causing IDEs and static analysis tools to flag null assignments or null checks as warnings/errors.

This PR aligns @Nullable annotations across builder fields, builder setters (parameters and returns), and corresponding credential getter return types across 21 credential and authorizer builder classes.

@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 builder classes in the Google Auth Library for Java to improve null-safety. Feedback suggests that while builder fields can be annotated as @Nullable, the corresponding fields in the instantiated credential classes (such as ExternalAccountAuthorizedUserCredentials) should remain non-nullable if they are required and validated during construction, preventing unnecessary null checks in internal logic.

Comment on lines +88 to +95
private final @Nullable String audience;
private final @Nullable String tokenUrl;
private final @Nullable String tokenInfoUrl;
private final @Nullable String revokeUrl;
private final @Nullable String clientId;
private final @Nullable String clientSecret;

private String refreshToken;
private @Nullable String refreshToken;

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

In ExternalAccountAuthorizedUserCredentials, fields like audience, tokenUrl, and refreshToken are required for the credential to function (e.g., to perform token refresh). While these fields are appropriately marked as @Nullable in the Builder class (since they start as null before being set), they should remain non-nullable (unannotated under @NullMarked) in the ExternalAccountAuthorizedUserCredentials class itself. Annotating them as @Nullable in the main class weakens null safety, as it forces all internal usages to handle potential null values even though they are guaranteed to be non-null after successful construction/validation.

Suggested change
private final @Nullable String audience;
private final @Nullable String tokenUrl;
private final @Nullable String tokenInfoUrl;
private final @Nullable String revokeUrl;
private final @Nullable String clientId;
private final @Nullable String clientSecret;
private String refreshToken;
private @Nullable String refreshToken;
private final String audience;
private final String tokenUrl;
private final @Nullable String tokenInfoUrl;
private final @Nullable String revokeUrl;
private final @Nullable String clientId;
private final @Nullable String clientSecret;
private String refreshToken;

@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_builder_nullability branch from 8ad1e6c to deea921 Compare August 20, 2026 20:57
@lqiu96
lqiu96 force-pushed the fix_auth_credential_types_nullability branch from fbe5519 to f0b8fc9 Compare August 20, 2026 21:03
@lqiu96
lqiu96 force-pushed the fix_auth_builder_nullability branch from deea921 to 1f922ec 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