NPE with `CollectionDeserializer` with `TreeSet` class, with input `null`
See original GitHub issueHello,
I’ve a problem while trying deserialize a TreeSet with a custom deserializer, in my situation deserializer not find the registry to add the collection, and returns null, but as TreeSet does not accept nulls, pops exception in Java, as below:
com.fasterxml.jackson.databind.JsonMappingException: (was java.lang.NullPointerException) (through reference chain: com.framework.entity.dynamic.DocumentEntityInfo["folders"]->java.util.TreeSet[0])
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:378)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:350)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:298)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:249)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:26)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:490)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:95)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:260)
at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:163)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:135)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer._deserializeTypedForId(AsPropertyTypeDeserializer.java:120)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromObject(AsPropertyTypeDeserializer.java:91)
at com.fasterxml.jackson.databind.jsontype.impl.AsPropertyTypeDeserializer.deserializeTypedFromAny(AsPropertyTypeDeserializer.java:163)
at com.fasterxml.jackson.databind.deser.impl.TypeWrappedDeserializer.deserialize(TypeWrappedDeserializer.java:42)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3807)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2797)
Caused by: java.lang.NullPointerException
at java.util.TreeMap.compare(TreeMap.java:1290)
at java.util.TreeMap.put(TreeMap.java:538)
at java.util.TreeSet.add(TreeSet.java:255)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:284)
The suggestion is to treat null for this situation in the Collection Deserializer, and not add the item in the list in return. Line 284 of CollectionDeserializer class.
I’ve searched for an issue linked to that, without success in the issue tracker.
Thanks for your help.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
At first I insert null in TreeSet. After that I insert any other value ...
When you try to add null on empty TreeSet initially it does not contain any element to compare hence its add without NPE,...
Read more >TreeSet in Java - GeeksforGeeks
For an empty tree-set, when trying to insert null as the first value, one will get NPE from JDK 7. From JDK 7...
Read more >TreeSet (Java Platform SE 7 ) - Oracle Help Center
A NavigableSet implementation based on a TreeMap . The elements are ordered using their natural ordering, or by a Comparator provided at set...
Read more >TreeSet in Java - javatpoint
Hierarchy of TreeSet class, example of java tree set class. ... Java TreeSet class doesn't allow null elements. Java TreeSet class is non-synchronized....
Read more >Can TreeSet have null values in Java? - Quora
TreeSet elements are keys in a TreeMap and it cannot have null as a key! ... So TreeSet 's add() throws NullPointerException if...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Actually while I do not like one-off feature for null handling for just collections, I think it would be valid to block
null
fromTreeSet
, given that it can not work with JDK.Actually closing as it should be handled via #1402, and I have no plans for type-specific hack.