[java] Add missing @Nullable with useJspecify for additionalProperties, equals and toIndentedString
Merged
NQ
1d ago+134+134+012345678901234567890123456789-61-61-01234567890123456789
Partially addresses #25536.
With useJspecify, model packages are @NullMarked, but the restclient, webclient, resttemplate, native and microprofile templates left these nullable values without @Nullable:
- the
additionalPropertiesmap field andgetAdditionalProperties(), which staynulluntil the firstputAdditionalPropertycall getAdditionalProperty(String), which returnsnullfor a missing key. A qualified type gets the annotation on its simple name (java.time.@Nullable Instant), through the existingjSpecifyNullable/jSpecifyDatatypelambdas.- the parameter of
equals(Object)andtoIndentedString(Object), which both handlenull
Nothing changes without useJspecify. Not covered here: nullability of the map's values, and the JavaSpring templates.
Tests:
- New
JavaClientCodegenTest#testJspecifyNullableAdditionalPropertiesAndObjectParameterscovers all 5 libraries and fails without the template change. - New
JavaClientCodegenTest#testNullableAdditionalPropertiesOnlyWithJspecify. JavaClientCodegenTest,JavaModelTestandJavaMicroprofileServerCodegenTestpass (397 tests).- The regenerated jspecify samples compile, and so do restclient and native clients generated from the new test spec.
PR checklist
- Read the contribution guidelines.
- Run the following to build the project and update samples:
I regenerated the six Java client configs that use./mvnw clean package || exit ./bin/generate-samples.sh ./bin/configs/*.yaml || exit ./bin/utils/export_docs_generators.sh || exituseJspecify(bin/configs/java-*-jspecify*.yaml), which are the only samples these templates affect. The other jspecify configs (spring-boot-4-*,jaxrs-spec-quarkus-jspecify) use other generators whose templates aren't changed here. No generator options changed, so the generator docs are unaffected. - If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request: @martin-mfg @KannaKim @Zomzog
Summary by cubic
Adds missing @Nullable annotations to the restclient, webclient, resttemplate, native, and microprofile Java client templates when useJspecify is enabled, since @NullMarked packages would otherwise treat these nullable values as non-null.
- Annotates the
additionalPropertiesmap field andgetAdditionalProperties(), which staynulluntil the firstputAdditionalPropertycall. - Annotates
getAdditionalProperty(String), which returnsnullfor a missing key; qualified types get the annotation on their simple name (for example,java.time.@Nullable Instant). - Annotates the
equals(Object)andtoIndentedString(Object)parameters, which both handlenull. - Adds tests covering all five libraries; output is unchanged without
useJspecify.