[SPRING] Improve jSpecify Nullable for all args constructor, fluent setters and Builder and toIndentedString
when useJspecify=true:
- add
@Nullableon fluent setters, all argument constructors and builder for non required attributes. HonoropenApiNullable,useOptionalandoptionalAcceptNullable. fixes #23681 Supersedes #24263 - fix #24294 for Spring (default value handling)
- update
lambda.jSpecifyNullableto generate@Nullable List<java.time.Instant>instead ofList<java.time.@Nullable Instant)
For all spring options:
- fix #22598 (
String toIndentedString(@Nullable Object o)
Add unit tests in SpringCodegenTest
Add 2 more spring samples
Example using useOptional=true and optionalAcceptNullable=true
public Foo color(@Nullable String color) {
this.color = Optional.ofNullable(color);
return this;
}
useOptional=true and optionalAcceptNullable=false
public Foo color(String color) {
this.color = Optional.of(color);
return this;
}
ps: this PR focuses on jspecify. There are still some missing @jakarta.annotation.Nullable when useJspecify=false.
It avoids regenerating too many samples. That is for another PR. There are comments in the mustache template like {{!backward compatibility}} to locate the code to fix.
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.
Review welcome:
@cachescrubber (2022/02) @welshm (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) @KannaKim (2026/07)
Summary by cubic
Improves JSpecify @Nullable in Spring generators: we annotate all-args constructors and builder/fluent setters, place @Nullable correctly on qualified types and generics, and honor openApiNullable, useOptional, and optionalAcceptNullable. Adds Spring Boot 4 configs/samples, maps OffsetDateTime to java.time.Instant, and updates samples with a color query param and related fields.
-
New Features
- All-args constructors and builder chain setters add
@NullablewhenuseJspecify=true, honoringopenApiNullable,useOptional, andoptionalAcceptNullable; packages marked@NullMarked. - New Spring Boot 4 configs:
spring-boot-4-jspecify-openapiNullable.yamlandspring-boot-4-jspecify-useOptional.yaml;OffsetDateTime->java.time.Instant,BigDecimal->java.math.BigDecimal. - API/models: add
colorquery param (defaultred) and related fields; samples regenerated across clients/servers; CI/workflows include new sample dirs and fix naming tospringboot-4-jspecify.
- All-args constructors and builder chain setters add
-
Bug Fixes
- Correct JSpecify placement before generics via
getLastIndex, yieldingjava.time.@Nullable Instantand@Nullable List<java.time.Instant>. - Use
nullableDatatypeWithEnuminJava/nullableArgumentWithEnum.mustache; builder setters usenullableArgument_builder. - Split
nullableAnnotation.mustacheintonullableAnnotation_jspecify.mustacheandnullableAnnotation_default.mustachefor correct rules and backward compatibility. - Mark
toIndentedString(@Nullable Object o)across samples and add test assertions foroptionalAcceptNullable=true/false.
- Correct JSpecify placement before generics via