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

Sean Owen commented on MAHOUT-1211:
-----------------------------------

Yeah that's a good point. If two exceptions occur, in Java 7, the initial 
exception would be thrown along with the closing exception attached as 
'suppressed'. So swallowing the exception from close, in the case of a writer 
or anything else, better mimics that behavior. The problem is just that you 
throw 0 exceptions with this approach if the close() fails and not the original 
body. (In Java 7 you would propagate the closing exception.)

I don't know of a solution short of actually copying the complete and complex 
boilerplate code that Java 7 would generate. You have to store and save 
exceptions to be able to check whether a finally block was reach with or 
without error. It's a real mess.

For the meantime, one possible compromise is to log the initial exception and 
then let an exception in close() potentially mask the initial exception. At 
least the initial info is logged, and you do throw an exception in this case, 
which is kind of safer behavior than just continuing.

    try {
      ...
    } catch (IOException ioe) {
      log.warn(..., ioe);
      throw ioe;
    } finally {
      Closeables.close(writer, false);
    }

                
> Replace deprecated Closables.closeQuietly calls
> -----------------------------------------------
>
>                 Key: MAHOUT-1211
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-1211
>             Project: Mahout
>          Issue Type: Improvement
>            Reporter: Stevo Slavic
>            Assignee: Ted Dunning
>            Priority: Minor
>             Fix For: 0.8
>
>         Attachments: MAHOUT-1211.patch
>
>
> Deprecated Guava {{Closables.closeQuietly}} API has to be replaced, it's 
> usage is a code smell, and that method is scheduled to be removed from Guava 
> 16.0.
> See [this 
> discussion|https://code.google.com/p/guava-libraries/issues/detail?id=1118] 
> for more info.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to