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,9 +159,12 @@ public class TextLineDemarcator {
|
||||||
this.index = currentIndex + 1;
|
this.index = currentIndex + 1;
|
||||||
this.fill();
|
this.fill();
|
||||||
}
|
}
|
||||||
|
crlfLength = 1;
|
||||||
|
if (currentIndex < this.buffer.length - 1) {
|
||||||
currentByte = this.buffer[currentIndex + 1];
|
currentByte = this.buffer[currentIndex + 1];
|
||||||
crlfLength = currentByte == '\n' ? 2 : 1;
|
crlfLength = currentByte == '\n' ? 2 : 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return crlfLength;
|
return crlfLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class TextLineDemarcatorTest {
|
||||||
assertNull(demarcator.nextOffsetInfo());
|
assertNull(demarcator.nextOffsetInfo());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyStreamAndStartWithFilter() {
|
public void emptyStreamAndStartWithFilter() {
|
||||||
String data = "";
|
String data = "";
|
||||||
|
@ -59,6 +60,26 @@ public class TextLineDemarcatorTest {
|
||||||
assertNull(demarcator.nextOffsetInfo("hello".getBytes()));
|
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
|
@Test
|
||||||
public void singleCR() {
|
public void singleCR() {
|
||||||
InputStream is = stringToIs("\r");
|
InputStream is = stringToIs("\r");
|
||||||
|
|
Loading…
Reference in New Issue