Repository navigation
[Java][jaxrs-spec] Annotate nullable @JsonCreator/@JsonbCreator parameters with JSpecify (fixes #25438) - #25439
Merged
wing328 merged 1 commit intoNov 2, 2026
Conversation
…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).
Member
|
thanks for the PR cc @Ignacio-Vidal (author of #24885) |
Contributor
|
Thank you for the fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25438. Follow-up to #24885.
Problem
With
useJspecify=true,jaxrs-specannotates fields, getters, setters and fluent setters of nullable propertieswith
@Nullable, but not the parameters of the generated@JsonCreatorconstructor (nor, since #25177, the@JsonbCreatorconstructor). These constructors take the required properties, so a property that is bothrequiredandnullable: trueends up with an unannotated parameter. Because the model package is@NullMarked, thatparameter means non-null, and calling the constructor with
nullis 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-jspecifysample (RequiredAndNullable), before:after:
The Spring and Java client generators already got the equivalent fix in #24563 and #24711;
jaxrs-spechas its owntemplate directory and doesn't inherit it.
Changes
JavaJaxRS/spec/pojo.mustache: the@JsonCreatorand@JsonbCreatorconstructor parameters use the samepattern as the getter:
nullable_var_annotationsstashes the annotation and thejSpecifyDatatypelambda emits it,so qualified types keep type-use placement (
java.math.@Nullable BigDecimal). Both changes are guarded by{{#useJspecify}}/the lambda, so output withoutuseJspecifyis unchanged.JavaJAXRSSpecServerCodegenTest:testUseJspecifynow asserts the@JsonCreatorparameters ofRequiredAndNullable(nullable ones annotated,onlyRequirednot); newtestUseJspecifyWithJsonbCreatorassertsthe same for the JSON-B constructor.
jaxrs-spec-quarkus-jspecify(RequiredAndNullable.java). No other sample usesuseJspecifywithjaxrs-spec, so no other sample changes.PR checklist
export_docs_generators.shproduces no diff.cc @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim