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

Devaraj K commented on MAPREDUCE-2243:
--------------------------------------

Thanks Nicholas for reviewing.
It is not required to use single try for everything because the block of code 
(given below) which comes in between these two try blocks is not required to 
keep in the try block.
{code:xml}
if (str == null) { //the file doesn't have anything
      throw new IOException ("Index file for the log of " + taskid+" doesn't 
exist.");
    }
    l.location = str.substring(str.indexOf(LogFileDetail.LOCATION)+
        LogFileDetail.LOCATION.length());
    //special cases are the debugout and profile.out files. They are guaranteed
    //to be associated with each task attempt since jvm reuse is disabled
    //when profiling/debugging is enabled
    if (filter.equals(LogName.DEBUGOUT) || filter.equals(LogName.PROFILE)) {
      l.length = new File(l.location, filter.toString()).length();
      l.start = 0;
      fis.close();
      return l;
    }
{code}

Here it has only fis.close(); which deals with streams. If we put fis.close() 
in the try finally, it will try to close it in the try block, if suppose it 
throws IOException, then again it will try to close in the finally and throws 
the exception again. It doesn’t give any difference if we keep in try or don’t 
keep inside try block.


> Close all the file streams propely in a finally block to avoid their leakage.
> -----------------------------------------------------------------------------
>
>                 Key: MAPREDUCE-2243
>                 URL: https://issues.apache.org/jira/browse/MAPREDUCE-2243
>             Project: Hadoop Map/Reduce
>          Issue Type: Improvement
>          Components: jobtracker, tasktracker
>    Affects Versions: 0.22.0, 0.23.0
>         Environment: NA
>            Reporter: Bhallamudi Venkata Siva Kamesh
>            Assignee: Devaraj K
>            Priority: Minor
>             Fix For: 0.23.0
>
>         Attachments: MAPREDUCE-2243-1.patch, MAPREDUCE-2243-2.patch, 
> MAPREDUCE-2243.patch
>
>   Original Estimate: 72h
>  Remaining Estimate: 72h
>
> In the following classes streams should be closed in finally block to avoid 
> their leakage in the exceptional cases.
> CompletedJobStatusStore.java
> ------------------------------------------
>        dataOut.writeInt(events.length);
>         for (TaskCompletionEvent event : events) {
>           event.write(dataOut);
>         }
>        dataOut.close() ;
> EventWriter.java
> ----------------------
>    encoder.flush();
>    out.close();
> MapTask.java
> -------------------
>     splitMetaInfo.write(out);
>      out.close();
> TaskLog
> ------------
>  1) str = fis.readLine();
>       fis.close();
> 2) dos.writeBytes(Long.toString(new File(logLocation, LogName.SYSLOG
>       .toString()).length() - prevLogLength) + "\n");
>     dos.close();
> TotalOrderPartitioner.java
> -----------------------------------
>  while (reader.next(key, value)) {
>             parts.add(key);
>             key = ReflectionUtils.newInstance(keyClass, conf);
>           }
> reader.close();

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to