Skip to content

cleanup(gax-java): remove javax.annotation.Nonnull usage - #13959

Draft
nnicolee wants to merge 2 commits into
mainfrom
cleanup/gax-remove-javax-nonnull
Draft

cleanup(gax-java): remove javax.annotation.Nonnull usage#13959
nnicolee wants to merge 2 commits into
mainfrom
cleanup/gax-remove-javax-nonnull

Conversation

@nnicolee

Copy link
Copy Markdown
Contributor

This PR removes all occurrences of javax.annotation.Nonnull (both imports and annotations) across the gax-java codebase.

Why this change is needed:

As part of the repository-wide migration to JSpecify annotations, classes are annotated with @NullMarked, making all unannotated types non-nullable by default. The legacy javax.annotation.Nonnull annotations are redundant and can be safely removed without changing null-safety semantics.

Changes:

  • Removed import javax.annotation.Nonnull; and @Nonnull from 30 files across gax, gax-grpc, and gax-httpjson (including test files).
  • Formatted modified files using fmt-maven-plugin.
  • Verified that all compilation references to javax.annotation.Nonnull under gax-java have been eliminated.

@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 removes the @Nonnull annotation and its corresponding javax.annotation.Nonnull import across numerous files in the gax-java library, likely as part of a migration to JSpecify annotations. A review of the changes identified a redundant null check in ServerStreamingCallSettings.java where Preconditions.checkNotNull(resumptionStrategy) is called twice consecutively, which should be simplified.

Comment on lines 290 to 291
Preconditions.checkNotNull(resumptionStrategy);
this.resumptionStrategy = Preconditions.checkNotNull(resumptionStrategy);

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

The null check Preconditions.checkNotNull(resumptionStrategy) is performed twice in a row. We can simplify this by directly assigning the result of Preconditions.checkNotNull(resumptionStrategy) to this.resumptionStrategy.

Suggested change
Preconditions.checkNotNull(resumptionStrategy);
this.resumptionStrategy = Preconditions.checkNotNull(resumptionStrategy);
this.resumptionStrategy = Preconditions.checkNotNull(resumptionStrategy);
References
  1. Ensure that null checks and validation steps are not redundant with checks already performed by upstream callers or preceding logic in the same method.

@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@nnicolee
nnicolee requested a review from lqiu96 July 30, 2026 16:14
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