Skip to content

Commit

Permalink
fix ArrayIndexOutOfBoundsException from empty String field reference
Browse files Browse the repository at this point in the history
fixes #8823

Fixes #8824
  • Loading branch information
jakelandis committed Dec 11, 2017
1 parent 1ea1d19 commit a1e5897
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions logstash-core/src/main/java/org/logstash/FieldReference.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public final class FieldReference {
private static final FieldReference METADATA_PARENT_REFERENCE =
new FieldReference(EMPTY_STRING_ARRAY, Event.METADATA, META_PARENT);

static final FieldReference DATA_EMPTY_STRING_REFERENCE =
new FieldReference(EMPTY_STRING_ARRAY, "", DATA_CHILD);

/**
* Cache of all existing {@link FieldReference}.
*/
Expand All @@ -70,6 +73,9 @@ private FieldReference(final String[] path, final String key, final int type) {
}

public static FieldReference from(final CharSequence reference) {
if( reference == null || reference.length() == 0){
return DATA_EMPTY_STRING_REFERENCE;
}
// atomicity between the get and put is not important
final FieldReference result = CACHE.get(reference);
if (result != null) {
Expand Down
10 changes: 10 additions & 0 deletions logstash-core/src/test/java/org/logstash/FieldReferenceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,14 @@ public void testParse3FieldsPath() throws Exception {
public void deduplicatesTimestamp() throws Exception {
assertTrue(FieldReference.from("@timestamp") == FieldReference.from("[@timestamp]"));
}

@Test
public void testParseEmptyString(){
assertEquals(FieldReference.from(""), FieldReference.DATA_EMPTY_STRING_REFERENCE);
}

@Test
public void testParseNull(){
assertEquals(FieldReference.from(null), FieldReference.DATA_EMPTY_STRING_REFERENCE);
}
}

0 comments on commit a1e5897

Please sign in to comment.