Skip to content

[java] Add missing @Nullable with useJspecify for additionalProperties, equals and toIndentedString - #25586

Merged
wing328 merged 2 commits into
OpenAPITools:masterfrom
Nqvinh7603:java-jspecify-nullable-additional-properties
Nov 10, 2026
Merged

wing328 merged 2 commits into
OpenAPITools:masterfrom
Nqvinh7603:java-jspecify-nullable-additional-properties

Conversation

@Nqvinh7603

@Nqvinh7603 Nqvinh7603 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Partially addresses #25536.

With useJspecify, model packages are @NullMarked, but the restclient, webclient, resttemplate, native and microprofile templates left these nullable values without @Nullable:

  • the additionalProperties map field and getAdditionalProperties(), which stay null until the first putAdditionalProperty call
  • getAdditionalProperty(String), which returns null for a missing key. A qualified type gets the annotation on its simple name (java.time.@Nullable Instant), through the existing jSpecifyNullable/jSpecifyDatatype lambdas.
  • the parameter of equals(Object) and toIndentedString(Object), which both handle null

Nothing changes without useJspecify. Not covered here: nullability of the map's values, and the JavaSpring templates.

Tests:

  • New JavaClientCodegenTest#testJspecifyNullableAdditionalPropertiesAndObjectParameters covers all 5 libraries and fails without the template change.
  • New JavaClientCodegenTest#testNullableAdditionalPropertiesOnlyWithJspecify.
  • JavaClientCodegenTest, JavaModelTest and JavaMicroprofileServerCodegenTest pass (397 tests).
  • The regenerated jspecify samples compile, and so do restclient and native clients generated from the new test spec.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    I regenerated the six Java client configs that use useJspecify (bin/configs/java-*-jspecify*.yaml), which are the only samples these templates affect. The other jspecify configs (spring-boot-4-*, jaxrs-spec-quarkus-jspecify) use other generators whose templates aren't changed here. No generator options changed, so the generator docs are unaffected.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request: @martin-mfg @KannaKim @Zomzog

Summary by cubic

Adds missing @Nullable annotations to the restclient, webclient, resttemplate, native, and microprofile Java client templates when useJspecify is enabled, since @NullMarked packages would otherwise treat these nullable values as non-null.

  • Annotates the additionalProperties map field and getAdditionalProperties(), which stay null until the first putAdditionalProperty call.
  • Annotates getAdditionalProperty(String), which returns null for a missing key; qualified types get the annotation on their simple name (for example, java.time.@Nullable Instant).
  • Annotates the equals(Object) and toIndentedString(Object) parameters, which both handle null.
  • Adds tests covering all five libraries; output is unchanged without useJspecify.

Written for commit 78be673. Summary will update on new commits.

View guided diff

…s, equals and toIndentedString

With useJspecify the model packages are @NullMarked, but the restclient,
webclient, resttemplate, native and microprofile templates left several
nullable values unannotated:

- the additionalProperties map field and getAdditionalProperties(), which
  stay null until the first putAdditionalProperty call
- getAdditionalProperty(String), which returns null for a missing key
  (a qualified type gets the annotation on its simple name)
- the parameter of equals(Object) and toIndentedString(Object), which
  both handle null

Refs OpenAPITools#25536

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 30 files

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

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

Built the head on JDK 17, ran JavaClientCodegenTest, and compiled clients of all five libraries with useJspecify, including array, map and enum values. For #25536, not this PR: equals(Object) and toIndentedString(Object) are still unannotated in single_request_parameter.mustache (webclient, restclient) and native AbstractOpenApiSchema.mustache.

@wing328

wing328 commented Nov 9, 2026

Copy link
Copy Markdown
Member

thanks for the PR

also cc @jpfinne

@wing328 wing328 added this to the 7.28.0 milestone Nov 9, 2026
@jpfinne

jpfinne commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

thanks for the PR

also cc @jpfinne

Seems good to me
Approved.

@wing328
wing328 merged commit 81eeb20 into OpenAPITools:master Nov 10, 2026
114 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants