[Java][microprofile] - Add JSpecify support
Merged
IG
2mo ago+2865+2865+0123456789012345678901234567890123456789-19-19-01234567890123456789
Adds useJspecify support to the java generator's microprofile library.
Fixes #24883
Changes
JavaClientCodegen: addMICROPROFILEtoJSPECIFY_SUPPORTED_LIBRARIES.pojo.mustache:@Nullableon the field, getter, setter and fluent setter, with types routed throughnullableDatatypeWithEnumso the annotation lands type-use style on qualified types (java.math.@Nullable BigDecimal).queryParams/pathParams/headerParams/bodyParams/cookieParams/formParams:@Nullableon operation parameters, alongside the existing JAX-RS annotations.pom.mustache+pom_3.0.mustache: declareorg.jspecify:jspecify:1.0.0.- Regenerated
docs/generators/java.mdanddocs/generators/java-microprofile.md.
Why the template changes are guarded
Every template change is wrapped in {{#useJspecify}}, so output with useJspecify=false is unchanged. The guard is required:
- The shared
nullable_var_annotations.mustacheemits@{{javaxPackage}}.annotation.Nullable/Nonnullwhen the flag is off, and those symbols do not resolve in a generated microprofile project jakarta.annotation.Nullable/Nonnullwere only added injakarta.annotation-api2.1.1, while the microprofile poms pin1.3.5(rest client 2.0) and2.0.0(rest client 3.0).
Testing
- New
testJspecify_microprofileinJavaClientCodegenTest, asserting type-use placement on qualified types, JAX-RS parameter annotations coexisting with@Nullable, that required properties are not annotated, and the pom dependency. - New
testJspecify_microprofile_sealedOneOfInterfaces, coveringuseJspecifytogether withuseSealedOneOfInterfaces(previously uncovered) <java.version>17</java.version>and the jspecify dependency. It uses a dedicated fixture becauseoneof_interface_petstore.yamlhas only required properties, so it would produce no@Nullableand assert nothing.- New sample
samples/client/petstore/java/microprofile-rest-client-3.0-jspecify, registered insamples-java-client-jdk11.yaml.
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.