[ 
https://issues.apache.org/jira/browse/CSV-167?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15123153#comment-15123153
 ] 

Bruno P. Kinoshita commented on CSV-167:
----------------------------------------

Had a look at this issue, in the code and CSV attached, and also in the unit 
test provided.

After debugging the parser, it looks like it may be a feature but not a bug? 
TL;DR: comments are attached to the next valid CSVRecord; three lines with 
comments in a CSV file are treated as a single comment by the parser in [csv].

When the parser finds the find comment, it stores its value and looks for the 
next line, which contains the headers. It generates a CSVRecord with value = 
author,title,publishDate and comment = "Comment before header,,"

Then it reads a line with "Dan Simmons,Hyperion,1989" creating a CSVRecord with 
value = Dan Simmons,Hyperion,1989

But then it finds another comment. So it stores its values, and looks for the 
next line, which is another comment. Here, the parser adds the comment to the 
previous comment with a line feed. And ditto for the next comment. Finally the 
parser finds a line with text Douglas Adams,"The Hitchhiker's \"Guide\" to the 
Galaxy",1979", creating a CSV Record with value = "Douglas Adams,"The 
Hitchhiker's \"Guide\" to the Galaxy",1979, and comment = Comment Line 
1,,LFComment Line 2,,LFComment Line 3,,

Finally it finds the line with Douglas John,"The Hitchhiker's \"Guide\" to the 
Mars",1979.

So I don't believe it is exactly a bug. The parser simply appends any comment 
found to the next line, as an attribute of the CSVRecord.

One note is that if you add a comment to the last line of the file, that 
comment is discarded, as there won't be a CSVRecord to attach the comment to. 

> Comment line hides next record
> ------------------------------
>
>                 Key: CSV-167
>                 URL: https://issues.apache.org/jira/browse/CSV-167
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.2
>            Reporter: Rene
>            Priority: Critical
>         Attachments: CSVProcessor.java, sample1.csv
>
>
> 1. First CSV record after the comment line is not processed at all (record #2 
> and #7)
> 2. Second/Third line after the first comment line are not recognized as 
> comment lines (record #5 and #6)
> See attached example!



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to