hadoop-common-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tsz Wo Nicholas Sze (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HADOOP-12309) [Refactor] Use java.lang.Throwable.addSuppressed(Throwable) instead of class org.apache.hadoop.io.MultipleIOException
Date Wed, 12 Aug 2015 17:18:46 GMT

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

Tsz Wo Nicholas Sze commented on HADOOP-12309:
----------------------------------------------

{code}
     synchronized void closeAll(boolean onlyAutomatic) throws IOException {
-      List<IOException> exceptions = new ArrayList<IOException>();
+      IOException exceptions = null;
 
       // Make a copy of the keys in the map since we'll be modifying
       // the map while iterating over it, which isn't safe.
@@ -2814,13 +2813,17 @@ synchronized void closeAll(boolean onlyAutomatic) throws IOException
{
             fs.close();
           }
           catch(IOException ioe) {
-            exceptions.add(ioe);
+            if (exceptions == null) {
+              exceptions =
+                  new IOException("Composite Exception. Read suppressed");
+            }
+            exceptions.addSuppressed(ioe);
           }
         }
       }
 
-      if (!exceptions.isEmpty()) {
-        throw MultipleIOException.createIOException(exceptions);
+      if (exceptions != null) {
+        throw exceptions;
       }
     }
{code}
I think we should keep the List<IOException>, add the IOException to the list in catch-block,
and then create and throw IOException at the end.  i.e. only replace throw MultipleIOException.createIOException(exceptions)
with new IOException using addSuppressed.  Otherwise, the stack trace won't be correct.

> [Refactor] Use java.lang.Throwable.addSuppressed(Throwable) instead of class org.apache.hadoop.io.MultipleIOException
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: HADOOP-12309
>                 URL: https://issues.apache.org/jira/browse/HADOOP-12309
>             Project: Hadoop Common
>          Issue Type: Improvement
>            Reporter: Ajith S
>            Assignee: Ajith S
>            Priority: Minor
>         Attachments: HADOOP-12309.patch
>
>
> Can use java.lang.Throwable.addSuppressed(Throwable) instead of org.apache.hadoop.io.MultipleIOException
as 1.7+ java provides support for this. org.apache.hadoop.io.MultipleIOException can be deprecated
as for now
> {code}
> ............
> catch (IOException e) {
>           if(generalException == null)
>           {
>             generalException = new IOException("General exception");
>           }
>           generalException.addSuppressed(e);
>         }
> {code}



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

Mime
View raw message