You are viewing a plain text version of this content. The canonical link for it is here.
Posted to hdfs-dev@hadoop.apache.org by "Ted Yu (JIRA)" <ji...@apache.org> on 2014/08/21 05:50:28 UTC

[jira] [Created] (HDFS-6902) FileWriter should be closed in finally block in BlockReceiver#receiveBlock()

Ted Yu created HDFS-6902:
----------------------------

             Summary: FileWriter should be closed in finally block in BlockReceiver#receiveBlock()
                 Key: HDFS-6902
                 URL: https://issues.apache.org/jira/browse/HDFS-6902
             Project: Hadoop HDFS
          Issue Type: Bug
            Reporter: Ted Yu
            Priority: Minor


Here is code starting from line 828:
{code}
            try {
              FileWriter out = new FileWriter(restartMeta);
              // write out the current time.
              out.write(Long.toString(Time.now() + restartBudget));
              out.flush();
              out.close();
            } catch (IOException ioe) {
{code}
If write() or flush() call throws IOException, out wouldn't be closed.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Re: [jira] [Created] (HDFS-6902) FileWriter should be closed in finally block in BlockReceiver#receiveBlock()

Posted by vlab <Th...@VLab.ca>.
Unless you need 'out' later, have this statement.
FileWriter out(restartMeta);
then when exiting the try block, 'out' will go out of scope

i assume this FileWriter that is create is delete'd else where
(else there is a memory leak).   {but then this code snippet could be 
java and can be messy.}

On 8/20/2014 8:50 PM, Ted Yu (JIRA) wrote:
> Ted Yu created HDFS-6902:
> ----------------------------
>
>               Summary: FileWriter should be closed in finally block in BlockReceiver#receiveBlock()
>                   Key: HDFS-6902
>                   URL: https://issues.apache.org/jira/browse/HDFS-6902
>               Project: Hadoop HDFS
>            Issue Type: Bug
>              Reporter: Ted Yu
>              Priority: Minor
>
>
> Here is code starting from line 828:
> {code}
>              try {
>                FileWriter out = new FileWriter(restartMeta);
>                // write out the current time.
>                out.write(Long.toString(Time.now() + restartBudget));
>                out.flush();
>                out.close();
>              } catch (IOException ioe) {
> {code}
> If write() or flush() call throws IOException, out wouldn't be closed.
>
>
>
> --
> This message was sent by Atlassian JIRA
> (v6.2#6252)
>