CSV-122: NullPointerException when empty header string and and null string of "". Thanks to Mike Lewis.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1609768 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
d3afa156e4
commit
b67524da7f
|
@ -40,6 +40,7 @@
|
|||
<body>
|
||||
|
||||
<release version="1.0" date="TBD" description="First release">
|
||||
<action issue="CSV-122" type="fix" dev="britter" due-to="Mike Lewis">NullPointerException when empty header string and and null string of ""</action>
|
||||
<action issue="CSV-117" type="update" dev="sebb">Validate format parameters in constructor</action>
|
||||
<action issue="CSV-121" type="add" dev="ggregory" due-to="Sebastian Hardt">IllegalArgumentException thrown when the header contains duplicate names when the column names are empty.</action>
|
||||
<action issue="CSV-120" type="add" dev="ggregory" due-to="Sergei Lebedev">CSVFormat#withHeader doesn't work with CSVPrinter</action>
|
||||
|
|
|
@ -381,7 +381,7 @@ public final class CSVParser implements Iterable<CSVRecord>, 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));
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue