[jira] [Created] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
CSV Parser loops inifinitely if last line starts with a comment char
--------------------------------------------------------------------

                 Key: SANDBOX-406
                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
             Project: Commons Sandbox
          Issue Type: Bug
          Components: CSV
            Reporter: Edgar Philipp


Behaviour:

Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!

Examplary CSV file:

some
# comment OK
line
# comment OK
value
# problematic comment

Excerpt of Java code:

   private static final char COMMENT = '#';
   private static final char QUOTE = '"';
   private static final char SEPARATOR = ';';

   CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
   CSVParser parser = new CSVParser(reader, csvStrategy);

   String[] line = parser.getLine();

   while (line != null) {
      Log.debug("Line: " + line[0]);
      // Do something
      line = parser.getLine();
   }

Used Maven Dependency:

 <dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-commons-csv</artifactId>
    <version>1.4.0</version>
 </dependency>sol


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)

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

Edgar Philipp commented on SANDBOX-406:
---------------------------------------

Sorry, the CSV file got escaped in Wiki syntax.
It looks like this:

\# comment OK
line
\# comment OK
value
\# problematic comment

               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> Excerpt of Java code:
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> Used Maven Dependency:
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>sol

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

     [ https://issues.apache.org/jira/browse/SANDBOX-406?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated SANDBOX-406:
-----------------------------------

           Description:
Behaviour:

Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!

Examplary CSV file:

{code}
some
# comment OK
line
# comment OK
value
# problematic comment
{code}

Excerpt of Java code:

{code:java}
   private static final char COMMENT = '#';
   private static final char QUOTE = '"';
   private static final char SEPARATOR = ';';

   CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
   CSVParser parser = new CSVParser(reader, csvStrategy);

   String[] line = parser.getLine();

   while (line != null) {
      Log.debug("Line: " + line[0]);
      // Do something
      line = parser.getLine();
   }
{code}

Used Maven Dependency:

{code:xml}
 <dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-commons-csv</artifactId>
    <version>1.4.0</version>
 </dependency>
{code}


  was:
Behaviour:

Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!

Examplary CSV file:

some
# comment OK
line
# comment OK
value
# problematic comment

Excerpt of Java code:

   private static final char COMMENT = '#';
   private static final char QUOTE = '"';
   private static final char SEPARATOR = ';';

   CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
   CSVParser parser = new CSVParser(reader, csvStrategy);

   String[] line = parser.getLine();

   while (line != null) {
      Log.debug("Line: " + line[0]);
      // Do something
      line = parser.getLine();
   }

Used Maven Dependency:

 <dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-commons-csv</artifactId>
    <version>1.4.0</version>
 </dependency>sol


    Remaining Estimate:     (was: 24h)
     Original Estimate:     (was: 24h)
   

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Emmanuel Bourg commented on SANDBOX-406:
----------------------------------------

Thank you for the report Edgar. This issue seems specific to the SOLR version of Commons CSV, I ran this test on the current version of Commons CSV on the trunk and it worked fine:
{code}    
StringReader input = new StringReader("# Comment 1\na,b,c\n# Comment 2");
CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#');

for (String[] line : new CSVParser(input, format)) {
    System.out.println("Line: " + Arrays.toString(line));
}
{code}

Could you do another test with this artefact instead? This is a more recent version, you'll have to change your code slightly, the CSVStrategy class has been renamed to CSVFormat.

{code}
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-csv</artifactId>
    <version>1.0-SNAPSHOT</version>
 </dependency>
{code}

This artifact is located in the Apache snapshot repository at http://repository.apache.org/snapshots




               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Edgar Philipp commented on SANDBOX-406:
---------------------------------------

Emmanuel, thank you for the quick reply!

Indeed when using the suggested commons-csv artifact, the problem does not occur any more.
The only think that strikes me is that it is still a snapshot version. When is the release planned?
               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Emmanuel Bourg commented on SANDBOX-406:
----------------------------------------

Glad to hear it works! There is no release date for Commons CSV 1.0, help is welcome to flesh out a rock solid initial release.
               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

     [ https://issues.apache.org/jira/browse/SANDBOX-406?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg resolved SANDBOX-406.
------------------------------------

    Resolution: Duplicate
   

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Edgar Philipp commented on SANDBOX-406:
---------------------------------------

Hmm, I am a bit irritated by the recent change in the constructor visibility of {{CSVFormat(char, char, char)}} from public to package protected:

IMHO it is a bit awkward having to use
{{CSVFormat.DEFAULT.withDelimiter(SEPARATOR).withEncapsulator(QUOTE).withCommentStart(COMMENT);}}
instead of the above constructor.

What is the philosophy behind that change?
 
               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Issue Comment Edited] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Edgar Philipp edited comment on SANDBOX-406 at 3/9/12 9:06 AM:
---------------------------------------------------------------

Hmm, I am a bit irritated by the recent change in the constructor visibility of
{code}
CSVFormat(char, char, char)
{code}
from public to package protected:

IMHO it is a bit awkward having to use
{code}
CSVFormat.DEFAULT.withDelimiter(SEPARATOR).withEncapsulator(QUOTE).withCommentStart(COMMENT);
{code}
instead of the above constructor.

What is the philosophy behind that change?
 
               
      was (Author: edgarphilipp):
    Hmm, I am a bit irritated by the recent change in the constructor visibility of {{CSVFormat(char, char, char)}} from public to package protected:

IMHO it is a bit awkward having to use
{{CSVFormat.DEFAULT.withDelimiter(SEPARATOR).withEncapsulator(QUOTE).withCommentStart(COMMENT);}}
instead of the above constructor.

What is the philosophy behind that change?
 
                 

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Emmanuel Bourg commented on SANDBOX-406:
----------------------------------------

Thank you for the feedback Edgar. I understand this looks unusual, the idea is to provide a fluent API to improve the readability and avoid the proliferation of alternative constructors.

For the reference you can look at these links:
- http://en.wikipedia.org/wiki/Fluent_interface
- http://martinfowler.com/bliki/FluentInterface.html

This pattern is adapted to classes with a lot of optional parameters like CSVFormat, instead of having a constructor for every possible case a base instance is derived to specify the parameters relevant to the use case.

               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (SANDBOX-406) CSV Parser loops inifinitely if last line starts with a comment char

Woonsan Ko (Jira)
In reply to this post by Woonsan Ko (Jira)

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

Edgar Philipp commented on SANDBOX-406:
---------------------------------------

Ok, now I see the point - thanks for the Wiki reference! :-)
Due to Java's lack of named parameters, a fluent API is a better choice.

