You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2017/07/20 20:18:01 UTC
[jira] [Updated] (CSV-213) CSVParser#iterator()#hasNext() fails
[ https://issues.apache.org/jira/browse/CSV-213?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary Gregory updated CSV-213:
-----------------------------
Summary: CSVParser#iterator()#hasNext() fails (was: CSVParser#terator()#hasNext() fails)
> CSVParser#iterator()#hasNext() fails
> ------------------------------------
>
> Key: CSV-213
> URL: https://issues.apache.org/jira/browse/CSV-213
> Project: Commons CSV
> Issue Type: Bug
> Components: Parser
> Affects Versions: 1.4
> Environment: linux/osx
> Reporter: Lukas Vasek
> Priority: Blocker
> Attachments: 999751170.patch.csv
>
>
> Hello,
> with class sample below and attached fail 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?
> {code:java}
> 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"));
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)