fix(auth): annotate builder fields, setters, and getters as @Nullable across credential builders - #14154
Conversation
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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.
| 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; |
a364201 to
fbe5519
Compare
8ad1e6c to
deea921
Compare
fbe5519 to
f0b8fc9
Compare
…across credential builders
deea921 to
1f922ec
Compare
…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>
This PR is part 3 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 buildersDescription
In
@NullMarkedcredential classes and their correspondingBuildernested classes, fields that default tonullbefore 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
@Nullableannotations across builder fields, builder setters (parameters and returns), and corresponding credential getter return types across 21 credential and authorizer builder classes.