The language Groovy, for example allows such constructors:

{code}
   new CSVStrategy(separator:';', quote:'"', comment:'#');
{code}

               

> CSV Parser loops inifinitely if last line starts with a comment char
> --------------------------------------------------------------------
>
>                 Key: SANDBOX-406
>                 URL: https://issues.apache.org/jira/browse/SANDBOX-406
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: CSV
>            Reporter: Edgar Philipp
>
> Behaviour:
> Whenever the last non-empty line of the CSV file starts with a comment, the CSVParser loops infinitely!
> Examplary CSV file:
> {code}
> some
> # comment OK
> line
> # comment OK
> value
> # problematic comment
> {code}
> Excerpt of Java code:
> {code:java}
>    private static final char COMMENT = '#';
>    private static final char QUOTE = '"';
>    private static final char SEPARATOR = ';';
>    CSVStrategy csvStrategy = new CSVStrategy(SEPARATOR, QUOTE, COMMENT);
>    CSVParser parser = new CSVParser(reader, csvStrategy);
>    String[] line = parser.getLine();
>    while (line != null) {
>       Log.debug("Line: " + line[0]);
>       // Do something
>       line = parser.getLine();
>    }
> {code}
> Used Maven Dependency:
> {code:xml}
>  <dependency>
>     <groupId>org.apache.solr</groupId>
>     <artifactId>solr-commons-csv</artifactId>
>     <version>1.4.0</version>
>  </dependency>
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira