fix(avro-schema): fix NPE for null enum values (#19771)

This commit is contained in:
Joscha Feth 2024-10-04 05:56:11 +01:00 committed by GitHub
parent 817da39124
commit cfe6520283
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 45 additions and 4 deletions

View File

@ -6648,7 +6648,7 @@ public class DefaultCodegen implements CodegenConfig {
for (Object value : values) {
if (value == null) {
// raw null values in enums are unions for nullable
// atttributes, not actual enum values, so we remove them here
// attributes, not actual enum values, so we remove them here
continue;
}
Map<String, Object> enumVar = new HashMap<>();

View File

@ -199,7 +199,10 @@ public class AvroSchemaCodegen extends DefaultCodegen implements CodegenConfig {
@Override
protected List<Map<String, Object>> buildEnumVars(List<Object> values, String dataType) {
List<Object> sanitizedValues = values.stream().map(Object::toString).map(this::sanitizeEnumValue)
List<Object> sanitizedValues = values.stream()
.filter(x -> x != null)
.map(Object::toString)
.map(this::sanitizeEnumValue)
.collect(Collectors.toList());
removeEnumValueCollisions(sanitizedValues);
return super.buildEnumVars(sanitizedValues, dataType);

View File

@ -28,3 +28,15 @@ components:
- 'coll-ision'
- 'coll_ision'
type: 'string'
another:
enum:
- 'x'
- 'y'
- null
type: 'string'
equivalent:
enum:
- 'x'
- 'y'
type: 'string'
nullable: true

View File

@ -20,6 +20,32 @@
}],
"doc": "",
"default": null
},
{
"name": "another",
"type": ["null", {
"type": "enum",
"name": "Sample_another",
"symbols": [
"x",
"y"
]
}],
"doc": "",
"default": null
},
{
"name": "equivalent",
"type": ["null", {
"type": "enum",
"name": "Sample_equivalent",
"symbols": [
"x",
"y"
]
}],
"doc": "",
"default": null
}
]