diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index a08b6c8a..7c7097fd 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -199,6 +199,10 @@ public class CSVFormat implements Serializable { if (escape != null && escape == commentStart) { throw new IllegalStateException("The comment start and the escape character cannot be the same ('" + commentStart + "')"); } + + if (escape == null && quotePolicy == Quote.NONE) { + throw new IllegalStateException("No quotes mode set but no escape character is set"); + } } /** diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java index b0ba045a..f6884c19 100644 --- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java +++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java @@ -153,7 +153,14 @@ public class CSVFormatTest { } catch (final IllegalStateException e) { // expected } - } + + try { + format.withQuoteChar('!').withQuotePolicy(Quote.NONE).validate(); + fail(); + } catch (final IllegalStateException e) { + // expected + } +} @SuppressWarnings("boxing") // no need to worry about boxing here @Test