Skip to content

Commit

Permalink
Fix Null Pointer Exception in KeyValue Processor (#3927)
Browse files Browse the repository at this point in the history
* Fix Null Pointer Exception in KeyValue Processor

Signed-off-by: Krishna Kondaka <[email protected]>

* Added a test case

Signed-off-by: Krishna Kondaka <[email protected]>

---------

Signed-off-by: Krishna Kondaka <[email protected]>
Co-authored-by: Krishna Kondaka <[email protected]>
  • Loading branch information
kkondaka and Krishna Kondaka authored Jan 9, 2024
1 parent 774fa21 commit 35a6948
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor
final Map<String, Object> outputMap = new HashMap<>();
final Event recordEvent = record.getData();
final String groupsRaw = recordEvent.get(keyValueProcessorConfig.getSource(), String.class);
if (groupsRaw == null) {
continue;
}
final String[] groups = fieldDelimiterPattern.split(groupsRaw, 0);

if (keyValueProcessorConfig.getRecursive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ void testSingleKvToObjectKeyValueProcessor() {
assertThatKeyEquals(parsed_message, "key1", "value1");
}

@Test
void testKeyValueProcessorWithoutMessage() {
final Map<String, Object> testData = new HashMap();
testData.put("notMessage", "not a message");
final Record<Event> record = buildRecordWithEvent(testData);
final List<Record<Event>> editedRecords = (List<Record<Event>>) keyValueProcessor.doExecute(Collections.singletonList(record));
assertThat(editedRecords.size(), equalTo(1));
assertThat(editedRecords.get(0), notNullValue());
LinkedHashMap<String, Object> parsed_message = editedRecords.get(0).getData().get("parsed_message", LinkedHashMap.class);
assertThat(parsed_message, equalTo(null));
}

@Test
void testMultipleKvToObjectKeyValueProcessor() {
final Record<Event> record = getMessage("key1=value1&key2=value2");
Expand Down Expand Up @@ -851,4 +863,4 @@ private void assertThatKeyEquals(final LinkedHashMap<String, Object> parsed_mess
assertThat(parsed_message.containsKey(key), is(true));
assertThat(parsed_message.get(key), equalTo(value));
}
}
}

0 comments on commit 35a6948

Please sign in to comment.