Skip to content

feat(gapic-generator): add JSpecify Null annotations to the generator classes#13769

Merged
nnicolee merged 12 commits into
mainfrom
feat/jspecify-generator-annotations
Jul 23, 2026
Merged

feat(gapic-generator): add JSpecify Null annotations to the generator classes#13769
nnicolee merged 12 commits into
mainfrom
feat/jspecify-generator-annotations

Conversation

@nnicolee

@nnicolee nnicolee commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This PR continues the onboarding of the gapic-generator-java project to JSpecify null-safety. Specifically, it applies the @NullMarked annotation to all modified source and test classes in this branch to declare them non-null by default.

Annotations Applied

  • @NullMarked Class Declarations: Applied at the class level to all modified source and test classes to establish a non-null by default context.
  • @nullable Type Annotations: Applied to specific methods, fields, and parameters to explicitly denote where null values are accepted/returned.

Automation Method
To apply the class-level annotations efficiently, we leveraged Chris's Error Prone automation tool (custom BugChecker plugin under com.google.errorprone.bugpatterns.nullness) to run AST-based refactoring and automatically insert the JSpecify @NullMarked annotations across the codebase.

Verification/Testing

@nnicolee
nnicolee requested a review from lqiu96 July 14, 2026 14:20
@nnicolee nnicolee added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 14, 2026
gemini-code-assist[bot]

This comment was marked as resolved.

@nnicolee nnicolee removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Jul 22, 2026
@nnicolee
nnicolee marked this pull request as ready for review July 22, 2026 16:16
@nnicolee
nnicolee requested review from a team as code owners July 22, 2026 16:16
@lqiu96

lqiu96 commented Jul 22, 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 introduces JSpecify nullness annotations (@NullMarked and @Nullable) across the codebase to improve null-safety and static analysis. The review feedback highlights a potential nullness analysis error in Writer.java, where the gapicPackageInfo parameter of the write method should be explicitly annotated with @Nullable because it can receive null values from Composer.composePackageInfo.

@sonarqubecloud

Copy link
Copy Markdown

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

Failed conditions
72.7% Coverage on New Code (required ≥ 80%)
C Reliability Rating on New Code (required ≥ A)
B Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

@sonarqubecloud

Copy link
Copy Markdown

@nnicolee

Copy link
Copy Markdown
Contributor Author

/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 integrates JSpecify nullness annotations (@NullMarked and @nullable) across numerous classes in the gapic-generator-java project to enhance static analysis and null safety. The review feedback highlights three critical nullness issues introduced by these changes: a potential NullPointerException in CodeGeneratorRequestFileToGapicMain.java due to a missing null check on a @nullable response, a static analysis warning in Main.java where a null check is performed using a constant instead of a direct null comparison, and a nullness mismatch in Trie.java where a @nullable field is passed to a non-null-marked function parameter.

@nnicolee
nnicolee merged commit 843bd7c into main Jul 23, 2026
402 of 405 checks passed
@nnicolee
nnicolee deleted the feat/jspecify-generator-annotations branch July 23, 2026 14:55
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.

3 participants