Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#lambda.jSpecifyDatatype}}{{{datatypeWithEnum}}}{{/lambda.jSpecifyDatatype}}
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
/**
* Constructor with all args parameters
*/
public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{>nullableAnnotation}}{{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{>nullableAnnotation}}{{>nullableDatatypeWithEnum}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When useOptional=true, optional scalar parameters in the all-args constructor and fluent setter still accept null at runtime (they’re wrapped in Optional.ofNullable), but the generated parameter signature omits @Nullable. The nullableAnnotation partial gates @Nullable behind {{^useOptional}}, and the jSpecifyDatatype lambda only marks the type when that annotation is emitted, so neither path compensates. This leaves a null-safety mismatch for callers in null-checked codebases. Consider extending the annotation logic so that optional properties using Optional.ofNullable also carry @Nullable on their parameters.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache, line 137:

<comment>When `useOptional=true`, optional scalar parameters in the all-args constructor and fluent setter still accept null at runtime (they’re wrapped in `Optional.ofNullable`), but the generated parameter signature omits `@Nullable`. The `nullableAnnotation` partial gates `@Nullable` behind `{{^useOptional}}`, and the `jSpecifyDatatype` lambda only marks the type when that annotation is emitted, so neither path compensates. This leaves a null-safety mismatch for callers in null-checked codebases. Consider extending the annotation logic so that optional properties using `Optional.ofNullable` also carry `@Nullable` on their parameters.</comment>

<file context>
@@ -134,7 +134,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
    * Constructor with all args parameters
    */
-  public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{>nullableAnnotation}}{{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
+  public {{classname}}({{#vendorExtensions.x-java-all-args-constructor-vars}}{{>nullableAnnotation}}{{>nullableDatatypeWithEnum}} {{name}}{{^-last}}, {{/-last}}{{/vendorExtensions.x-java-all-args-constructor-vars}}) {
   {{#parent}}
       super({{#parentVars}}{{name}}{{^-last}}, {{/-last}}{{/parentVars}});
</file context>

@Exidex Exidex Jul 9, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a way bigger task than the current change, and is mostly not related to the bug I am fixing here

{{#parent}}
super({{#parentVars}}{{name}}{{^-last}}, {{/-last}}{{/parentVars}});
{{/parent}}
Expand All @@ -153,7 +153,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
{{^lombok.Data}}

{{! begin feature: fluent setter methods }}
public {{classname}} {{name}}({{>nullableAnnotation}}{{{datatypeWithEnum}}} {{name}}) {
public {{classname}} {{name}}({{>nullableAnnotation}}{{>nullableDatatypeWithEnum}} {{name}}) {
{{#openApiNullable}}
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}Optional.of{{#optionalAcceptNullable}}Nullable{{/optionalAcceptNullable}}({{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}}{{name}}{{#isNullable}}){{/isNullable}}{{#useOptional}}{{^required}}{{^isNullable}}{{^isContainer}}){{/isContainer}}{{/isNullable}}{{/required}}{{/useOptional}};
{{/openApiNullable}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public Foo(OffsetDateTime requiredDt) {
/**
* Constructor with all args parameters
*/
public Foo(OffsetDateTime dt, org.springframework.core.io.Resource binary, List<OffsetDateTime> listOfDt, List<OffsetDateTime> listMinIntems, OffsetDateTime requiredDt, BigDecimal number) {
public Foo(@Nullable OffsetDateTime dt, org.springframework.core.io.@Nullable Resource binary, List<OffsetDateTime> listOfDt, List<OffsetDateTime> listMinIntems, OffsetDateTime requiredDt, @Nullable BigDecimal number) {
this.dt = dt;
this.binary = binary;
this.listOfDt = listOfDt;
Expand All @@ -79,7 +79,7 @@ public Foo(OffsetDateTime dt, org.springframework.core.io.Resource binary, List<
this.number = number;
}

public Foo dt(OffsetDateTime dt) {
public Foo dt(@Nullable OffsetDateTime dt) {
this.dt = dt;
return this;
}
Expand All @@ -104,7 +104,7 @@ public void setDt(@Nullable OffsetDateTime dt) {
this.dt = dt;
}

public Foo binary(org.springframework.core.io.Resource binary) {
public Foo binary(org.springframework.core.io.@Nullable Resource binary) {
this.binary = binary;
return this;
}
Expand Down Expand Up @@ -223,7 +223,7 @@ public void setRequiredDt(OffsetDateTime requiredDt) {
this.requiredDt = requiredDt;
}

public Foo number(BigDecimal number) {
public Foo number(@Nullable BigDecimal number) {
this.number = number;
return this;
}
Expand Down