[BUG][JAVA] useJspecify=true: java/restclient and java/webclient ApiClient support class still imports jakarta.annotation.Nullable
Bug Report Checklist
Description
With useJspecify=true, the java generator correctly emits org.jspecify.annotations.Nullable
on models and API code, but the generated ApiClient support class for the
restclient and webclient libraries still emits:
import jakarta.annotation.Nullable; // (or javax.annotation.Nullable when useJakartaEe=false)
used by createDefaultMapper(@Nullable DateFormat dateFormat).
The import is hardcoded in the template and is not guarded by useJspecify, so the generated
client mixes JSpecify everywhere except ApiClient, which keeps the jakarta/javax annotation.
For projects that enforce "JSpecify only" (e.g. an ArchUnit/NullAway rule banning
jakarta.annotation/javax.annotation/org.springframework.lang nullness annotations), this
single import breaks the build / trips the rule and must currently be patched out by hand.
openapi-generator version
7.23.0 (also present on master). The useJspecify option was introduced in 7.22.0 via #23256.
OpenAPI declaration file content or url
Any spec generated with the java generator and the restclient (or webclient) library —
the ApiClient support class is library-level, independent of the spec. Minimal config:
generatorName: java
library: restclient
additionalProperties:
useJakartaEe: "true"
useJspecify: "true"
Generation Steps
openapi-generator-cli generate \
-g java --library restclient \
-i petstore.yaml -o out \
--additional-properties=useJakartaEe=true,useJspecify=true
Actual output
out/src/main/java/.../ApiClient.java:
import jakarta.annotation.Nullable;
...
public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) { ... }
Expected output
Under useJspecify=true, the import should resolve to JSpecify, consistent with the rest of the
generated sources:
import org.jspecify.annotations.Nullable;
Root cause
Java/libraries/restclient/ApiClient.mustache (line 82) and
Java/libraries/webclient/ApiClient.mustache (line 85) hardcode:
import {{javaxPackage}}.annotation.Nullable;
with no {{#useJspecify}} guard. #23256 wired JSpecify through the model/API codegen
(AbstractJavaCodegen#applyJspecify / addNullableImportForOperation) and the JavaSpring
nullableAnnotation partial, but the java-library ApiClient support templates were not
updated. @Nullable is used as a simple name in both files, so only the import line needs to be
made conditional. (Other java libraries' ApiClient.mustache do not import Nullable and are
unaffected.)
[BUG][JAVA] useJspecify=true: java/restclient and java/webclient ApiClient support class still imports
jakarta.annotation.NullableBug Report Checklist
Description
With
useJspecify=true, thejavagenerator correctly emitsorg.jspecify.annotations.Nullableon models and API code, but the generated
ApiClientsupport class for therestclientandwebclientlibraries still emits:used by
createDefaultMapper(@Nullable DateFormat dateFormat).The import is hardcoded in the template and is not guarded by
useJspecify, so the generatedclient mixes JSpecify everywhere except
ApiClient, which keeps the jakarta/javax annotation.For projects that enforce "JSpecify only" (e.g. an ArchUnit/NullAway rule banning
jakarta.annotation/javax.annotation/org.springframework.langnullness annotations), thissingle import breaks the build / trips the rule and must currently be patched out by hand.
openapi-generator version
7.23.0 (also present on
master). TheuseJspecifyoption was introduced in 7.22.0 via #23256.OpenAPI declaration file content or url
Any spec generated with the
javagenerator and therestclient(orwebclient) library —the
ApiClientsupport class is library-level, independent of the spec. Minimal config:Generation Steps
Actual output
out/src/main/java/.../ApiClient.java:Expected output
Under
useJspecify=true, the import should resolve to JSpecify, consistent with the rest of thegenerated sources:
Root cause
Java/libraries/restclient/ApiClient.mustache(line 82) andJava/libraries/webclient/ApiClient.mustache(line 85) hardcode:import {{javaxPackage}}.annotation.Nullable;with no
{{#useJspecify}}guard.#23256wired JSpecify through the model/API codegen(
AbstractJavaCodegen#applyJspecify/addNullableImportForOperation) and theJavaSpringnullableAnnotationpartial, but thejava-libraryApiClientsupport templates were notupdated.
@Nullableis used as a simple name in both files, so only the import line needs to bemade conditional. (Other
javalibraries'ApiClient.mustachedo not importNullableand areunaffected.)