Skip to content

[Java][jaxrs-spec] Annotate nullable @JsonCreator/@JsonbCreator parameters with JSpecify (fixes #25438) - #25439

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
ivufim:fix/jaxrs-spec-jspecify-json-creator
Nov 2, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
ivufim:fix/jaxrs-spec-jspecify-json-creator

Conversation

@ivufim

@ivufim ivufim commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #25438. Follow-up to #24885.

Problem

With useJspecify=true, jaxrs-spec annotates fields, getters, setters and fluent setters of nullable properties
with @Nullable, but not the parameters of the generated @JsonCreator constructor (nor, since #25177, the
@JsonbCreator constructor). These constructors take the required properties, so a property that is both
required and nullable: true ends up with an unannotated parameter. Because the model package is @NullMarked, that
parameter means non-null, and calling the constructor with null is reported as an error by NullAway (JSpecify mode)
and other JSpecify-aware checkers, although the spec explicitly allows null.

Example from the existing jaxrs-spec-quarkus-jspecify sample (RequiredAndNullable), before:

private @Nullable String str;
...
@JsonCreator
public RequiredAndNullable(
  @JsonProperty(required = true, value = "str") String str,   // non-null under @NullMarked

after:

  @JsonProperty(required = true, value = "str") @Nullable String str,

The Spring and Java client generators already got the equivalent fix in #24563 and #24711; jaxrs-spec has its own
template directory and doesn't inherit it.

Changes

  • JavaJaxRS/spec/pojo.mustache: the @JsonCreator and @JsonbCreator constructor parameters use the same
    pattern as the getter: nullable_var_annotations stashes the annotation and the jSpecifyDatatype lambda emits it,
    so qualified types keep type-use placement (java.math.@Nullable BigDecimal). Both changes are guarded by
    {{#useJspecify}}/the lambda, so output without useJspecify is unchanged.
  • JavaJAXRSSpecServerCodegenTest: testUseJspecify now asserts the @JsonCreator parameters of
    RequiredAndNullable (nullable ones annotated, onlyRequired not); new testUseJspecifyWithJsonbCreator asserts
    the same for the JSON-B constructor.
  • Updated sample jaxrs-spec-quarkus-jspecify (RequiredAndNullable.java). No other sample uses useJspecify with
    jaxrs-spec, so no other sample changes.

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/jaxrs-spec-quarkus-jspecify.yaml || exit
    
    No generator option changed, so export_docs_generators.sh produces no diff.
  • @mention the technical committee members for Java.

cc @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim

…eters with JSpecify (fixes OpenAPITools#25438)

With useJspecify, pojo.mustache annotates fields, getters, setters and
fluent setters of nullable properties, but not the parameters of the
@jsoncreator and @JsonbCreator constructors. Those constructors take the
required properties, so a property that is both required and nullable
gets an unannotated parameter. Under the generated @NullMarked package
that parameter means non-null, and callers passing null are reported by
NullAway and other JSpecify checkers.

Use the same pattern as the getter: nullable_var_annotations stashes the
annotation and the jSpecifyDatatype lambda emits it in type-use position
(e.g. java.math.@nullable BigDecimal).

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

View guided diff | Re-trigger cubic

@wing328

wing328 commented Nov 2, 2026

Copy link
Copy Markdown
Member

thanks for the PR

cc @Ignacio-Vidal (author of #24885)

@wing328 wing328 added this to the 7.27.0 milestone Nov 2, 2026
@wing328
wing328 merged commit 0ed71f2 into OpenAPITools:master Nov 2, 2026
60 checks passed
@Ignacio-Vidal

Copy link
Copy Markdown
Contributor

Thank you for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][JAVA][jaxrs-spec] useJspecify: nullable required properties are not annotated in @JsonCreator/@JsonbCreator constructor

3 participants