Skip to content

cleanup(generator): remove javax.annotation.Nonnull usage - #13960

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

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

Conversation

@nnicolee

Copy link
Copy Markdown
Contributor

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

Why this change is needed:

As part of the migration to JSpecify annotations, generator 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.

Changes:

  • Removed import javax.annotation.Nonnull; and @Nonnull from 4 files in the generator codebase (TypeParser.java, SourceCodeInfoLocation.java, TryCatchStatement.java, and ImportWriterVisitor.java).
  • Formatted the modified files using fmt-maven-plugin.
  • Verified that all compilation references to javax.annotation.Nonnull under gapic-generator-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 redundant @Nonnull annotations and their corresponding imports across several files, including TryCatchStatement.java, ImportWriterVisitor.java, SourceCodeInfoLocation.java, and TypeParser.java, as these classes are already annotated with @NullMarked. Feedback on the changes highlights that the body parameter in the addCatch method of TryCatchStatement.java is currently unused and suggests updating the builder to properly record the catch block statements.

Comment on lines +64 to 67
public Builder addCatch(VariableExpr variableExpr, List<Statement> body) {
List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs());
catchVarExprs.add(variableExpr);
setCatchVariableExprs(catchVarExprs);

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 body parameter in addCatch is currently unused, which means the catch block's statements are ignored and not added to the TryCatchStatement. If TryCatchStatement uses catchBlocks() to store the catch block bodies, you should update this method to also add the body to catchBlocks().

Suggested change
public Builder addCatch(VariableExpr variableExpr, List<Statement> body) {
List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs());
catchVarExprs.add(variableExpr);
setCatchVariableExprs(catchVarExprs);
public Builder addCatch(VariableExpr variableExpr, List<Statement> body) {
List<VariableExpr> catchVarExprs = new ArrayList<>(catchVariableExprs());
catchVarExprs.add(variableExpr);
setCatchVariableExprs(catchVarExprs);
List<List<Statement>> catchBodies = new ArrayList<>(catchBlocks());
catchBodies.add(body);
setCatchBlocks(catchBodies);
}

@nnicolee
nnicolee requested a review from lqiu96 July 30, 2026 16:14
@sonarqubecloud

Copy link
Copy Markdown

@sonarqubecloud

Copy link
Copy Markdown

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