[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
This commit is contained in:
Gary D. Gregory 2013-09-18 14:57:57 +00:00
parent 2b5f84ede1
commit 22601f647f
2 changed files with 8 additions and 2 deletions

View File

@ -281,11 +281,11 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
* Returns a copy of the header map that iterates in column order.
* <p>
* The map keys are column names. The map values are 0-based indices.
*
* </p>
* @return a copy of the header map that iterates in column order.
*/
public Map<String, Integer> getHeaderMap() {
return new LinkedHashMap<String, Integer>(this.headerMap);
return this.headerMap == null ? null : new LinkedHashMap<String, Integer>(this.headerMap);
}
/**

View File

@ -664,6 +664,12 @@ public class CSVParserTest {
assertFalse(records.hasNext());
}
@Test
public void testNoHeaderMap() throws Exception {
final CSVParser parser = CSVParser.parse("a,b,c\n1,2,3\nx,y,z", CSVFormat.DEFAULT);
Assert.assertNull(parser.getHeaderMap());
}
@Test
public void testGetLineNumberWithLF() throws Exception {
this.validateLineNumbers(String.valueOf(LF));