mirror of https://github.com/apache/nifi.git
NIFI-3278 Fixed ArrayIndexOutOfBoundsException in TextLineDemarcator
NIFI-3278 addressed PR comments This closes #1389
This commit is contained in:
parent
083d4043e0
commit
bba675a11d
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue