Skip to content

Commit 22601f6

Browse files
committed
[CSV-100] CSVParser: getHeaderMap throws NPE.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1524435 13f79535-47bb-0310-9956-ffa450edef68
1 parent 2b5f84e commit 22601f6

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,11 @@ public long getCurrentLineNumber() {
281281
* Returns a copy of the header map that iterates in column order.
282282
* <p>
283283
* The map keys are column names. The map values are 0-based indices.
284-
*
284+
* </p>
285285
* @return a copy of the header map that iterates in column order.
286286
*/
287287
public Map<String, Integer> getHeaderMap() {
288-
return new LinkedHashMap<String, Integer>(this.headerMap);
288+
return this.headerMap == null ? null : new LinkedHashMap<String, Integer>(this.headerMap);
289289
}
290290

291291
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,12 @@ public void testGetHeaderMap() throws Exception {
664664
assertFalse(records.hasNext());
665665
}
666666

667+
@Test
668+
public void testNoHeaderMap() throws Exception {
669+
final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT);
670+
Assert.assertNull(parser.getHeaderMap());
671+
}
672+
667673
@Test
668674
public void testGetLineNumberWithLF() throws Exception {
669675
this.validateLineNumbers(String.valueOf(LF));

0 commit comments

Comments
 (0)