Skip to content

Commit 1b4b790

Browse files
committed
prevent NPE
1 parent a38fd1b commit 1b4b790

47 files changed

Lines changed: 96 additions & 96 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/JavaSpring/pojo.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
161161

162162
public {{classname}} add{{nameInPascalCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
163163
{{#openApiNullable}}
164-
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
164+
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) {
165165
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}ArrayList{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}};
166166
}
167167
this.{{name}}{{#isNullable}}.get(){{/isNullable}}.add({{name}}Item);
@@ -179,7 +179,7 @@ public {{>sealed}}class {{classname}}{{#parent}} extends {{{parent}}}{{/parent}}
179179

180180
public {{classname}} put{{nameInPascalCase}}Item(String key, {{{items.datatypeWithEnum}}} {{name}}Item) {
181181
{{#openApiNullable}}
182-
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent(){{/isNullable}}) {
182+
if (this.{{name}} == null{{#isNullable}} || !this.{{name}}.isPresent() || this.{{name}}.get() == null{{/isNullable}}) {
183183
this.{{name}} = {{#isNullable}}JsonNullable.of({{/isNullable}}{{{defaultValue}}}{{^defaultValue}}new {{#uniqueItems}}LinkedHashSet{{/uniqueItems}}{{^uniqueItems}}HashMap{{/uniqueItems}}<>(){{/defaultValue}}{{#isNullable}}){{/isNullable}};
184184
}
185185
this.{{name}}{{#isNullable}}.get(){{/isNullable}}.put(key, {{name}}Item);

samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ContainerDefaultValueDto nullableArray(List<String> nullableArray) {
4646
}
4747

4848
public ContainerDefaultValueDto addNullableArrayItem(String nullableArrayItem) {
49-
if (this.nullableArray == null || !this.nullableArray.isPresent()) {
49+
if (this.nullableArray == null || !this.nullableArray.isPresent() || this.nullableArray.get() == null) {
5050
this.nullableArray = JsonNullable.of(new ArrayList<>());
5151
}
5252
this.nullableArray.get().add(nullableArrayItem);
@@ -73,7 +73,7 @@ public ContainerDefaultValueDto nullableRequiredArray(List<String> nullableRequi
7373
}
7474

7575
public ContainerDefaultValueDto addNullableRequiredArrayItem(String nullableRequiredArrayItem) {
76-
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent()) {
76+
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent() || this.nullableRequiredArray.get() == null) {
7777
this.nullableRequiredArray = JsonNullable.of(new ArrayList<>());
7878
}
7979
this.nullableRequiredArray.get().add(nullableRequiredArrayItem);
@@ -129,7 +129,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List<String> nullableAr
129129
}
130130

131131
public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) {
132-
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent()) {
132+
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) {
133133
this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar")));
134134
}
135135
this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem);

samples/client/petstore/spring-http-interface-bean-validation/src/main/java/org/openapitools/model/NullableMapPropertyDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public NullableMapPropertyDto languageValues(Map<String, String> languageValues)
3636
}
3737

3838
public NullableMapPropertyDto putLanguageValuesItem(String key, String languageValuesItem) {
39-
if (this.languageValues == null || !this.languageValues.isPresent()) {
39+
if (this.languageValues == null || !this.languageValues.isPresent() || this.languageValues.get() == null) {
4040
this.languageValues = JsonNullable.of(new HashMap<>());
4141
}
4242
this.languageValues.get().put(key, languageValuesItem);

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValueDto.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ContainerDefaultValueDto nullableArray(List<String> nullableArray) {
4545
}
4646

4747
public ContainerDefaultValueDto addNullableArrayItem(String nullableArrayItem) {
48-
if (this.nullableArray == null || !this.nullableArray.isPresent()) {
48+
if (this.nullableArray == null || !this.nullableArray.isPresent() || this.nullableArray.get() == null) {
4949
this.nullableArray = JsonNullable.of(new ArrayList<>());
5050
}
5151
this.nullableArray.get().add(nullableArrayItem);
@@ -72,7 +72,7 @@ public ContainerDefaultValueDto nullableRequiredArray(List<String> nullableRequi
7272
}
7373

7474
public ContainerDefaultValueDto addNullableRequiredArrayItem(String nullableRequiredArrayItem) {
75-
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent()) {
75+
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent() || this.nullableRequiredArray.get() == null) {
7676
this.nullableRequiredArray = JsonNullable.of(new ArrayList<>());
7777
}
7878
this.nullableRequiredArray.get().add(nullableRequiredArrayItem);
@@ -128,7 +128,7 @@ public ContainerDefaultValueDto nullableArrayWithDefault(List<String> nullableAr
128128
}
129129

130130
public ContainerDefaultValueDto addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) {
131-
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent()) {
131+
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) {
132132
this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar")));
133133
}
134134
this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem);

samples/client/petstore/spring-http-interface-noResponseEntity/src/main/java/org/openapitools/model/NullableMapPropertyDto.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public NullableMapPropertyDto languageValues(Map<String, String> languageValues)
3535
}
3636

3737
public NullableMapPropertyDto putLanguageValuesItem(String key, String languageValuesItem) {
38-
if (this.languageValues == null || !this.languageValues.isPresent()) {
38+
if (this.languageValues == null || !this.languageValues.isPresent() || this.languageValues.get() == null) {
3939
this.languageValues = JsonNullable.of(new HashMap<>());
4040
}
4141
this.languageValues.get().put(key, languageValuesItem);

samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/ContainerDefaultValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public ContainerDefaultValue nullableArray(List<String> nullableArray) {
5252
}
5353

5454
public ContainerDefaultValue addNullableArrayItem(String nullableArrayItem) {
55-
if (this.nullableArray == null || !this.nullableArray.isPresent()) {
55+
if (this.nullableArray == null || !this.nullableArray.isPresent() || this.nullableArray.get() == null) {
5656
this.nullableArray = JsonNullable.of(new ArrayList<>());
5757
}
5858
this.nullableArray.get().add(nullableArrayItem);
@@ -79,7 +79,7 @@ public ContainerDefaultValue nullableRequiredArray(List<String> nullableRequired
7979
}
8080

8181
public ContainerDefaultValue addNullableRequiredArrayItem(String nullableRequiredArrayItem) {
82-
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent()) {
82+
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent() || this.nullableRequiredArray.get() == null) {
8383
this.nullableRequiredArray = JsonNullable.of(new ArrayList<>());
8484
}
8585
this.nullableRequiredArray.get().add(nullableRequiredArrayItem);
@@ -135,7 +135,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List<String> nullableArray
135135
}
136136

137137
public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) {
138-
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent()) {
138+
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) {
139139
this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar")));
140140
}
141141
this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem);

samples/client/petstore/spring-http-interface-reactive-bean-validation/src/main/java/org/openapitools/model/NullableMapProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public NullableMapProperty languageValues(Map<String, String> languageValues) {
3434
}
3535

3636
public NullableMapProperty putLanguageValuesItem(String key, String languageValuesItem) {
37-
if (this.languageValues == null || !this.languageValues.isPresent()) {
37+
if (this.languageValues == null || !this.languageValues.isPresent() || this.languageValues.get() == null) {
3838
this.languageValues = JsonNullable.of(new HashMap<>());
3939
}
4040
this.languageValues.get().put(key, languageValuesItem);

samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/ContainerDefaultValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ContainerDefaultValue nullableArray(List<String> nullableArray) {
5151
}
5252

5353
public ContainerDefaultValue addNullableArrayItem(String nullableArrayItem) {
54-
if (this.nullableArray == null || !this.nullableArray.isPresent()) {
54+
if (this.nullableArray == null || !this.nullableArray.isPresent() || this.nullableArray.get() == null) {
5555
this.nullableArray = JsonNullable.of(new ArrayList<>());
5656
}
5757
this.nullableArray.get().add(nullableArrayItem);
@@ -78,7 +78,7 @@ public ContainerDefaultValue nullableRequiredArray(List<String> nullableRequired
7878
}
7979

8080
public ContainerDefaultValue addNullableRequiredArrayItem(String nullableRequiredArrayItem) {
81-
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent()) {
81+
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent() || this.nullableRequiredArray.get() == null) {
8282
this.nullableRequiredArray = JsonNullable.of(new ArrayList<>());
8383
}
8484
this.nullableRequiredArray.get().add(nullableRequiredArrayItem);
@@ -134,7 +134,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List<String> nullableArray
134134
}
135135

136136
public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) {
137-
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent()) {
137+
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) {
138138
this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar")));
139139
}
140140
this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem);

samples/client/petstore/spring-http-interface-reactive-noResponseEntity/src/main/java/org/openapitools/model/NullableMapProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public NullableMapProperty languageValues(Map<String, String> languageValues) {
3333
}
3434

3535
public NullableMapProperty putLanguageValuesItem(String key, String languageValuesItem) {
36-
if (this.languageValues == null || !this.languageValues.isPresent()) {
36+
if (this.languageValues == null || !this.languageValues.isPresent() || this.languageValues.get() == null) {
3737
this.languageValues = JsonNullable.of(new HashMap<>());
3838
}
3939
this.languageValues.get().put(key, languageValuesItem);

samples/client/petstore/spring-http-interface-reactive/src/main/java/org/openapitools/model/ContainerDefaultValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public ContainerDefaultValue nullableArray(List<String> nullableArray) {
5151
}
5252

5353
public ContainerDefaultValue addNullableArrayItem(String nullableArrayItem) {
54-
if (this.nullableArray == null || !this.nullableArray.isPresent()) {
54+
if (this.nullableArray == null || !this.nullableArray.isPresent() || this.nullableArray.get() == null) {
5555
this.nullableArray = JsonNullable.of(new ArrayList<>());
5656
}
5757
this.nullableArray.get().add(nullableArrayItem);
@@ -78,7 +78,7 @@ public ContainerDefaultValue nullableRequiredArray(List<String> nullableRequired
7878
}
7979

8080
public ContainerDefaultValue addNullableRequiredArrayItem(String nullableRequiredArrayItem) {
81-
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent()) {
81+
if (this.nullableRequiredArray == null || !this.nullableRequiredArray.isPresent() || this.nullableRequiredArray.get() == null) {
8282
this.nullableRequiredArray = JsonNullable.of(new ArrayList<>());
8383
}
8484
this.nullableRequiredArray.get().add(nullableRequiredArrayItem);
@@ -134,7 +134,7 @@ public ContainerDefaultValue nullableArrayWithDefault(List<String> nullableArray
134134
}
135135

136136
public ContainerDefaultValue addNullableArrayWithDefaultItem(String nullableArrayWithDefaultItem) {
137-
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent()) {
137+
if (this.nullableArrayWithDefault == null || !this.nullableArrayWithDefault.isPresent() || this.nullableArrayWithDefault.get() == null) {
138138
this.nullableArrayWithDefault = JsonNullable.of(new ArrayList<>(Arrays.asList("foo", "bar")));
139139
}
140140
this.nullableArrayWithDefault.get().add(nullableArrayWithDefaultItem);

0 commit comments

Comments
 (0)