Skip to content

Commit

Permalink
Fix #4381: add null checks for BigIntegerNode, BinaryNode, DecimalN…
Browse files Browse the repository at this point in the history
…ode, TextNode constructors
  • Loading branch information
cowtowncoder committed Mar 2, 2024
1 parent c7016e7 commit b52dd89
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Versions: 3.x (for earlier see VERSION-2.x)
#3542: Rename "com.fasterxml.jackson" -> "tools.jackson"
#3601: Change `Optional` deserialization from "absent" value into `null`, from "empty"
$4160: Deprecate `DefaultTyping.EVERYTHING` in `2.x` and remove in `3.0`
#4381: Prevent construction of `null`-valued `JsonNode`s (like `TextNode`)
- Remove `MappingJsonFactory`
- Add context parameter for `TypeSerializer` contextualization (`forProperty()`)
- Default for `JsonNodeFeature.STRIP_TRAILING_BIGDECIMAL_ZEROES` changed to `false` for 3.0
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public class BigIntegerNode
/**********************************************************
*/

public BigIntegerNode(BigInteger v) { _value = v; }
public BigIntegerNode(BigInteger v) {
// 01-Mar-2024, tatu: [databind#4381] No null-valued JsonNodes
_value = Objects.requireNonNull(v);
}

public static BigIntegerNode valueOf(BigInteger v) { return new BigIntegerNode(v); }

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/tools/jackson/databind/node/BinaryNode.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tools.jackson.databind.node;

import java.util.Arrays;
import java.util.Objects;

import tools.jackson.core.*;
import tools.jackson.databind.SerializerProvider;
Expand All @@ -20,7 +21,8 @@ public class BinaryNode

public BinaryNode(byte[] data)
{
_data = data;
// 01-Mar-2024, tatu: [databind#4381] No null-valued JsonNodes
_data = Objects.requireNonNull(data);
}

public BinaryNode(byte[] data, int offset, int length)
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/tools/jackson/databind/node/DecimalNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Objects;

import tools.jackson.core.*;
import tools.jackson.databind.*;
Expand Down Expand Up @@ -30,7 +31,10 @@ public class DecimalNode
/**********************************************************************
*/

public DecimalNode(BigDecimal v) { _value = v; }
public DecimalNode(BigDecimal v) {
// 01-Mar-2024, tatu: [databind#4381] No null-valued JsonNodes
_value = Objects.requireNonNull(v);
}

public static DecimalNode valueOf(BigDecimal d) { return new DecimalNode(d); }

Expand Down
5 changes: 1 addition & 4 deletions src/main/java/tools/jackson/databind/node/POJONode.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public byte[] binaryValue()
@Override
public boolean asBoolean(boolean defaultValue)
{
if (_value != null && _value instanceof Boolean) {
if (_value instanceof Boolean) {
return ((Boolean) _value).booleanValue();
}
return defaultValue;
Expand Down Expand Up @@ -147,9 +147,6 @@ public boolean equals(Object o)
return false;
}

/**
* @since 2.3
*/
protected boolean _pojoEquals(POJONode other)
{
if (_value == null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/tools/jackson/databind/node/TextNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class TextNode
protected final String _value;

public TextNode(String v) {
_value = v;
// 01-Mar-2024, tatu: [databind#4381] No null-valued TextNodes
_value = Objects.requireNonNull(v);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions src/test/java/tools/jackson/databind/node/TextNodeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ public void testText()

public void testEquals()
{
assertEquals(new TextNode(null), new TextNode(null));
assertEquals(new TextNode("abc"), new TextNode("abc"));
assertNotEquals(new TextNode(null), new TextNode("def"));
assertNotEquals(new TextNode("abc"), new TextNode("def"));
assertNotEquals(new TextNode("abc"), new TextNode(null));
}

public void testHashCode()
Expand Down

0 comments on commit b52dd89

Please sign in to comment.