Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit c2cf305

Browse files
authored
Merge pull request apache#352 from gbidsilva/CSV-310
[CSV-310] Misleading error message when QuoteMode set to None
2 parents dbdd56c + eb95e6d commit c2cf305

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ private void validate() throws IllegalArgumentException {
24492449
}
24502450

24512451
if (escapeCharacter == null && quoteMode == QuoteMode.NONE) {
2452-
throw new IllegalArgumentException("No quotes mode set but no escape character is set");
2452+
throw new IllegalArgumentException("Quote mode set to NONE but no escape character is set");
24532453
}
24542454

24552455
// Validate headers

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,4 +1477,17 @@ public void testWithSystemRecordSeparator() {
14771477
final CSVFormat formatWithRecordSeparator = CSVFormat.DEFAULT.withSystemRecordSeparator();
14781478
assertEquals(System.lineSeparator(), formatWithRecordSeparator.getRecordSeparator());
14791479
}
1480+
1481+
@Test
1482+
public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
1483+
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
1484+
CSVFormat.DEFAULT.builder()
1485+
.setHeader("Col1", "Col2", "Col3", "Col4")
1486+
.setQuoteMode(QuoteMode.NONE)
1487+
.build();
1488+
});
1489+
String actualMessage = exception.getMessage();
1490+
String expectedMessage = "Quote mode set to NONE but no escape character is set";
1491+
assertEquals(expectedMessage, actualMessage);
1492+
}
14801493
}

0 commit comments

Comments
 (0)