osiegmar / FastCSV

CSV library for Java that is fast, RFC-compliant and dependency-free.
https://fastcsv.org/
MIT License
551 stars 93 forks source link

ArrayIndexOutOfBoundsException in ReusableStringBuilder #21

Closed topsy-turvy closed 6 years ago

topsy-turvy commented 6 years ago

Please help with this exception:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at java.base/java.lang.System.arraycopy(Native Method) at de.siegmar.fastcsv.reader.ReusableStringBuilder.append(ReusableString Builder.java:65) at de.siegmar.fastcsv.reader.RowReader.readLine(RowReader.java:74) at de.siegmar.fastcsv.reader.CsvParser.nextRow(CsvParser.java:85) at de.siegmar.fastcsv.reader.CsvReader.read(CsvReader.java:147) at de.siegmar.fastcsv.reader.CsvReader.read(CsvReader.java:126) at com.teamtrade.fundamental.report.screener.ReportScreener.readCsvFile( ReportScreener.java:69) at com.teamtrade.fundamental.report.screener.ReportScreener.readQuarterR eports(ReportScreener.java:141) at com.teamtrade.fundamental.report.screener.ReportScreener.main(ReportS creener.java:45)

private static CsvContainer readCsvFile(Path path) throws IOException {
    CsvReader csvReader = new CsvReader();
    csvReader.setFieldSeparator('\t');
    csvReader.setContainsHeader(true);
    return csvReader.read(path, StandardCharsets.UTF_8); // line number 69
}

CSV file name 'txt.tsv'. It is in this archive: https://www.sec.gov/files/dera/data/financial-statement-and-notes-data-sets/2015q2_notes.zip

osiegmar commented 6 years ago

The file does not contain any text delimiters, but FastCSV is configured to read double quotes as a text delimiter, by default. The file does contain double quotes but they're not meant as text delimiters and thus FastCSV misinterprets them...

Right now, it's not possible to disable text delimiters explicitly, but you can set the character to some value that does not occur in your file(s).

I tested your file by setting the text delimiter to the null character by:

csvReader.setTextDelimiter('\0');
topsy-turvy commented 6 years ago

Much appreciate your reply. I'll give it a try. Thanks!

topsy-turvy commented 6 years ago

It works. Thank you.