commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gary Gregory (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (CSV-197) CSVParser doesn't close the underlying handle after iteration
Date Sat, 24 Sep 2016 18:31:20 GMT

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

Gary Gregory edited comment on CSV-197 at 9/24/16 6:31 PM:
-----------------------------------------------------------

The parser implements close() which calls close() on the lexer which closes() the reader.

So all you have to do is manage the parser in a try-with-resources block:

{code:java}
  try (final CSVParser parser = CSVParser.parse(...)) {
    ...
  }
{code}




was (Author: garydgregory):
The parser implements close() which calls close() on the lexer which closes() the reader.

So all you have to do is manage the parser in a try-with-resources block:

{code:java}
  try (final CSVParser parser = CSVParser.parse(...)) {
  ...
  }
{code}



> CSVParser doesn't close the underlying handle after iteration
> -------------------------------------------------------------
>
>                 Key: CSV-197
>                 URL: https://issues.apache.org/jira/browse/CSV-197
>             Project: Commons CSV
>          Issue Type: Bug
>          Components: Parser
>            Reporter: Prateek Rungta
>            Priority: Minor
>             Fix For: Patch Needed, Discussion, 1.4.1
>
>
> The following code leaks file handles:
> {code}
> CSVParser parser = // setup parser
> for (CSVRecord rec: parser) {
> }
> // leak
> {code}
> I'd expect the underlying iterator to close() if it's finished iterating. 



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

Mime
View raw message