commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1594966 - in /commons/proper/csv/trunk/src: changes/changes.xml main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordTest.java
Date Thu, 15 May 2014 16:26:27 GMT
Author: ggregory
Date: Thu May 15 16:26:26 2014
New Revision: 1594966

URL: http://svn.apache.org/r1594966
Log:
<action issue="CSV-118" type="fix" dev="ggregory" due-to="Enrique Lara">CSVRecord.toMap()
throws NPE on formats with no headers.</action>

Modified:
    commons/proper/csv/trunk/src/changes/changes.xml
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordTest.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=1594966&r1=1594965&r2=1594966&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/changes/changes.xml (original)
+++ commons/proper/csv/trunk/src/changes/changes.xml Thu May 15 16:26:26 2014
@@ -40,11 +40,15 @@
   <body>
 
     <release version="1.0" date="TBD" description="First release">
+      <action issue="CSV-118" type="fix" dev="ggregory" due-to="Enrique Lara">CSVRecord.toMap()
throws NPE on formats with no
+        headers.</action>
       <action issue="CSV-113" type="fix" dev="sebb">Check whether ISE/IAE are being
used appropriately</action>
       <action issue="CSV-114" type="fix" dev="sebb">CSVFormat constructor should reject
a header array with duplicate
-        entries</action>
+        entries
+      </action>
       <action issue="CSV-112" type="fix" dev="britter">HeaderMap is inconsistent when
it is parsed from an input with
-        duplicate columns names</action>
+        duplicate columns names
+      </action>
       <action issue="CSV-111" type="fix" dev="ggregory">CSVRecord.toMap() fails if
row length shorter than header length
       </action>
       <action issue="CSV-106" type="fix" dev="ggregory">CSVFormat.format allways append
null</action>
@@ -55,18 +59,21 @@
       </action>
       <action issue="CSV-99" type="update" dev="britter">Revert Builder implementation
in CSVFormat</action>
       <action issue="CSV-53" type="fix" dev="britter">CSVRecord does not verify that
the length of the header mapping
-        matches the number of values</action>
+        matches the number of values
+      </action>
       <action issue="CSV-93" type="update" dev="ggregory">Allow the handling of NULL
values</action>
       <action issue="CSV-68" type="update" dev="ggregory">Use the Builder pattern for
CSVFormat</action>
       <action issue="CSV-84" type="update" dev="sebb">Clarify comment handling</action>
       <action issue="CSV-25" type="update" dev="ebourg">CSVParser.nextValue() seems
pointless</action>
       <action issue="CSV-97" type="update" dev="ggregory">Allow the String value for
null to be customized for the CSV
-        printer</action>
+        printer
+      </action>
       <action issue="CSV-88" type="update" dev="ggregory">Not possible to create a
CSVFormat from scratch</action>
       <action issue="CSV-52" type="add" dev="ggregory">Keep track of record number</action>
       <action issue="CSV-94" type="update" dev="sebb">Lexer should only use char fields</action>
       <action issue="CSV-92" type="add" dev="ggregory">Need a way to extract parsed
headers, e.g. for use in formatting
-        output</action>
+        output
+      </action>
       <action issue="CSV-65" type="add" dev="ebourg">Header support</action>
       <action issue="CSV-54" type="fix" dev="sebb">Confusing semantic of the ignore
leading/trailing spaces parameters
       </action>
@@ -76,7 +83,8 @@
       <action issue="CSV-55" type="update" dev="britter">Replace while(true)-loop in
CSVParser.getRecord with do-while-loop
       </action>
       <action issue="CSV-34" type="fix" dev="sebb">CSVFormat describes itself as immutable,
but it is not - in
-        particular it is not thread-safe</action>
+        particular it is not thread-safe
+      </action>
       <action issue="CSV-36" type="fix" dev="yonik">Endless loops in CSV parser</action>
       <action issue="CSV-13" type="fix" dev="ebourg">NullPointerException in CSVPrinter.print()/println()</action>
       <action issue="CSV-45" type="update" dev="yonik">CSVPrinter overhaul</action>

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1594966&r1=1594965&r2=1594966&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu May 15
16:26:26 2014
@@ -177,6 +177,9 @@ public final class CSVRecord implements 
      * @return the given map.
      */
     <M extends Map<String, String>> M putIn(final M map) {
+        if (mapping == null) {
+            return map;
+        }
         for (final Entry<String, Integer> entry : mapping.entrySet()) {
             final int col = entry.getValue().intValue();
             if (col < values.length) {

Modified: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordTest.java?rev=1594966&r1=1594965&r2=1594966&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordTest.java (original)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordTest.java Thu May
15 16:26:26 2014
@@ -18,6 +18,7 @@ package org.apache.commons.csv;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
@@ -166,6 +167,15 @@ public class CSVRecordTest {
        final CSVRecord shortRec = parser.iterator().next();
        shortRec.toMap();
     }
+
+    @Test
+    public void testToMapWithNoHeader() throws Exception {
+       final CSVParser parser =  CSVParser.parse("a,b", CSVFormat.newFormat(','));
+       final CSVRecord shortRec = parser.iterator().next();
+       Map<String, String> map = shortRec.toMap();
+       assertNotNull("Map is not null.", map);
+       assertTrue("Map is empty.", map.isEmpty());
+    }
     
     private void validateMap(final Map<String, String> map, final boolean allowsNulls)
{
         assertTrue(map.containsKey("first"));



Mime
View raw message