Skip to content

Commit 4fc5def

Browse files
committed
Merge branch '2.15' into 2.16
2 parents ccabd8e + 901ba02 commit 4fc5def

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

release-notes/VERSION-2.x

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ Project: jackson-databind
150150
#4303: `ObjectReader` is not serializable if it's configured for polymorphism
151151
(reported by @asardaes)
152152
(fix contributed by Joo-Hyuk K)
153+
#4378: `TextNode.equals()` throws `NullPointerException` when `TextNode`
154+
constructed with `null`
155+
(reported by @Javed6234)
156+
(fix contributed by @pjfanning)
153157
154158
2.15.3 (12-Oct-2023)
155159

src/main/java/com/fasterxml/jackson/databind/node/TextNode.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.fasterxml.jackson.databind.node;
22

33
import java.io.IOException;
4+
import java.util.Objects;
45

56
import com.fasterxml.jackson.core.*;
67
import com.fasterxml.jackson.core.io.CharTypes;
@@ -164,13 +165,16 @@ public boolean equals(Object o)
164165
if (o == this) return true;
165166
if (o == null) return false;
166167
if (o instanceof TextNode) {
167-
return ((TextNode) o)._value.equals(_value);
168+
TextNode otherNode = (TextNode) o;
169+
return Objects.equals(otherNode._value, _value);
168170
}
169171
return false;
170172
}
171173

172174
@Override
173-
public int hashCode() { return _value.hashCode(); }
175+
public int hashCode() {
176+
return Objects.hashCode(_value);
177+
}
174178

175179
@Deprecated // since 2.10
176180
protected static void appendQuoted(StringBuilder sb, String content)

src/test/java/com/fasterxml/jackson/databind/node/TextNodeTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.fasterxml.jackson.databind.node;
22

3+
import static org.junit.Assert.assertNotEquals;
4+
35
public class TextNodeTest extends NodeTestBase
46
{
57
public void testText()
@@ -36,4 +38,19 @@ public void testText()
3638
assertFalse(TextNode.valueOf("false").asBoolean(true));
3739
assertFalse(TextNode.valueOf("false").asBoolean(false));
3840
}
41+
42+
public void testEquals()
43+
{
44+
assertEquals(new TextNode(null), new TextNode(null));
45+
assertEquals(new TextNode("abc"), new TextNode("abc"));
46+
assertNotEquals(new TextNode(null), new TextNode("def"));
47+
assertNotEquals(new TextNode("abc"), new TextNode("def"));
48+
assertNotEquals(new TextNode("abc"), new TextNode(null));
49+
}
50+
51+
public void testHashCode()
52+
{
53+
assertEquals(0, new TextNode(null).hashCode());
54+
assertEquals("abc".hashCode(), new TextNode("abc").hashCode());
55+
}
3956
}

0 commit comments

Comments
 (0)