[Java][Spring] keep @Nullable on inherited fluent setters in allOf children
Fixes #25831
With useJspecify=true, the fluent setter a model declares for its own property gets @Nullable (via the nullableArgument_chainSetter partial), but the fluent setters an allOf child re-declares for the parent's properties (the ones that call super.<name>(...)) used the bare {{{datatypeWithEnum}}}. In a @NullMarked package the override then declares a non-null parameter for a method that accepts null, which NullAway and other JSpecify checkers report.
The fix makes the inherited fluent setter in JavaSpring/pojo.mustache use the same nullableArgument_chainSetter partial as the parent's own setter, so the child's signature now always matches the parent's (including type-use placement such as java.time.@Nullable Instant, and the useOptional / optionalAcceptNullable rules). Required non-nullable properties stay unannotated. add*Item / put*Item are unchanged.
Without JSpecify, the child also gets the same @Nullable the parent setter already had for optional properties, which is why the regenerated samples include non-JSpecify Spring samples (signature-only changes on BigCat, ChildWithNullable, the oneOf samples, and so on).
Testing
- New
SpringCodegenTest#testJspecify_inheritedFluentSettersKeepNullable(new spec3_0/java/jspecify-allof-inherited-setters.yaml), run for all 8jspecifyLibrariescombinations: it fails on master (8 failures) and passes with this change. ./mvnw clean package: build and all unit tests passed../bin/generate-samples.sh ./bin/configs/*.yaml(841 generators) and./bin/utils/export_docs_generators.sh: committed the regenerated samples, no doc changes.mvn clean packageon each of the 25 changed Spring samples that CI builds: all passed.- Generated the issue's spec with
useJspecify=trueandopenApiNullabletrue/false,useOptional=true, anduseJspecify=false: in every case eachChildfluent setter signature is now identical to theBaseone, and the output compiles.
Java Spring technical committee: @cachescrubber @welshm @MelleD @atextor @manedev79 @javisst @borsch @banlevente @Zomzog @martin-mfg @KannaKim
| Before | After |
|---|---|
![]() | ![]() |
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 the inherited fluent setters in allOf children so they keep @Nullable, preventing JSpecify checkers like NullAway from flagging the override in @NullMarked packages.
The change reuses the same nullableArgument_chainSetter partial used for a model's own property setters, so child signatures always match the parent's, including type-use placement (java.time.@Nullable Instant) and the useOptional/optionalAcceptNullable rules. Required properties stay unannotated and add*Item/put*Item are untouched. Without JSpecify, children now also get the same @Nullable as the parent setter for optional properties.
Testing
- Added
SpringCodegenTest#testJspecify_inheritedFluentSettersKeepNullablewith a new spec, run across all 8jspecifyLibrariescombinations (fails on master, passes here). - Regenerated all samples; the diff is signature-only
@Nullableadditions on the affected models.

