hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uma Maheswara Rao G (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HADOOP-8179) risk of NPE in CopyCommands processArguments()
Date Tue, 20 Mar 2012 14:27:40 GMT

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

Uma Maheswara Rao G commented on HADOOP-8179:
---------------------------------------------

Hi Daryn, Patch mostly looks good. I have other suggestion to do.

{code}
             if (delimiter != null) {
               out.write(delimiter.getBytes("UTF-8"));
             }
-          } finally {
             in.close();
-          }
+	    in = null;
+	  } finally {
+	    IOUtils.closeStream(in);
+	  }
         }
+        out.close();
+	 out = null;
       } finally {
-        out.close();
+	 IOUtils.closeStream(out);
       }      
     }

{code}

closing stream in finally may mask the root exceptions if any exception in finally.
So, i would prefer this pattern to close the streams. Let's close the stream in try itself
and nullify if that is success. We can use IOUtils.closeStream in finally. It won't try to
close the stream if that is null.
                
> risk of NPE in CopyCommands processArguments()
> ----------------------------------------------
>
>                 Key: HADOOP-8179
>                 URL: https://issues.apache.org/jira/browse/HADOOP-8179
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: fs
>    Affects Versions: 0.24.0, 0.23.2
>            Reporter: Steve Loughran
>            Assignee: Daryn Sharp
>            Priority: Minor
>         Attachments: HADOOP-8179.patch, HADOOP-8179.patch
>
>
> My IDE is warning me that the {{is.close()}} method will NPE if the {{is = src.fs.open(src.path);}}
call raises an exception, which could happen if the source path could not be opened. There
should be an if (is!=null) wrapper

--
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

        

Mime
View raw message