This repository was archived by the owner on Sep 14, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
src/main/java/org/apache/commons/csv Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -466,7 +466,7 @@ private Map<String, Integer> createHeaderMap() throws IOException {
466466 if (formatHeader != null ) {
467467 hdrMap = this .format .getIgnoreHeaderCase () ?
468468 new TreeMap <>(String .CASE_INSENSITIVE_ORDER ) :
469- new LinkedHashMap <>();
469+ new TreeMap <>();
470470
471471 String [] headerRecord = null ;
472472 if (formatHeader .length == 0 ) {
@@ -486,13 +486,15 @@ private Map<String, Integer> createHeaderMap() throws IOException {
486486 if (headerRecord != null ) {
487487 for (int i = 0 ; i < headerRecord .length ; i ++) {
488488 final String header = headerRecord [i ];
489- final boolean containsHeader = hdrMap .containsKey (header );
489+ final boolean containsHeader = header == null ? false : hdrMap .containsKey (header );
490490 final boolean emptyHeader = header == null || header .trim ().isEmpty ();
491491 if (containsHeader && (!emptyHeader || !this .format .getAllowMissingColumnNames ())) {
492- throw new IllegalArgumentException ("The header contains a duplicate name: \" " + header +
493- "\" in " + Arrays .toString (headerRecord ));
492+ throw new IllegalArgumentException ("The header contains a duplicate name: \" " + header
493+ + "\" in " + Arrays .toString (headerRecord ));
494+ }
495+ if (header != null ) {
496+ hdrMap .put (header , Integer .valueOf (i ));
494497 }
495- hdrMap .put (header , Integer .valueOf (i ));
496498 }
497499 }
498500 }
You can’t perform that action at this time.
0 commit comments