mirror of
https://github.com/apache/commons-csv.git
synced 2025-02-28 05:49:04 +00:00
[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:
parent
2b5f84ede1
commit
22601f647f
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user