ARTICLE AD BOX
Using Opencsv (5.11), sometimes we get input files with a lot of lines (as many as 80k lines). If there's a CsvMalformedLineException while parsing one of these files (an "Unterminated quoted field at end of CSV line" problem), the exception gets wrapped in a RuntimeException with the entire offending line included in the exception message. With typical exception logging, that can result in massive log messages.
The problem with this kind of error in a really large file is that the unmatched " character causes the parser to think the whole remainder of the file is part of the same line, so all that content makes it into the exception message (see example below).
Something interesting is that the underlying CsvMalformedLineException's message only includes the start of the offending line text, which is actually more desirable.
Is there a straightforward way to prevent the RuntimeException from including the entire line in its message?
Example
Imagine a CSV file like this (kept small for readability):
col1, col2, col3, col4 Column 1-1 data,Column 1-2 data,Column 1-3 data,Column 1-4 data Column 2-1 data,Column 2-2" data,Column 2-3 data,Column 2-4 data Column 3-1 data,Column 3-2 data,Column 3-3 data,Column 3-4 data Column 4-1 data,Column 4-2 data,Column 4-3 data,Column 4-4 dataThe unterminated " in column 2-2 causes the exception to report that the offending line is
Column 2-1 data,Column 2-2" data,Column 2-3 data,Column 2-4 data Column 3-1 data,Column 3-2 data,Column 3-3 data,Column 3-4 data Column 4-1 data,Column 4-2 data,Column 4-3 data,Column 4-4 dataImagine a file with tens of thousands of lines after the unmatched " - the log messages get so huge as to be unusable.
Stepping through the source code, I found that the class LineExecutor is where the CsvMalformedLineException gets wrapped and the library's built-in resource bundle is used to formulate that message, using the CsvMalformedLineException's context (which is the offending "line"). It doesn't look trivial or even possible to override that.
I also considered catching the RuntimeException re-wrapping the nested exception with a shorter message, but that feels more than a little hack-y; I'm looking for another way more natural to Opencsv.
