You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/05/19 13:32:50 UTC
[commons-csv] branch master updated: [CSV-239] Cannot get headers
in column order from CSVRecord.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git
The following commit(s) were added to refs/heads/master by this push:
new d8d5de6 [CSV-239] Cannot get headers in column order from CSVRecord.
d8d5de6 is described below
commit d8d5de6476ac411593bd34ca89492e74905372ab
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun May 19 09:32:46 2019 -0400
[CSV-239] Cannot get headers in column order from CSVRecord.
Some NPE-proofing.
---
src/main/java/org/apache/commons/csv/CSVParser.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java
index 9615370..a3decdf 100644
--- a/src/main/java/org/apache/commons/csv/CSVParser.java
+++ b/src/main/java/org/apache/commons/csv/CSVParser.java
@@ -466,7 +466,7 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
if (formatHeader != null) {
hdrMap = this.format.getIgnoreHeaderCase() ?
new TreeMap<>(String.CASE_INSENSITIVE_ORDER) :
- new LinkedHashMap<>();
+ new TreeMap<>();
String[] headerRecord = null;
if (formatHeader.length == 0) {
@@ -486,13 +486,15 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
if (headerRecord != null) {
for (int i = 0; i < headerRecord.length; i++) {
final String header = headerRecord[i];
- final boolean containsHeader = hdrMap.containsKey(header);
+ final boolean containsHeader = header == null ? false : hdrMap.containsKey(header);
final boolean emptyHeader = header == null || header.trim().isEmpty();
if (containsHeader && (!emptyHeader || !this.format.getAllowMissingColumnNames())) {
- throw new IllegalArgumentException("The header contains a duplicate name: \"" + header +
- "\" in " + Arrays.toString(headerRecord));
+ throw new IllegalArgumentException("The header contains a duplicate name: \"" + header
+ + "\" in " + Arrays.toString(headerRecord));
+ }
+ if (header != null) {
+ hdrMap.put(header, Integer.valueOf(i));
}
- hdrMap.put(header, Integer.valueOf(i));
}
}
}