Skip to content

2.15.0 throws NPE when deserializing a polymorphic with unknown properties #3908

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
mishako opened this issue May 3, 2023 · 1 comment
Closed

Comments

@mishako
Copy link

mishako commented May 3, 2023

Describe the bug

This line throws NullPointerException:

https://github.com/FasterXML/jackson-databind/blob/2.15/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java#L1749

if (unknownTokens != null) {
  // need to add END_OBJECT marker first
  unknownTokens.writeEndObject();
  JsonParser p2 = unknownTokens.asParser(p.streamReadConstraints()); <-- !!! HERE !!!
  p2.nextToken(); // to get to first data field
  bean = subDeser.deserialize(p2, ctxt, bean);
}
Exception in thread "main" 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)
  at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1409)
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:352)
  at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:185)
  at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323)
  at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4825)
  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3772)
  at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3740)

Version information
Which Jackson version(s) was this for? 2.15.0

To Reproduce

Here's a minimal code to reproduce. Note the intentional mismatch between the supplied and expected field names (one and two).

public class Main {

  public static void main(String[] args) throws Exception {
    new ObjectMapper().readValue("{\"one\":1}", Parent.class);
  }

  public abstract static class Parent {
    @JsonCreator
    public static Parent create(@JsonProperty("two") String two) {
      return new Child();
    }
  }

  public static class Child extends Parent {}
}

Additional context

A more real-world example would be an AutoValue class. It would trigger the exception similarly to the example above.

The bug seems to have been introduced by #3691 in 2.15.0

@mishako mishako added the to-evaluate Issue that has been received but not yet evaluated label May 3, 2023
@mishako mishako changed the title NullPointerException when deserializing a polymorphic with unknown properties 2.15.0 throws NPE when deserializing a polymorphic with unknown properties May 3, 2023
@cowtowncoder
Copy link
Member

I think this is the same as one transferred as #3913, closing as dup (even if earlier)

@cowtowncoder cowtowncoder removed the to-evaluate Issue that has been received but not yet evaluated label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants