Skip to content

[Spring] fix missing @Nullable on toIndentedString param when useJspecify=true - #24567

Open
SubhamAshok wants to merge 2 commits into
OpenAPITools:masterfrom
SubhamAshok:fix/jspecify-nullable-toindentedstring
Open

[Spring] fix missing @Nullable on toIndentedString param when useJspecify=true#24567
SubhamAshok wants to merge 2 commits into
OpenAPITools:masterfrom
SubhamAshok:fix/jspecify-nullable-toindentedstring

Conversation

@SubhamAshok

@SubhamAshok SubhamAshok commented Aug 2, 2026

Copy link
Copy Markdown

With useJspecify=true, toIndentedString(Object o) is generated without @nullable. The nullableAnnotation partial strips the annotation and nothing puts it back, since Object is not wrapped in the jSpecifyDatatype lambda. Without jspecify the output is @nullable Object o, so the two modes disagree.

This matters because the model package is @NullMarked and toString() passes nullable fields into this method. NullAway and IntelliJ report an error on every generated model.

Fix: wrap Object in the jSpecifyDatatype lambda, same pattern as the rest of the template. This complements #24563 which fixes the constructor and fluent setter spots. Relates to #23848.

Checked both modes. jspecify=true now gives @nullable Object o with the import. jspecify=false output is byte identical to before. Added an assertion to SpringCodegenTest#testJspecify, all 8 combos pass. Regenerated samples for bin/configs/spring-boot-4-jspecify.yaml, the diff is one line.

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
    
    (Scoped sample regeneration to the affected config, spring-boot-4-jspecify.yaml. No generator options or docs changed, so export_docs_generators was not needed.)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

cc Java Spring technical committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim


Summary by cubic

Fixes missing @nullable on toIndentedString(Object o) when useJspecify=true by hardcoding the annotation in the Spring POJO template. This aligns jspecify and non-jspecify outputs and removes nullness errors in @NullMarked models. Complements #24563 and relates to #23848.

  • Bug Fixes
    • Hardcode @Nullable on toIndentedString(@Nullable Object o) in pojo.mustache instead of using the nullableAnnotation partial, avoiding context side effects and applying the fix to use-optional variants too.
    • Add a test assertion for the method signature and the import of org.jspecify.annotations.Nullable; regenerate affected samples.

Written for commit 6bd8ee2. Summary will update on new commits.

Review in cubic

…cify=true

The nullableAnnotation partial strips the annotation in jspecify mode
and nothing re-inserts it, since Object is not wrapped in the
jSpecifyDatatype lambda. Wrap it like the rest of the template does.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

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

No issues found across 3 files

Re-trigger cubic

@jpfinne

jpfinne commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

@SubhamAshok I think everyone makes it too complex by using {{>nullableAnnotation}} For example #22685 and #22599
The partial is intended to be used for a CodeGenProperty.

It gives side effects with the complex conditions on the property (required, isNullable, defaultValue....)
Let keep it simple: String toIndentedString(@Nullable Object o)

My PR is work in progress: #24563

…partial

Review feedback: nullableAnnotation is meant for a CodegenProperty context
and its conditions cause side effects here. The method always accepts null,
so state it directly. useOptional samples now get the annotation too.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@SubhamAshok

Copy link
Copy Markdown
Author

Thanks, makes sense. #22599 / #22685 show how the partial got here and why it keeps breaking. Updated to a hardcoded @Nullable Object o. Note: useOptional configs previously got no annotation here, now they do, so a few more sample files changed. All spring samples regenerated.

@jpfinne

jpfinne commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

@SubhamAshok My PR is ready #24563

It includes the same fix for toIndentedString, and a lot more for fluent setters...

Can you review?

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