Skip to content

Commit 6d5993c

Browse files
authored
Merge pull request #600 from garydgregory/fix/CSV-321_CSVFormat_equals_hashCode
[CSV-321] CSVFormat.equals()/hashCode() ignores maxRows
2 parents 69248ba + 5e2d059 commit 6d5993c

2 files changed

Lines changed: 16 additions & 7 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,11 +1690,11 @@ public boolean equals(final Object obj) {
16901690
duplicateHeaderMode == other.duplicateHeaderMode && Objects.equals(escapeCharacter, other.escapeCharacter) &&
16911691
Arrays.equals(headerComments, other.headerComments) && Arrays.equals(headers, other.headers) &&
16921692
ignoreEmptyLines == other.ignoreEmptyLines && ignoreHeaderCase == other.ignoreHeaderCase &&
1693-
ignoreSurroundingSpaces == other.ignoreSurroundingSpaces && lenientEof == other.lenientEof &&
1694-
Objects.equals(nullString, other.nullString) && Objects.equals(quoteCharacter, other.quoteCharacter) &&
1695-
quoteMode == other.quoteMode && Objects.equals(quotedNullString, other.quotedNullString) &&
1696-
Objects.equals(recordSeparator, other.recordSeparator) && skipHeaderRecord == other.skipHeaderRecord &&
1697-
trailingData == other.trailingData && trailingDelimiter == other.trailingDelimiter && trim == other.trim;
1693+
ignoreSurroundingSpaces == other.ignoreSurroundingSpaces && lenientEof == other.lenientEof && maxRows == other.maxRows &&
1694+
Objects.equals(nullString, other.nullString) && Objects.equals(quoteCharacter, other.quoteCharacter) && quoteMode == other.quoteMode &&
1695+
Objects.equals(quotedNullString, other.quotedNullString) && Objects.equals(recordSeparator, other.recordSeparator) &&
1696+
skipHeaderRecord == other.skipHeaderRecord && trailingData == other.trailingData && trailingDelimiter == other.trailingDelimiter &&
1697+
trim == other.trim;
16981698
}
16991699

17001700
private void escape(final char c, final Appendable appendable) throws IOException {
@@ -2029,9 +2029,10 @@ public int hashCode() {
20292029
int result = 1;
20302030
result = prime * result + Arrays.hashCode(headerComments);
20312031
result = prime * result + Arrays.hashCode(headers);
2032-
return prime * result + Objects.hash(allowMissingColumnNames, autoFlush, commentMarker, delimiter, duplicateHeaderMode, escapeCharacter,
2033-
ignoreEmptyLines, ignoreHeaderCase, ignoreSurroundingSpaces, lenientEof, nullString, quoteCharacter, quoteMode, quotedNullString,
2032+
result = prime * result + Objects.hash(allowMissingColumnNames, autoFlush, commentMarker, delimiter, duplicateHeaderMode, escapeCharacter,
2033+
ignoreEmptyLines, ignoreHeaderCase, ignoreSurroundingSpaces, lenientEof, maxRows, nullString, quoteCharacter, quoteMode, quotedNullString,
20342034
recordSeparator, skipHeaderRecord, trailingData, trailingDelimiter, trim);
2035+
return result;
20352036
}
20362037

20372038
/**

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ void testEqualsLeftNoQuoteRightQuote_Deprecated() {
395395
assertNotEqualsFlip(left, right);
396396
}
397397

398+
@Test
399+
void testEqualsMaxRows() {
400+
final CSVFormat right = CSVFormat.DEFAULT.builder().setMaxRows(10).get();
401+
final CSVFormat left = CSVFormat.DEFAULT.builder().setMaxRows(1000).get();
402+
assertNotEqualsFlip(right, left);
403+
assertNotEquals(right.hashCode(), left.hashCode());
404+
}
405+
398406
@Test
399407
void testEqualsNoQuotes() {
400408
final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).get();

0 commit comments

Comments
 (0)