Skip to content

Commit 474fdb6

Browse files
committed
Keep exsiting behavior when using objectMapper.readTree() with empty values
FasterXML/jackson-databind#2211 - In Jackson <2.9.0 an IOException was raised - In Jackson >=2.9.0, null is returned
1 parent 8e9eeef commit 474fdb6

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

graylog2-server/src/main/java/org/graylog/plugins/beats/Beats2Codec.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,14 @@ public Message decode(@Nonnull RawMessage rawMessage) {
7070
final JsonNode event;
7171
try {
7272
event = objectMapper.readTree(payload);
73+
if (event == null) {
74+
throw new IOException("null result");
75+
}
7376
} catch (IOException e) {
7477
LOG.error("Couldn't decode raw message {}", rawMessage);
7578
return null;
7679
}
7780

78-
// Adhere to the legacy behaviour
79-
if (event == null) {
80-
return null;
81-
}
82-
8381
return parseEvent(event);
8482
}
8583

graylog2-server/src/main/java/org/graylog/plugins/pipelineprocessor/functions/json/JsonParse.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public JsonParse(ObjectMapper objectMapper) {
5050
public JsonNode evaluate(FunctionArgs args, EvaluationContext context) {
5151
final String value = valueParam.required(args, context);
5252
try {
53-
return objectMapper.readTree(value);
53+
final JsonNode node = objectMapper.readTree(value);
54+
if (node == null) {
55+
throw new IOException("null result");
56+
}
57+
return node;
5458
} catch (IOException e) {
5559
log.warn("Unable to parse JSON", e);
5660
}

graylog2-server/src/main/java/org/graylog2/inputs/codecs/GelfCodec.java

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import javax.annotation.Nonnull;
4646
import javax.annotation.Nullable;
4747
import javax.inject.Inject;
48+
import java.io.IOException;
4849
import java.util.Iterator;
4950
import java.util.Map;
5051

@@ -127,6 +128,9 @@ public Message decode(@Nonnull final RawMessage rawMessage) {
127128

128129
try {
129130
node = objectMapper.readTree(json);
131+
if (node == null) {
132+
throw new IOException("null result");
133+
}
130134
} catch (final Exception e) {
131135
log.error("Could not parse JSON, first 400 characters: " +
132136
StringUtils.abbreviate(json, 403), e);

graylog2-server/src/main/java/org/graylog2/plugin/Tools.java

+3
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,9 @@ public static Optional<AbsoluteRange> extractHistogramBoundaries(final String qu
644644
try {
645645
final JsonParser jp = OBJECT_MAPPER.getFactory().createParser(query);
646646
final JsonNode rootNode = OBJECT_MAPPER.readTree(jp);
647+
if (rootNode == null) {
648+
throw new IOException("null result");
649+
}
647650
final JsonNode timestampNode = rootNode.findValue("range").findValue("timestamp");
648651
final String from = elasticSearchTimeFormatToISO8601(timestampNode.findValue("from").asText());
649652
final String to = elasticSearchTimeFormatToISO8601(timestampNode.findValue("to").asText());

0 commit comments

Comments
 (0)