victools / jsonschema-generator

Java JSON Schema Generator – creating JSON Schema (Draft 6, Draft 7, Draft 2019-09, or Draft 2020-12) from Java classes
https://victools.github.io/jsonschema-generator
Apache License 2.0
398 stars 58 forks source link

java.lang.NullPointerException: Cannot invoke "com.fasterxml.classmate.ResolvedType.getErasedType()" because "type" is null #473

Closed jochenberger closed 1 month ago

jochenberger commented 1 month ago

I'm still trying to gather more info, but I can already provide a stacktrace. I'm working with @JsonUnwrapped on a delegate object. The Lombok-generated setter for that object seems to cause the issue.


Caused by: java.lang.NullPointerException: Cannot invoke "com.fasterxml.classmate.ResolvedType.getErasedType()" because "type" is null
    at com.github.victools.jsonschema.generator.TypeContext.lambda$getTypeWithAnnotation$2(TypeContext.java:381)
    at com.github.victools.jsonschema.generator.TypeContext.getTypeConsideringHierarchyMatching(TypeContext.java:396)
    at com.github.victools.jsonschema.generator.TypeContext.getTypeWithAnnotation(TypeContext.java:380)
    at com.github.victools.jsonschema.generator.TypeContext.getTypeWithAnnotation(TypeContext.java:363)
    at com.github.victools.jsonschema.module.jackson.JsonSubTypesResolver.provideCustomSchemaDefinition(JsonSubTypesResolver.java:169)
    at com.github.victools.jsonschema.generator.impl.SchemaGeneratorConfigImpl.lambda$getCustomDefinition$1(SchemaGeneratorConfigImpl.java:284)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1685)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
    at com.github.victools.jsonschema.generator.impl.SchemaGeneratorConfigImpl.getCustomDefinition(SchemaGeneratorConfigImpl.java:286)
    at com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl.traverseGenericType(SchemaGenerationContextImpl.java:298)
    at com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl.createStandardDefinition(SchemaGenerationContextImpl.java:235)
    at com.github.victools.jsonschema.module.jackson.JsonUnwrappedDefinitionProvider.createUnwrappedMemberSchema(JsonUnwrappedDefinitionProvider.java:90)
    at com.github.victools.jsonschema.module.jackson.JsonUnwrappedDefinitionProvider.lambda$provideCustomSchemaDefinition$1(JsonUnwrappedDefinitionProvider.java:61)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:1024)
    at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEachOrdered(ReferencePipeline.java:601)
    at com.github.victools.jsonschema.module.jackson.JsonUnwrappedDefinitionProvider.provideCustomSchemaDefinition(JsonUnwrappedDefinitionProvider.java:62)
    at com.github.victools.jsonschema.generator.impl.SchemaGeneratorConfigImpl.lambda$getCustomDefinition$1(SchemaGeneratorConfigImpl.java:284)
    at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
    at java.base/java.util.ArrayList$ArrayListSpliterator.tryAdvance(ArrayList.java:1685)
    at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
    at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
    at com.github.victools.jsonschema.generator.impl.SchemaGeneratorConfigImpl.getCustomDefinition(SchemaGeneratorConfigImpl.java:286)
    at com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl.traverseGenericType(SchemaGenerationContextImpl.java:298)
    at com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl.traverseGenericType(SchemaGenerationContextImpl.java:280)
    at com.github.victools.jsonschema.generator.impl.SchemaGenerationContextImpl.parseType(SchemaGenerationContextImpl.java:94)
    at com.github.victools.jsonschema.generator.SchemaBuilder.createSchemaForSingleType(SchemaBuilder.java:110)
    at com.github.victools.jsonschema.generator.SchemaBuilder.createSingleTypeSchema(SchemaBuilder.java:57)
    at com.github.victools.jsonschema.generator.SchemaGenerator.generateSchema(SchemaGenerator.java:60)
jochenberger commented 1 month ago

If there is no setter (e.g. if the field is made final), the problem does not arise.

CarstenWickner commented 1 month ago

This bug was introduced in 4.35.0: since then, even for void methods it is possible to provide custom definitions. The JacksonModule didn't take that into account and therefore can run into this error.

Thanks for raising this. I'll fix it soon. For the time being, perhaps downgrade to version 4.34.0 temporarily.