-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
With Java & spring generator, when using JSpecify Nullable annotation, the generated code don't add a @Nullable on the parameter of the generated method toIndentedString.
That creates a warns with nullAway because this private methode is called with parameters that could be nullable.
openapi-generator version
7.18.2, this is not a regression
OpenAPI declaration file content or url
My Maven plugin conf:
<configuration>
<generatorName>spring</generatorName>
...
<importMappings>
<importMapping>Nullable=org.jspecify.annotations.Nullable</importMapping>
</importMappings>
</configuration>Generation Details
Generated POJO:
package ...
import org.jspecify.annotations.Nullable;
...
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-12-30T12:03:39.667194+01:00[Europe/Zurich]", comments = "Generator version: 7.18.0")
public class XxxDto {
private @Nullable String myVar;
....
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class XxxDto {\n");
sb.append(" myVar: ").append(toIndentedString(myVar)).append("\n"); /* <=== Clash here as myVar is nullable*/
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) { /* <=== Clash here because o is not Nullable */
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}Expected POJO
package ...
import org.jspecify.annotations.Nullable;
...
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2025-12-30T12:03:39.667194+01:00[Europe/Zurich]", comments = "Generator version: 7.18.0")
public class XxxDto {
private @Nullable String myVar;
....
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class XxxDto {\n");
sb.append(" myVar: ").append(toIndentedString(myVar)).append("\n");
sb.append("}");
return sb.toString();
}
/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(@Nullable Object o) { /* <== only add @Nullable */
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}Steps to reproduce
Setup JSpecify and NullAway.
Run the generator, when compiling the following Warns are generated:
[INFO] -------------------------------------------------------------
[WARNING] COMPILATION WARNING :
[INFO] -------------------------------------------------------------
[WARNING] .../shared/target/generated-sources/src/main/java/tech/generated/dto/AboutReadDto.java:[154,57] [NullAway] passing @Nullable parameter 'tenantId' where @NonNull is required
(see http://t.uber.com/nullaway )
Related issues/PRs
I was using the mechanism introduce in this PR: #21498
Suggest a fix
See the associated PR.