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

Varun Saxena commented on YARN-2937:
------------------------------------

[~zjshen], yes I had got your point. What I meant was that this code is 
essentially like under :
{code}
    PrintWriter pw = null;
     try {
      File file = new File(path + "/" + param);
      Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
      pw = new PrintWriter(w);
      pw.write(value);
     } catch (IOException e) {
       throw new IOException("Unable to set " + param + "=" + value +
           " for cgroup at: " + path, e);
     } finally {
      if (pw != null) {
        pw.close();
        if(pw.checkError()) {
          LOG.warn("Error while closing cgroup file " + path);
         }
       }
     }
{code}
As you can see {{pw.close()}} is in finally block. If we throw an exception 
from finally block, it may mask original IOException(if thrown from code 
preceding finally block. AFAIK, this is not a good practice. Correct me if I am 
wrong. 

Even before this patch, code was like below. Here we catch the exception in 
finally block and print a WARN log. The reason I checked for 
{{PrintWriter#checkError}} and printed a WARN log was to keep the behavior 
consistent with earlier code.
{code}
     try {
      f = new FileWriter(path + "/" + param, false);
      f.write(value);
     } catch (IOException e) {
       throw new IOException("Unable to set " + param + "=" + value +
           " for cgroup at: " + path, e);
     } finally {
      if (f != null) {
        try {
          f.close();
        } catch (IOException e) {
          LOG.warn("Unable to close cgroup file: " +
              path, e);
         }
       }
     }
{code}
  
Let me know your opinion.


> Fix new findbugs warnings in hadoop-yarn-nodemanager
> ----------------------------------------------------
>
>                 Key: YARN-2937
>                 URL: https://issues.apache.org/jira/browse/YARN-2937
>             Project: Hadoop YARN
>          Issue Type: Improvement
>            Reporter: Varun Saxena
>            Assignee: Varun Saxena
>             Fix For: 2.7.0
>
>         Attachments: YARN-2937.001.patch, YARN-2937.002.patch, 
> YARN-2937.003.patch, YARN-2937.004.patch, YARN-2937.005.patch
>
>




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

Reply via email to