Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

NPE in ExampleJsonGenerator #314

Closed
hirth-abi opened this issue Jul 31, 2023 · 2 comments
Closed

NPE in ExampleJsonGenerator #314

hirth-abi opened this issue Jul 31, 2023 · 2 comments
Labels
bug Something isn't working core Involves springwolf-core staged for release

Comments

@hirth-abi
Copy link

Describe the bug

The ExampleJsonGenerator for objects always expects that the schema has non-null properties. This if often not the case, for example if a schema refers to another one, only the name and the $ref properties are set, all others, especially properties are null.

Dependencies and versions used

Springwolf 0.13.0

Code example

Stack trace and error logs

Caused by: java.lang.RuntimeException: Error occured during creation of AsyncAPI
	at io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiService.getAsyncAPI(DefaultAsyncApiService.java:45)
	at io.github.stavshamir.springwolf.asyncapi.SpringwolfInitApplicationListener.afterPropertiesSet(SpringwolfInitApplicationListener.java:39)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1817)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766)
	... 16 common frames omitted
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.Map.entrySet()" because "properties" is null
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleObject(ExampleJsonGenerator.java:134)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:69)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleArraySchema(ExampleJsonGenerator.java:92)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:65)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.lambda$handleObject$0(ExampleJsonGenerator.java:140)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	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.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleObject(ExampleJsonGenerator.java:144)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:69)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:61)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.lambda$handleObject$0(ExampleJsonGenerator.java:140)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	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.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleObject(ExampleJsonGenerator.java:144)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:69)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:61)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.lambda$handleObject$0(ExampleJsonGenerator.java:140)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	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.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.handleObject(ExampleJsonGenerator.java:144)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.buildSchema(ExampleJsonGenerator.java:69)
	at io.github.stavshamir.springwolf.schemas.example.ExampleJsonGenerator.fromSchema(ExampleJsonGenerator.java:39)
	at io.github.stavshamir.springwolf.schemas.DefaultSchemasService.generateExampleWhenMissing(DefaultSchemasService.java:89)
	at java.base/java.util.HashMap.forEach(HashMap.java:1421)
	at io.github.stavshamir.springwolf.schemas.DefaultSchemasService.finalizeDefinitions(DefaultSchemasService.java:45)
	at io.github.stavshamir.springwolf.schemas.DefaultSchemasService.getDefinitions(DefaultSchemasService.java:39)
	at io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiService.initAsyncAPI(DefaultAsyncApiService.java:71)
	at io.github.stavshamir.springwolf.asyncapi.DefaultAsyncApiService.getAsyncAPI(DefaultAsyncApiService.java:39)
	... 19 common frames omitted
@hirth-abi hirth-abi added the bug Something isn't working label Jul 31, 2023
@timonback
Copy link
Member

Hi @hirth-abi,

Thank you for the bug report and technical details.

I addressed the NPE in #316 and also added a more complex example to close the test gap.

Based on this report as well as #315, I suspect there are more cases. Are you able to replicate/contribute a test case or provide your DTO structure? Based on the stacktrace, I am only able to see that there is an object -> object -> object -> array -> object relationship. Class and property names do not matter, feel free to have a look at the PR.
I am also happy to help and make the test green, but can only assume the class structure at this point.

@timonback
Copy link
Member

Thank your for the report, the issue has been addressed in the new release.

Feel free to reopen this issue if there is still something missing.

Also, please participate in #342 if you can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working core Involves springwolf-core staged for release
Projects
None yet
Development

No branches or pull requests

2 participants