NIFI-3278 Fixed ArrayIndexOutOfBoundsException in TextLineDemarcator

NIFI-3278 addressed PR comments

This closes #1389
This commit is contained in:
Oleg Zhurakousky 2017-01-04 12:09:34 -05:00 committed by Matt Burgess
parent 083d4043e0
commit bba675a11d
2 changed files with 26 additions and 2 deletions

View File

@ -159,8 +159,11 @@ public class TextLineDemarcator {
this.index = currentIndex + 1;
this.fill();
}
currentByte = this.buffer[currentIndex + 1];
crlfLength = currentByte == '\n' ? 2 : 1;
crlfLength = 1;
if (currentIndex < this.buffer.length - 1) {
currentByte = this.buffer[currentIndex + 1];
crlfLength = currentByte == '\n' ? 2 : 1;
}
}
return crlfLength;
}

View File

@ -51,6 +51,7 @@ public class TextLineDemarcatorTest {
assertNull(demarcator.nextOffsetInfo());
}
@Test
public void emptyStreamAndStartWithFilter() {
String data = "";
@ -59,6 +60,26 @@ public class TextLineDemarcatorTest {
assertNull(demarcator.nextOffsetInfo("hello".getBytes()));
}
// this test has no assertions. It's success criteria is validated by lack
// of failure (see NIFI-3278)
@Test
public void endsWithCRWithBufferLengthEqualStringLengthA() {
String str = "\r";
InputStream is = stringToIs(str);
TextLineDemarcator demarcator = new TextLineDemarcator(is, str.length());
while (demarcator.nextOffsetInfo() != null) {
}
}
@Test
public void endsWithCRWithBufferLengthEqualStringLengthB() {
String str = "abc\r";
InputStream is = stringToIs(str);
TextLineDemarcator demarcator = new TextLineDemarcator(is, str.length());
while (demarcator.nextOffsetInfo() != null) {
}
}
@Test
public void singleCR() {
InputStream is = stringToIs("\r");