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

Closed
SU
3mo ago
+64-63

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.