You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Jelmer Kuperus (JIRA)" <ji...@apache.org> on 2019/07/22 19:46:00 UTC

[jira] [Created] (CSV-249) ArrayIndexOutOfBoundsException when trying to read record using CSVParser written by CSVPrinter with same format

Jelmer Kuperus created CSV-249:
----------------------------------

             Summary: ArrayIndexOutOfBoundsException when trying to read record using CSVParser written by CSVPrinter with same format
                 Key: CSV-249
                 URL: https://issues.apache.org/jira/browse/CSV-249
             Project: Commons CSV
          Issue Type: Bug
          Components: Parser
    Affects Versions: 1.7, 1.6, 1.5
            Reporter: Jelmer Kuperus


The following code will fail with the exception 

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
{noformat}
import org.apache.commons.csv.*;

import java.io.StringReader;
import java.io.StringWriter;
import java.util.List;

public class Poc {

    public static void main(String[] args) throws Exception {

        CSVFormat csvFormat = CSVFormat.DEFAULT
                .withEscape('\\');

        StringWriter stringWriter = new StringWriter();

        CSVPrinter printer = new CSVPrinter(stringWriter, csvFormat);
        printer.printRecord("foo \\", "bar");

        StringReader stringReader = new StringReader(stringWriter.toString());
        CSVParser parser = new CSVParser(stringReader, csvFormat);
        List<CSVRecord> records = parser.getRecords();

        records.forEach(record -> {
            System.out.println(record.get(0));
            System.out.println(record.get(1));
        });

    }
}{noformat}



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)