commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject svn commit: r1609768 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVParser.java test/java/org/apache/commons/csv/CSVParserTest.java
Date Fri, 11 Jul 2014 18:42:49 GMT
Author: britter
Date: Fri Jul 11 18:42:48 2014
New Revision: 1609768

URL: http://svn.apache.org/r1609768
Log:
CSV-122: NullPointerException when empty header string and and null string of "". Thanks to
Mike Lewis.

Modified:
    commons/proper/csv/trunk/src/changes/changes.xml
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java

Modified: commons/proper/csv/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/changes/changes.xml?rev=1609768&r1=1609767&r2=1609768&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Fri Jul 11 18:42:48 2014
@@ -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>

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java?rev=1609768&r1=1609767&r2=1609768&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVParser.java Fri Jul 11
18:42:48 2014
@@ -381,7 +381,7 @@ public final class CSVParser implements 
                 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));

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java?rev=1609768&r1=1609767&r2=1609768&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVParserTest.java Fri Jul
11 18:42:48 2014
@@ -662,6 +662,12 @@ public class CSVParserTest {
     }
 
     @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");
 



Mime
View raw message