Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 503aca7

Browse files
committed
Backport #54 fix for 2.4.4
1 parent f639f66 commit 503aca7

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

release-notes/CREDITS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ Jason Dunkelberger (dirkraft@github)
2222

2323
* Suggested #32: Allow disabling of quoteChar
2424
(2.4.0)
25+
26+
Wei Li (wli600@github)
27+
28+
* Contributed fix for 54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter
29+
or end-of-line happened to be the leading character of a segment buffer
30+
(2.4.4)

release-notes/VERSION

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ Project: jackson-dataformat-csv
99
#53: Add a way to specify "null value" (String) for `CsvGenerator` to use when writing `null`s
1010
(part of `CsvSchema`; method `withNullValue()`)
1111

12+
2.4.4 (not yet released)
13+
14+
#54: Encounter ArrayIndexOutOfBoundsException in the corner case delimiter or end-of-line
15+
happened to be the leading character of a segment buffer
16+
(contributed by wli600@github)
17+
1218
2.4.3 (04-Oct-2014)
1319

1420
- Support JDK serializability of CsvMapper

src/main/java/com/fasterxml/jackson/dataformat/csv/impl/TextBuffer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,16 +404,17 @@ public int getCurrentSegmentSize() {
404404
}
405405

406406
/**
407-
*
408-
* @param lastSegmentEnd End offset in the currently active segment
407+
* @param lastSegmentEnd End offset in the currently active segment,
408+
* could be 0 in the case of first character is
409+
* delimiter or end-of-line
409410
* @param trimTrailingSpaces Whether trailing spaces should be trimmed or not
410411
*/
411412
public String finishAndReturn(int lastSegmentEnd, boolean trimTrailingSpaces)
412413
{
413414
if (trimTrailingSpaces) {
414415
// First, see if it's enough to trim end of current segment:
415-
int ptr = lastSegmentEnd-1;
416-
if (_currentSegment[ptr] <= 0x0020) {
416+
int ptr = lastSegmentEnd - 1;
417+
if (ptr < 0 || _currentSegment[ptr] <= 0x0020) {
417418
return _doTrim(ptr);
418419
}
419420
}

src/test/java/com/fasterxml/jackson/dataformat/csv/TestParserNoSchema.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,37 @@ public void testUntypedAsSequenceVarLengths() throws Exception
120120
it.close();
121121
}
122122

123+
// [Issue#54]
124+
public void testDelimiterAtBufferBoundary() throws Exception
125+
{
126+
CsvMapper mapper = mapperForCsv();
127+
mapper.enable(CsvParser.Feature.TRIM_SPACES);
128+
129+
final String col1 = "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
130+
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
131+
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" +
132+
"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
133+
final String col2 = "H";
134+
135+
CsvParser cp = mapper.getFactory().createParser(col1 + " ," + col2 +"\n" + col2 + "," + col1 + "\n");
136+
MappingIterator<Object[]> it = mapper.reader(Object[].class).readValues(cp);
137+
138+
Object[] row;
139+
140+
assertTrue(it.hasNext());
141+
row = it.next();
142+
assertEquals(2, row.length);
143+
assertEquals(col1, row[0]);
144+
assertEquals(col2, row[1]);
145+
146+
assertTrue(it.hasNext());
147+
row = it.next();
148+
assertEquals(2, row.length);
149+
assertEquals(col2, row[0]);
150+
assertEquals(col1, row[1]);
151+
152+
cp.close();
153+
it.close();
154+
}
155+
123156
}

0 commit comments

Comments
 (0)