Skip to content

Commit ef84a2a

Browse files
committed
[ 9f03b06 ] after bug fix 6
2 parents b0715ab + 9f03b06 commit ef84a2a

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ public Iterator<String> iterator() {
178178
*/
179179
<M extends Map<String, String>> M putIn(final M map) {
180180
for (final Entry<String, Integer> entry : mapping.entrySet()) {
181-
map.put(entry.getKey(), values[entry.getValue().intValue()]);
181+
final int col = entry.getValue().intValue();
182+
if (col < values.length) {
183+
map.put(entry.getKey(), values[col]);
184+
}
182185
}
183186
return map;
184187
}

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ public void testToMap() {
160160
this.validateMap(map, true);
161161
}
162162

163+
@Test
164+
public void testToMapWithShortRecord() throws Exception {
165+
final CSVParser parser = CSVParser.parse("a,b", CSVFormat.DEFAULT.withHeader("A", "B", "C"));
166+
final CSVRecord shortRec = parser.iterator().next();
167+
shortRec.toMap();
168+
}
169+
163170
private void validateMap(final Map<String, String> map, final boolean allowsNulls) {
164171
assertTrue(map.containsKey("first"));
165172
assertTrue(map.containsKey("second"));

0 commit comments

Comments
 (0)