Repository: nifi Updated Branches: refs/heads/master 083d4043e -> bba675a11
NIFI-3278 Fixed ArrayIndexOutOfBoundsException in TextLineDemarcator NIFI-3278 addressed PR comments This closes #1389 Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/bba675a1 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/bba675a1 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/bba675a1 Branch: refs/heads/master Commit: bba675a11dce4fe28617ef93a1c807aba77da200 Parents: 083d404 Author: Oleg Zhurakousky <[email protected]> Authored: Wed Jan 4 12:09:34 2017 -0500 Committer: Matt Burgess <[email protected]> Committed: Wed Jan 4 15:52:23 2017 -0500 ---------------------------------------------------------------------- .../nifi/stream/io/util/TextLineDemarcator.java | 7 +++++-- .../stream/io/util/TextLineDemarcatorTest.java | 21 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/bba675a1/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java index 124e673..7c918b4 100644 --- a/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java +++ b/nifi-commons/nifi-utils/src/main/java/org/apache/nifi/stream/io/util/TextLineDemarcator.java @@ -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; } http://git-wip-us.apache.org/repos/asf/nifi/blob/bba675a1/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java index ce66cad..cd8b7c5 100644 --- a/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java +++ b/nifi-commons/nifi-utils/src/test/java/org/apache/nifi/stream/io/util/TextLineDemarcatorTest.java @@ -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");
