Skip to content

Commit f7ce795

Browse files
committed
[CSV-239] Cannot get headers in column order from CSVRecord.
* simplify if statement
1 parent 9893c09 commit f7ce795

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,16 @@ private Headers createHeaderMapAndHeaderNames() throws IOException {
488488
final String header = headerRecord[i];
489489
final boolean containsHeader = header == null ? false : hdrMap.containsKey(header);
490490
final boolean emptyHeader = header == null || header.trim().isEmpty();
491-
if (containsHeader && !emptyHeader && !this.format.getAllowDuplicateHeaderNames()) {
492-
throw new IllegalArgumentException("The header contains a duplicate name: \"" + header
493-
+ "\" in " + Arrays.toString(headerRecord) + ". If this is valid then use CSVFormat.withAllowDuplicateHeaderNames().");
494-
}
495-
if (containsHeader && emptyHeader && !this.format.getAllowMissingColumnNames()) {
496-
throw new IllegalArgumentException("A header name is missing in " + Arrays.toString(headerRecord));
491+
if (containsHeader) {
492+
if (!emptyHeader && !this.format.getAllowDuplicateHeaderNames()) {
493+
throw new IllegalArgumentException("The header contains a duplicate name: \"" + header
494+
+ "\" in " + Arrays.toString(headerRecord)
495+
+ ". If this is valid then use CSVFormat.withAllowDuplicateHeaderNames().");
496+
}
497+
if (emptyHeader && !this.format.getAllowMissingColumnNames()) {
498+
throw new IllegalArgumentException(
499+
"A header name is missing in " + Arrays.toString(headerRecord));
500+
}
497501
}
498502
if (header != null) {
499503
hdrMap.put(header, Integer.valueOf(i));

0 commit comments

Comments
 (0)