[JAVA] fix jspecify in java builders
Draft
JP
3mo ago+9097+9097+0123456789012345678901234567890123456789-228-228-012345678901234567890123456789
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:
(For Windows users, please run the script in WSL)./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exit
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
@Nullablein builder setters via newnullableArgument_builderfor Java and Spring (respectsuseOptionalandoptionalAcceptNullablein Spring). - Add
@Nullableto Spring all‑args constructors whenuseJspecifyis enabled. - Mark
toIndentedString(Object o)as@Nullableacross Java templates and all library variants. - New sample configs:
spring-boot-4-jspecify-openapiNullable,spring-boot-4-jspecify-useOptional, andjava-restclient-springBoot4-jackson3-jspecify-openapiNullable; CI workflows include them.
- Apply
-
Bug Fixes
- Correct enum nullable handling by using
nullableDatatypeWithEnuminnullableArgumentWithEnum.mustache. - Fix JSpecify annotation placement with generics using
getLastIndexinAbstractJavaCodegen. - Update
nullable_var_annotationsand SpringnullableAnnotationlogic to honoruseJspecify,openApiNullable, anduseOptional(split into default and JSpecify variants). - Exclude tests from generated
.openapi-generator/FILESto reduce noise in CI.
- Correct enum nullable handling by using