[
https://issues.apache.org/jira/browse/CSV-310?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Gary D. Gregory resolved CSV-310.
---------------------------------
Fix Version/s: 1.10.1
Resolution: Fixed
> Misleading error message when QuoteMode set to None
> ---------------------------------------------------
>
> Key: CSV-310
> URL: https://issues.apache.org/jira/browse/CSV-310
> Project: Commons CSV
> Issue Type: Improvement
> Components: Parser
> Affects Versions: 1.10.0
> Reporter: Buddhi De Silva
> Priority: Minor
> Labels: easy-fix, formatter,
> Fix For: 1.10.1
>
>
> When we try to print CSV content using the _CSVFormat_ and {_}CSVPrinter{_},
> we can ger it done with following sample code.
> {code:java}
> public void testHappyPath() throws IOException {
> CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
> .setHeader("Col1", "Col2", "Col3", "Col4")
> .setQuoteMode(QuoteMode.NONE)
> .setEscape('#')
> .build(); CSVPrinter printer = new CSVPrinter(System.out,
> csvFormat); List<String[]> temp = new ArrayList<>(); temp.add(new
> String[] { "rec1", "rec2\"", "", "rec4" });
> temp.add(new String[] { "", "rec6", "rec7", "rec8" }); for (String[]
> temp1 : temp) {
> printer.printRecord(temp1);
> }
> printer.close();
> } {code}
> In above sample I have used 'setQuoteMode(QuoteMode.NONE)'. However, if we do
> not set the escape character using 'setEscape('#')' then it would result in
> following exception.
> {code:java}
> java.lang.IllegalArgumentException: No quotes mode set but no escape
> character is set. {code}
> At first, I was wondering why I was getting this error. Then I looked into
> the source and figured out that _CSVFormat.printWithEscapes()_ method
> internaly using _getEscapeCharacter().charValue()_ method to print records.
>
> However, the error message which we are getting is sort of misleading. It
> implies that the code has not set any quote mode even though we set it.
> Simple and more meaningful exception message could be: "Quote mode set to
> NONE but no escape character is set".
--
This message was sent by Atlassian Jira
(v8.20.10#820010)