[CSV-310] Misleading error message when QuoteMode set to None #352
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See related Jira issue: https://issues.apache.org/jira/browse/CSV-310
When we try to print CSV content using the
CSVFormat
andCSVPrinter
, we can ger it done with following sample code.In above sample I have used
setQuoteMode(QuoteMode.NONE)
. However, if we do not set the escape character usingsetEscape('#')
then it would result in following exception.java.lang.IllegalArgumentException: No quotes mode set but no escape character is set.
At first, I was wondering why I was getting this error. Then I looked into the source and figured out that
CSVFormat.printWithEscapes()
method internally usinggetEscapeCharacter().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
.