Why does Apache Commons CSVParser.getHeaderMap() always return null?

Viewed 4169

When reading the following TSV snippet with Apache Commons CSV:

Name    DOB SIN Address, contact information
"Patience Middleton"    "18-4-87"   720463771   "varius Cras sem aliquam taciti fames hendrerit tempor"

This is my code:

CSVFormat format = CSVFormat.newFormat('\t').withQuote('"');
CSVParser parsed = CSVParser.parse(csvData, format);
List<CSVRecord> record = parsed.getRecords();
System.out.println(parsed.getHeaderMap().toString());

However I always get a NullPointerException stating that parsed.getHeaderMap() == null.

According to the API (https://commons.apache.org/proper/commons-csv/apidocs/org/apache/commons/csv/CSVParser.html), the method may return a copy of the header map that iterates in column order.

Is there something wrong in my code or CSV file? Is the library failing?

1 Answers
Related