Menu

#147 CSVParser#terator()#hasNext() fails

v1.0 (example)
closed-invalid
None
1
2017-07-26
2017-07-20
bilak
No

Hello,
with this configuration

``
public class Test {

private static final CSVFormat csvFormat =
        CSVFormat.DEFAULT
                .withDelimiter(';')
                .withFirstRecordAsHeader()
                .withRecordSeparator('\n')
                .withQuoteMode(QuoteMode.ALL);


private static Optional<String[]> createEndChannel(File csvFile) {
    try (Reader reader = new InputStreamReader(new FileInputStream(csvFile), StandardCharsets.UTF_8);
         CSVParser parser = new CSVParser(reader, csvFormat)) {
        if (parser.iterator().hasNext()) {
            System.out.println(parser.getCurrentLineNumber());
            System.out.println(parser.getRecordNumber());
            // get only first record we don't need other's
            CSVRecord firstRecord = parser.iterator().next(); // this fails

            return Optional.of(null);
        }
    } catch (IOException e) {
        throw new RuntimeException("Error while adding end channel to csv", e);
    }

    return Optional.empty();
}


public static void main(String[] args) {
    createEndChannel(new File("/tmp/999751170.patch.csv"));
    //createEndChannel(new File("/tmp/129441.csv"));
}

}
``

and attached file the program fails. Problem is that iterator wrongly computes the records. If hasNext is true then next record should be fetched.

  • wouldn't it be better to provide currentRecord also?
1 Attachments

Discussion

  • bilak

    bilak - 2017-07-20

    sorry bad project

     
  • Andrew Rucker Jones

    • status: open --> closed-invalid
    • assigned_to: Andrew Rucker Jones
     

Log in to post a comment.