[Java][microprofile] - Add JSpecify support

Merged
IG
2mo ago
+2865-19

Adds useJspecify support to the java generator's microprofile library.

Fixes #24883

Changes

  • JavaClientCodegen: add MICROPROFILE to JSPECIFY_SUPPORTED_LIBRARIES.
  • pojo.mustache: @Nullable on the field, getter, setter and fluent setter, with types routed through nullableDatatypeWithEnum so the annotation lands type-use style on qualified types (java.math.@Nullable BigDecimal).
  • queryParams / pathParams / headerParams / bodyParams / cookieParams / formParams: @Nullable on operation parameters, alongside the existing JAX-RS annotations.
  • pom.mustache + pom_3.0.mustache: declare org.jspecify:jspecify:1.0.0.
  • Regenerated docs/generators/java.md and docs/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.mustache emits @{{javaxPackage}}.annotation.Nullable/Nonnull when the flag is off, and those symbols do not resolve in a generated microprofile project
  • jakarta.annotation.Nullable/Nonnull were only added in jakarta.annotation-api 2.1.1, while the microprofile poms pin 1.3.5 (rest client 2.0) and 2.0.0 (rest client 3.0).

Testing

  • New testJspecify_microprofile in JavaClientCodegenTest, 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, covering useJspecify together with useSealedOneOfInterfaces (previously uncovered)
  • <java.version>17</java.version> and the jspecify dependency. It uses a dedicated fixture because oneof_interface_petstore.yaml has only required properties, so it would produce no @Nullable and assert nothing.
  • New sample samples/client/petstore/java/microprofile-rest-client-3.0-jspecify, registered in samples-java-client-jdk11.yaml.

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/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.