6991528: Support making Throwable.suppressedExceptions immutable
authordarcy
Sun, 14 Nov 2010 07:16:46 -0800
changeset 7213 912fdd70fd2a
parent 7212 a3d2fea48d58
child 7214 26dfa4a69593
6991528: Support making Throwable.suppressedExceptions immutable Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java
langtools/src/share/classes/com/sun/tools/javac/util/Names.java
langtools/test/tools/javac/TryWithResources/TwrSuppression.java
langtools/test/tools/javac/TryWithResources/TwrTests.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sat Nov 13 19:00:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Nov 14 07:16:46 2010 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -1509,17 +1509,17 @@
     }
 
     private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) {
-        // primaryException.addSuppressedException(catchException);
+        // primaryException.addSuppressed(catchException);
         VarSymbol catchException =
             new VarSymbol(0, make.paramName(2),
                           syms.throwableType,
                           currentMethodSym);
         JCStatement addSuppressionStatement =
             make.Exec(makeCall(make.Ident(primaryException),
-                               names.fromString("addSuppressedException"),
+                               names.addSuppressed,
                                List.<JCExpression>of(make.Ident(catchException))));
 
-        // try { resource.close(); } catch (e) { primaryException.addSuppressedException(e); }
+        // try { resource.close(); } catch (e) { primaryException.addSuppressed(e); }
         JCBlock tryBlock =
             make.Block(0L, List.<JCStatement>of(makeResourceCloseInvocation(resource)));
         JCVariableDecl catchExceptionDecl = make.VarDef(catchException, null);
--- a/langtools/src/share/classes/com/sun/tools/javac/util/Names.java	Sat Nov 13 19:00:43 2010 -0800
+++ b/langtools/src/share/classes/com/sun/tools/javac/util/Names.java	Sun Nov 14 07:16:46 2010 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -150,6 +150,7 @@
     public final Name finalize;
     public final Name java_lang_AutoCloseable;
     public final Name close;
+    public final Name addSuppressed;
 
     public final Name.Table table;
 
@@ -268,6 +269,7 @@
 
         java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
         close = fromString("close");
+        addSuppressed = fromString("addSuppressed");
     }
 
     protected Name.Table createTable(Options options) {
--- a/langtools/test/tools/javac/TryWithResources/TwrSuppression.java	Sat Nov 13 19:00:43 2010 -0800
+++ b/langtools/test/tools/javac/TryWithResources/TwrSuppression.java	Sun Nov 14 07:16:46 2010 -0800
@@ -36,7 +36,7 @@
                 throw new RuntimeException();
             }
         } catch(RuntimeException e) {
-            Throwable[] suppressedExceptions = e.getSuppressedExceptions();
+            Throwable[] suppressedExceptions = e.getSuppressed();
             int length = suppressedExceptions.length;
             if (length != 2)
                 throw new RuntimeException("Unexpected length " + length);
--- a/langtools/test/tools/javac/TryWithResources/TwrTests.java	Sat Nov 13 19:00:43 2010 -0800
+++ b/langtools/test/tools/javac/TryWithResources/TwrTests.java	Sun Nov 14 07:16:46 2010 -0800
@@ -90,7 +90,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed");
                 }
@@ -112,7 +112,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed");
                 }
@@ -134,7 +134,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -158,7 +158,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -181,7 +181,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -207,7 +207,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -231,7 +231,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -259,7 +259,7 @@
                 } catch (Resource.CreateFailException e) {
                     creationFailuresDetected++;
                     checkCreateFailureId(e.resourceId(), createFailureId);
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     throw new AssertionError("Secondary exception suppression failed:" + e);
                 }
@@ -310,7 +310,7 @@
      * Check for proper suppressed exceptions in proper order.
      *
      * @param suppressedExceptions the suppressed exceptions array returned by
-     *        getSuppressedExceptions()
+     *        getSuppressed()
      * @bitmap a bitmap indicating which suppressed exceptions are expected.
      *         Bit i is set iff id should throw a CloseFailException.
      */
@@ -376,7 +376,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -388,7 +388,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 1);
             }
@@ -409,7 +409,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -421,7 +421,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 2);
             }
@@ -443,7 +443,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -455,7 +455,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 2);
             }
@@ -477,7 +477,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -489,7 +489,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 3);
             }
@@ -513,7 +513,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -525,7 +525,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 3);
             }
@@ -548,7 +548,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -560,7 +560,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 4);
             }
@@ -586,7 +586,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -598,7 +598,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 4);
             }
@@ -621,7 +621,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -633,7 +633,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 5);
             }
@@ -660,7 +660,7 @@
                 } catch (MyKindOfException e) {
                     if (failure == 0)
                         throw new AssertionError("Unexpected MyKindOfException");
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
                 } catch (Resource.CloseFailException e) {
                     if (failure == 1)
                         throw new AssertionError("Secondary exception suppression failed");
@@ -672,7 +672,7 @@
                         throw new AssertionError("CloseFailException: got id " + id
                                                  + ", expected lg(" + highestCloseFailBit +")");
                     }
-                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
+                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
                 }
                 checkClosedList(closedList, 5);
             }