Skip to content

Commit a7a4fdb

Browse files
committed
[ 2480dff ] after bug fix 9
2 parents 818888c + 2480dff commit a7a4fdb

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

src/changes/changes.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,15 @@
4040
<body>
4141

4242
<release version="1.0" date="TBD" description="First release">
43+
<action issue="CSV-118" type="fix" dev="ggregory" due-to="Enrique Lara">CSVRecord.toMap() throws NPE on formats with no
44+
headers.</action>
4345
<action issue="CSV-113" type="fix" dev="sebb">Check whether ISE/IAE are being used appropriately</action>
4446
<action issue="CSV-114" type="fix" dev="sebb">CSVFormat constructor should reject a header array with duplicate
45-
entries</action>
47+
entries
48+
</action>
4649
<action issue="CSV-112" type="fix" dev="britter">HeaderMap is inconsistent when it is parsed from an input with
47-
duplicate columns names</action>
50+
duplicate columns names
51+
</action>
4852
<action issue="CSV-111" type="fix" dev="ggregory">CSVRecord.toMap() fails if row length shorter than header length
4953
</action>
5054
<action issue="CSV-106" type="fix" dev="ggregory">CSVFormat.format allways append null</action>
@@ -55,18 +59,21 @@
5559
</action>
5660
<action issue="CSV-99" type="update" dev="britter">Revert Builder implementation in CSVFormat</action>
5761
<action issue="CSV-53" type="fix" dev="britter">CSVRecord does not verify that the length of the header mapping
58-
matches the number of values</action>
62+
matches the number of values
63+
</action>
5964
<action issue="CSV-93" type="update" dev="ggregory">Allow the handling of NULL values</action>
6065
<action issue="CSV-68" type="update" dev="ggregory">Use the Builder pattern for CSVFormat</action>
6166
<action issue="CSV-84" type="update" dev="sebb">Clarify comment handling</action>
6267
<action issue="CSV-25" type="update" dev="ebourg">CSVParser.nextValue() seems pointless</action>
6368
<action issue="CSV-97" type="update" dev="ggregory">Allow the String value for null to be customized for the CSV
64-
printer</action>
69+
printer
70+
</action>
6571
<action issue="CSV-88" type="update" dev="ggregory">Not possible to create a CSVFormat from scratch</action>
6672
<action issue="CSV-52" type="add" dev="ggregory">Keep track of record number</action>
6773
<action issue="CSV-94" type="update" dev="sebb">Lexer should only use char fields</action>
6874
<action issue="CSV-92" type="add" dev="ggregory">Need a way to extract parsed headers, e.g. for use in formatting
69-
output</action>
75+
output
76+
</action>
7077
<action issue="CSV-65" type="add" dev="ebourg">Header support</action>
7178
<action issue="CSV-54" type="fix" dev="sebb">Confusing semantic of the ignore leading/trailing spaces parameters
7279
</action>
@@ -76,7 +83,8 @@
7683
<action issue="CSV-55" type="update" dev="britter">Replace while(true)-loop in CSVParser.getRecord with do-while-loop
7784
</action>
7885
<action issue="CSV-34" type="fix" dev="sebb">CSVFormat describes itself as immutable, but it is not - in
79-
particular it is not thread-safe</action>
86+
particular it is not thread-safe
87+
</action>
8088
<action issue="CSV-36" type="fix" dev="yonik">Endless loops in CSV parser</action>
8189
<action issue="CSV-13" type="fix" dev="ebourg">NullPointerException in CSVPrinter.print()/println()</action>
8290
<action issue="CSV-45" type="update" dev="yonik">CSVPrinter overhaul</action>

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ public Iterator<String> iterator() {
177177
* @return the given map.
178178
*/
179179
<M extends Map<String, String>> M putIn(final M map) {
180+
if (mapping == null) {
181+
return map;
182+
}
180183
for (final Entry<String, Integer> entry : mapping.entrySet()) {
181184
final int col = entry.getValue().intValue();
182185
if (col < values.length) {

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertNotNull;
2122
import static org.junit.Assert.assertNull;
2223
import static org.junit.Assert.assertTrue;
2324

@@ -166,6 +167,15 @@ public void testToMapWithShortRecord() throws Exception {
166167
final CSVRecord shortRec = parser.iterator().next();
167168
shortRec.toMap();
168169
}
170+
171+
@Test
172+
public void testToMapWithNoHeader() throws Exception {
173+
final CSVParser parser = CSVParser.parse("a,b", CSVFormat.newFormat(','));
174+
final CSVRecord shortRec = parser.iterator().next();
175+
Map<String, String> map = shortRec.toMap();
176+
assertNotNull("Map is not null.", map);
177+
assertTrue("Map is empty.", map.isEmpty());
178+
}
169179

170180
private void validateMap(final Map<String, String> map, final boolean allowsNulls) {
171181
assertTrue(map.containsKey("first"));

0 commit comments

Comments
 (0)