Repository navigation
[Java][Spring] keep @Nullable on inherited fluent setters in allOf children - #25850
shu-chen-dot-ca wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
2 issues found across 75 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/test/resources/3_0/java/jspecify-allof-inherited-setters.yaml">
<violation number="1" location="modules/openapi-generator/src/test/resources/3_0/java/jspecify-allof-inherited-setters.yaml:15">
P2: The fixture has no required property that is also nullable, so the regression test never covers that case. Add a `nullable: true` required property to `Base` and assert its inherited `Child` setter keeps `@Nullable`.</violation>
</file>
<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java:8419">
P3: This regression test only covers the `useOptional=false` path. The PR changes inherited setters to use `nullableArgument_chainSetter`, which has separate `useOptional` / `optionalAcceptNullable` branches, but no test case asserts those inherited setters. Add a case with `useOptional` enabled (and `optionalAcceptNullable` on and off) to lock in the intended signatures.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| properties: | ||
| kind: | ||
| type: string | ||
| description: |
There was a problem hiding this comment.
P2: The fixture has no required property that is also nullable, so the regression test never covers that case. Add a nullable: true required property to Base and assert its inherited Child setter keeps @Nullable.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/resources/3_0/java/jspecify-allof-inherited-setters.yaml, line 15:
<comment>The fixture has no required property that is also nullable, so the regression test never covers that case. Add a `nullable: true` required property to `Base` and assert its inherited `Child` setter keeps `@Nullable`.</comment>
<file context>
@@ -0,0 +1,29 @@
+ properties:
+ kind:
+ type: string
+ description:
+ type: string
+ nullable: true
</file context>
| } | ||
|
|
||
| @Test(dataProvider = "jspecifyLibraries") | ||
| public void testJspecify_inheritedFluentSettersKeepNullable(String library, int springBootVersion) throws IOException { |
There was a problem hiding this comment.
P3: This regression test only covers the useOptional=false path. The PR changes inherited setters to use nullableArgument_chainSetter, which has separate useOptional / optionalAcceptNullable branches, but no test case asserts those inherited setters. Add a case with useOptional enabled (and optionalAcceptNullable on and off) to lock in the intended signatures.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java, line 8419:
<comment>This regression test only covers the `useOptional=false` path. The PR changes inherited setters to use `nullableArgument_chainSetter`, which has separate `useOptional` / `optionalAcceptNullable` branches, but no test case asserts those inherited setters. Add a case with `useOptional` enabled (and `optionalAcceptNullable` on and off) to lock in the intended signatures.</comment>
<file context>
@@ -8415,6 +8415,37 @@ public void testJspecify_useOptional(String library, int springBootVersion, bool
}
+ @Test(dataProvider = "jspecifyLibraries")
+ public void testJspecify_inheritedFluentSettersKeepNullable(String library, int springBootVersion) throws IOException {
+ // https://github.com/OpenAPITools/openapi-generator/issues/25831
+ String springVersionProperty = springBootVersion == 4? USE_SPRING_BOOT4: USE_SPRING_BOOT3;
</file context>
Fixes #25831
With
useJspecify=true, the fluent setter a model declares for its own property gets@Nullable(via thenullableArgument_chainSetterpartial), but the fluent setters anallOfchild re-declares for the parent's properties (the ones that callsuper.<name>(...)) used the bare{{{datatypeWithEnum}}}. In a@NullMarkedpackage 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.mustacheuse the samenullableArgument_chainSetterpartial as the parent's own setter, so the child's signature now always matches the parent's (including type-use placement such asjava.time.@Nullable Instant, and theuseOptional/optionalAcceptNullablerules). Required non-nullable properties stay unannotated.add*Item/put*Itemare unchanged.Without JSpecify, the child also gets the same
@Nullablethe parent setter already had for optional properties, which is why the regenerated samples include non-JSpecify Spring samples (signature-only changes onBigCat,ChildWithNullable, the oneOf samples, and so on).Testing
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.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
PR checklist
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.
Summary by cubic
Fixes the inherited fluent setters in
allOfchildren so they keep@Nullable, preventing JSpecify checkers like NullAway from flagging the override in@NullMarkedpackages.The change reuses the same
nullableArgument_chainSetterpartial 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 theuseOptional/optionalAcceptNullablerules. Required properties stay unannotated andadd*Item/put*Itemare untouched. Without JSpecify, children now also get the same@Nullableas the parent setter for optional properties.Testing
SpringCodegenTest#testJspecify_inheritedFluentSettersKeepNullablewith a new spec, run across all 8jspecifyLibrariescombinations (fails on master, passes here).@Nullableadditions on the affected models.Written for commit 9a6b7b3. Summary will update on new commits.