Skip to content

feat(gapic-generator): Add NullMarked annotation to generated classes#13584

Draft
nnicolee wants to merge 4 commits into
mainfrom
feat/jspecify-add-nullmarked
Draft

feat(gapic-generator): Add NullMarked annotation to generated classes#13584
nnicolee wants to merge 4 commits into
mainfrom
feat/jspecify-add-nullmarked

Conversation

@nnicolee

@nnicolee nnicolee commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

This PR updates the gapic-generator-java to add the JSpecify @NullMarked annotation to all generated class declarations. Adding @NullMarked at the class level defines the class scope as null-safe, establishing that all unannotated types in method signatures (parameters and return types) are nonnull able by default. This is the first phase in onboarding the generated client libraries to compile-time safety validation, see design doc for more details: go/sdk:java-jspecify-null-annotations-gapic

Classes Annotated:

  • Client Classes: AbstractServiceClientClassComposer
  • Settings Classes: AbstractServiceSettingsClassComposer and AbstractServiceStubSettingsClassComposer
  • Stub Classes: AbstractServiceStubClassComposer and AbstractTransportServiceStubClassComposer
  • Callable Factories: AbstractServiceCallableFactoryClassComposer
  • Resource Names: ResourceNameHelperClassComposer, CommonStrings

Implementation Changes:

  • Added JSpecify import statements to class-level generation templates
  • Registered NullMarked.class and Nullable.class in TypeStore across all class composers to ensure references compile and resolve properly

Verification/Testing:

Revisions:

  • Mainly to fix the autogenerator, not related to logic: added goldens + dependencies for the build

Next Steps:

  • In the next PR, will add @nullable annotations

@nnicolee nnicolee changed the title Feat/jspecify add nullmarked feat(gapic-generator): Add NullMarked annotation to generated classes Jun 29, 2026

@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 adds the org.jspecify:jspecify dependency to multiple pom.xml files across various Google Cloud Java proto modules. However, in the java-bigtable modules, the dependency was incorrectly placed inside the <dependencyManagement> block instead of the <dependencies> block. Additionally, since these pom.xml files are auto-generated, manual edits should be avoided to prevent them from being overwritten; instead, the generator or source metadata should be updated.

Comment on lines +18 to +21
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>

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

Avoid manually editing auto-generated files like pom.xml in generated client libraries because changes will be overwritten. To ensure the jspecify dependency is correctly placed in the <dependencies> block instead of <dependencyManagement>, please modify the generator or the source metadata instead.

References
  1. Avoid manually editing auto-generated files (such as pom.xml in generated client libraries) because changes will be overwritten. Modify the generator or the source metadata instead.

Comment on lines +18 to +21
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>

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

Avoid manually editing auto-generated files like pom.xml in generated client libraries because changes will be overwritten. To ensure the jspecify dependency is correctly placed in the <dependencies> block instead of <dependencyManagement>, please modify the generator or the source metadata instead.

References
  1. Avoid manually editing auto-generated files (such as pom.xml in generated client libraries) because changes will be overwritten. Modify the generator or the source metadata instead.

@sonarqubecloud

Copy link
Copy Markdown

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

Failed conditions
6.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@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