Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

joscha
Copy link
Contributor

@joscha joscha commented Oct 3, 2024

Fixes:

Download 7.9.0-20241003.092246-97 ...
Downloaded 7.9.0-20241003.092246-97
[[avro-schema] spec.json] [main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[[avro-schema] spec.json] [main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: avro-schema (schema)
[[avro-schema] spec.json] [main] INFO  o.o.codegen.DefaultGenerator - Generator 'avro-schema' is considered beta.
[[avro-schema] spec.json] Exception in thread "main" java.lang.RuntimeException: Could not process model 'Field'.Please make sure that your schema is correct!
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:528)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1303)
[[avro-schema] spec.json] 	at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
[[avro-schema] spec.json] 	at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
[[avro-schema] spec.json] 	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
[[avro-schema] spec.json] Caused by: java.lang.NullPointerException
[[avro-schema] spec.json] 	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
[[avro-schema] spec.json] 	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1708)
[[avro-schema] spec.json] 	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
[[avro-schema] spec.json] 	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
[[avro-schema] spec.json] 	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
[[avro-schema] spec.json] 	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
[[avro-schema] spec.json] 	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
[[avro-schema] spec.json] 	at org.openapitools.codegen.languages.AvroSchemaCodegen.buildEnumVars(AvroSchemaCodegen.java:203)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultCodegen.updateCodegenPropertyEnum(DefaultCodegen.java:6604)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum(DefaultCodegen.java:792)
[[avro-schema] spec.json] 	at org.openapitools.codegen.languages.AvroSchemaCodegen.postProcessModels(AvroSchemaCodegen.java:177)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1791)
[[avro-schema] spec.json] 	at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:523)
[[avro-schema] spec.json] 	... 5 more

bug was introduced in #19549

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

List<Object> sanitizedValues = values.stream().map(Object::toString).map(this::sanitizeEnumValue)
.collect(Collectors.toList());
List<Object> sanitizedValues = values.stream()
.filter(x -> x != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the meaningful change of this PR

@wing328 wing328 merged commit cfe6520 into OpenAPITools:master Oct 4, 2024
15 checks passed
@wing328 wing328 added Issue: Bug Schema: Avro Generation of Avro schemas labels Oct 4, 2024
@wing328 wing328 added this to the 7.9.0 milestone Oct 4, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Issue: Bug Schema: Avro Generation of Avro schemas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants