@@ -348,9 +348,6 @@ private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMo
348348 final boolean ignoreEmptyLines , final String recordSeparator , final String nullString ,
349349 final Object [] headerComments , final String [] header , final boolean skipHeaderRecord ,
350350 final boolean allowMissingColumnNames ) {
351- if (isLineBreak (delimiter )) {
352- throw new IllegalArgumentException ("The delimiter cannot be a line break" );
353- }
354351 this .delimiter = delimiter ;
355352 this .quoteCharacter = quoteChar ;
356353 this .quoteMode = quoteMode ;
@@ -362,18 +359,7 @@ private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMo
362359 this .recordSeparator = recordSeparator ;
363360 this .nullString = nullString ;
364361 this .headerComments = toStringArray (headerComments );
365- if (header == null ) {
366- this .header = null ;
367- } else {
368- final Set <String > dupCheck = new HashSet <String >();
369- for (final String hdr : header ) {
370- if (!dupCheck .add (hdr )) {
371- throw new IllegalArgumentException ("The header contains a duplicate entry: '" + hdr + "' in " +
372- Arrays .toString (header ));
373- }
374- }
375- this .header = header .clone ();
376- }
362+ this .header = header == null ? null : header .clone ();
377363 this .skipHeaderRecord = skipHeaderRecord ;
378364 validate ();
379365 }
@@ -742,6 +728,10 @@ public String toString() {
742728 * @throws IllegalArgumentException
743729 */
744730 private void validate () throws IllegalArgumentException {
731+ if (isLineBreak (delimiter )) {
732+ throw new IllegalArgumentException ("The delimiter cannot be a line break" );
733+ }
734+
745735 if (quoteCharacter != null && delimiter == quoteCharacter .charValue ()) {
746736 throw new IllegalArgumentException ("The quoteChar character and the delimiter cannot be the same ('" +
747737 quoteCharacter + "')" );
@@ -770,6 +760,17 @@ private void validate() throws IllegalArgumentException {
770760 if (escapeCharacter == null && quoteMode == QuoteMode .NONE ) {
771761 throw new IllegalArgumentException ("No quotes mode set but no escape character is set" );
772762 }
763+
764+ // validate header
765+ if (header != null ) {
766+ final Set <String > dupCheck = new HashSet <String >();
767+ for (final String hdr : header ) {
768+ if (!dupCheck .add (hdr )) {
769+ throw new IllegalArgumentException ("The header contains a duplicate entry: '" + hdr + "' in " +
770+ Arrays .toString (header ));
771+ }
772+ }
773+ }
773774 }
774775
775776 /**
0 commit comments