[
https://issues.apache.org/jira/browse/CSV-195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15473739#comment-15473739
]
Michael Vitz commented on CSV-195:
----------------------------------
The test (with the attached file) correctly processes each entry only once
(check the Output) but 'getCurrentLineNumber' produces the wrong result:
{code}
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.csv.bugs;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
public class JiraCsv195Test {
@Test
public void parse() throws IOException {
CSVFormat format = CSVFormat.RFC4180;
//
format = format.withFirstRecordAsHeader();
format = format.withIgnoreEmptyLines();
format = format.withTrim();
//
CSVParser parser = format.parse(getTestInput());
try {
for (CSVRecord record : parser) {
System.out.println(record);
}
Assert.assertEquals(28, parser.getCurrentLineNumber());
} finally {
parser.close();
}
}
private Reader getTestInput() {
final InputStream is =
ClassLoader.getSystemClassLoader().getResourceAsStream("csv-195/whitelist.csv");
return new InputStreamReader(is);
}
}
{code}
> Parser iterates over the last CSV Record twice.
> -----------------------------------------------
>
> Key: CSV-195
> URL: https://issues.apache.org/jira/browse/CSV-195
> Project: Commons CSV
> Issue Type: Bug
> Components: Parser
> Affects Versions: 1.4
> Environment: Mac OS X 10.10.5
> Reporter: Rodolfo Duldulao
> Fix For: Patch Needed
>
> Attachments: whitelist.csv
>
>
> {code:java}
> class CSVParserSpecification extends Specification {
> def "TEst CSVParser"() {
> setup:
> URL url = new URL("https://....../csv_with_28_lines_header_plus_
> 27_records");
> BufferedReader reader = new BufferedReader(new
> InputStreamReader(url.openStream()));
> def CSVParser parser =
> CSVFormat.RFC4180.withFirstRecordAsHeader().withIgnoreEmptyLines().withTrim().parse(reader);
> when:
> def count = 0
> for (CSVRecord record: parser)
> { println("Processing " + parser.getCurrentLineNumber()) count++ }
> println(count);
> parser.close()
> then:
> count == 27
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)