Skip to content

Regression 2.15.0: NullPointer exception parsing file with @JsonCreator and ignore unknown properties #3936

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

Closed
dhs3000 opened this issue May 16, 2023 · 1 comment
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@dhs3000
Copy link

dhs3000 commented May 16, 2023

Describe the bug
A NullPointerException occurs parsing a (YAML) file to a Kotlin class. The object is created using a @JsonCreator that does not use all properties in the file.

Version information
2.15.0

To Reproduce
Have a data class SomeTaskListClass with a property that is a list of another class Task. The Task class has a @JsonCreator annotated static method to create it. It does not need/mention all properties of the file. The parser is configured to ignore those fields.

Parsing results in this error

com.fasterxml.jackson.databind.JsonMappingException: Cannot invoke "com.fasterxml.jackson.core.JsonParser.streamReadConstraints()" because "p" is null (through reference chain: SomeTaskListClass["tasks"]->java.util.ArrayList[0])
(...)
Caused by: java.lang.NullPointerException: Cannot invoke "com.fasterxml.jackson.core.JsonParser.streamReadConstraints()" because "p" is null
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.handlePolymorphic(BeanDeserializerBase.java:1749)
	at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeUsingPropertyBased(BeanDeserializer.java:541)	

The line casing the error in handlePolymorphic is

JsonParser p2 = unknownTokens.asParser(p.streamReadConstraints());

a few lines later is a null check for p.
Looking at the call-site in _deserializeUsingPropertyBased, that NPE makes sense

return handlePolymorphic(null, ctxt, bean, unknown); // <-- passing null for `p`

Expected behavior
Parsing works without error.

@dhs3000 dhs3000 added the to-evaluate Issue that has been received but not yet evaluated label May 16, 2023
@pjfanning
Copy link
Member

duplicate of #3913

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

2 participants