diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0e74adda..26ad32f3 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -40,6 +40,7 @@
+ NullPointerException when empty header string and and null string of ""
Validate format parameters in constructor
IllegalArgumentException thrown when the header contains duplicate names when the column names are empty.
CSVFormat#withHeader doesn't work with CSVPrinter
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index b6867a40..b7ca3fa9 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -381,7 +381,7 @@ public final class CSVParser implements Iterable, Closeable {
for (int i = 0; i < headerRecord.length; i++) {
final String header = headerRecord[i];
final boolean containsHeader = hdrMap.containsKey(header);
- final boolean emptyHeader = header.trim().isEmpty();
+ final boolean emptyHeader = header == null || header.trim().isEmpty();
if (containsHeader && (!emptyHeader || (emptyHeader && !this.format.getIgnoreEmptyHeaders()))) {
throw new IllegalArgumentException("The header contains a duplicate name: \"" + header +
"\" in " + Arrays.toString(headerRecord));
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index 75531b5d..f5b6cb86 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -661,6 +661,12 @@ public class CSVParserTest {
CSVFormat.DEFAULT.withHeader().withIgnoreEmptyHeaders(true).parse(in).iterator();
}
+ @Test
+ public void testHeaderMissingWithNull() throws Exception {
+ final Reader in = new StringReader("a,,c,,d\n1,2,3,4\nx,y,z,zz");
+ CSVFormat.DEFAULT.withHeader().withNullString("").withIgnoreEmptyHeaders(true).parse(in).iterator();
+ }
+
@Test
public void testHeaderComment() throws Exception {
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");