You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
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
Version:
2.9.9
When I create an
ArrayNode
and use
ArrayNode#addAll
to add elements containing a raw
null
element as follows:
final List<ObjectNode> nodes = Arrays.asList(null, JsonNodeFactory.instance.objectNode());
final ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
arrayNode.addAll(nodes);
Calling
ArrayNode#deepCopy
and
ArrayNode#toString
on such
arrayNode
will throw
NullPointerException
s.
However, if we add the nodes using
ArrayNode#add
as follows:
final ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
arrayNode.add((JsonNode) null);
arrayNode.add(JsonNodeFactory.instance.objectNode());
Calling
ArrayNode#deepCopy
and
ArrayNode#toString
on such
arrayNode
will
NOT
throw any
NullPointerException
s.
This is because
ArrayNode#add
converts any raw
null
to a
NullNode
object:
jackson-databind/src/main/java/com/fasterxml/jackson/databind/node/ArrayNode.java
Lines 306 to 313
f75b304
438: Reference resolution of Product references (and set of) as an attribute of nested type
commercetools/commercetools-sync-java#439
First of all: thank you for reporting the issue! Yes, that looks like a problem, although surprisingly one that has not been reported before. I agree that raw
null
is not to be added; and to me it seems there are 2 possibilities: either automatically "upgrade"
null
as is done in a few other places, or throw an exception to indicate invalid value.
It seems reasonable to expect former, so that
null
s would be automatically coerced, given that this happens elsewhere.
I'll think about this bit more, and will get fixed for
2.10
to be included in 2.10.0.
Hi
@cowtowncoder
, thanks for the quick reply. I also agree with you about the former being the more suitable solution to be consistent with the rest of the methods.
I attempted to provide a fix for it here:
#2443
changed the title
ArrayNode#addAll adds raw null values which cause NullPointerException on ArrayNode#deepCopy and ArrayNode#toString
ArrayNode.addAll()
adds raw
null
values which cause NPE on
deepCopy()
and
toString()
Sep 6, 2019