[JAVA] fix jspecify in java builders

Draft
JP
3mo ago
+9097-228

Fix some missing @Nullable annotations for java clients:

  • add in builders
  • add in toIndentedString()

Add a sample for openapiNullable

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
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes JSpecify nullability in generated Java and Spring Boot 4 code so builder chain setters and all‑args constructors accept @Nullable where expected, including for fully qualified types and generics. Adds new openApiNullable/useOptional sample configs, updates workflows/tests/samples, and cleans up generated FILES lists.

  • New Features

    • Apply @Nullable in builder setters via new nullableArgument_builder for Java and Spring (respects useOptional and optionalAcceptNullable in Spring).
    • Add @Nullable to Spring all‑args constructors when useJspecify is enabled.
    • Mark toIndentedString(Object o) as @Nullable across Java templates and all library variants.
    • New sample configs: spring-boot-4-jspecify-openapiNullable, spring-boot-4-jspecify-useOptional, and java-restclient-springBoot4-jackson3-jspecify-openapiNullable; CI workflows include them.
  • Bug Fixes

    • Correct enum nullable handling by using nullableDatatypeWithEnum in nullableArgumentWithEnum.mustache.
    • Fix JSpecify annotation placement with generics using getLastIndex in AbstractJavaCodegen.
    • Update nullable_var_annotations and Spring nullableAnnotation logic to honor useJspecify, openApiNullable, and useOptional (split into default and JSpecify variants).
    • Exclude tests from generated .openapi-generator/FILES to reduce noise in CI.