Skip to content

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

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

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

Conversation

@nnicolee

@nnicolee nnicolee commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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

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.

JSR-305 (jsr305) Dependency Removal:

We removed the com.google.code.findbugs:jsr305 dependency from the pom.xml files. This is not a breaking change for the following reasons:

  • Why it was removed: Because we removed all references to the javax.annotation package in the codebase, the Maven dependency analyzer (mvn dependency:analyze) flagged jsr305 as an unused declared dependency. Since our verification fails on any warning (-DfailOnWarning=true), the dependency had to be removed to pass presubmit checks.
  • Why it's not a breaking change: The dependency was declared with provided scope, meaning it was only used during compilation and was never distributed transitively to downstream users. Removing it has no runtime impact on library consumers.

Changes:

  • Removed import javax.annotation.Nonnull; and @Nonnull from 30 files across gax, gax-grpc, and gax-httpjson (including test files).
  • Migrated remaining javax.annotation.Nullable usages in tests to JSpecify's @Nullable type-use annotation.
  • Removed the unused jsr305 dependency from the gax-java module POMs.
  • Formatted all modified files using fmt-maven-plugin.
  • Verified that all compilation and dependency analysis stages pass cleanly.

@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.

@nnicolee
nnicolee requested a review from lqiu96 July 30, 2026 16:14
Comment on lines -64 to -68
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

qq, why is this dep removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since we migrated the codebase to JSpecify, we removed all references to the javax.annotation packages (which are provided by the JSR-305 / jsr305 dependency).

Leaving this dependency declared would trigger an "unused declared dependency" warning!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok, got it. Can you add a note to the PR description why this isn't a breaking change and why we removed it? I think this should be fine since this is provided scope and won't be part of the customer's dependency tree from this jar

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated the PR message!

Comment thread sdk-platform-java/gax-java/gax-grpc/pom.xml
@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

@lqiu96

lqiu96 commented Aug 3, 2026

Copy link
Copy Markdown
Member

@nnicolee I think there are a few straggling instances I've seen with @Nullable being in the wrong spot from doing a spot check:

Can you take a look? I think we can also raise a new PR to do additional cleanup

@lqiu96

lqiu96 commented Aug 3, 2026

Copy link
Copy Markdown
Member

/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 migrates the codebase from JSR-305 nullness annotations (@nonnull, @nullable) to JSpecify annotations (@nullable, @NullMarked). It removes the jsr305 dependency from the Maven POM files across multiple modules (gax-grpc, gax-httpjson, and gax) and updates the Java source files by removing @nonnull annotations (relying on class-level @NullMarked instead) and shifting @nullable annotations to type-use positions. There are no review comments to address, and I have no additional feedback to provide.

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.

2 participants