6991528: Support making Throwable.suppressedExceptions immutable

Sun, 14 Nov 2010 07:16:46 -0800

author
darcy
date
Sun, 14 Nov 2010 07:16:46 -0800
changeset 745
4328728e0409
parent 744
a7faadc252c8
child 746
a7ea58fa3e9a

6991528: Support making Throwable.suppressedExceptions immutable
Reviewed-by: mcimadamore

src/share/classes/com/sun/tools/javac/comp/Lower.java file | annotate | diff | comparison | revisions
src/share/classes/com/sun/tools/javac/util/Names.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrSuppression.java file | annotate | diff | comparison | revisions
test/tools/javac/TryWithResources/TwrTests.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sat Nov 13 19:00:43 2010 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java	Sun Nov 14 07:16:46 2010 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -1509,17 +1509,17 @@
    1.11      }
    1.12  
    1.13      private JCBlock makeArmFinallyClause(Symbol primaryException, JCExpression resource) {
    1.14 -        // primaryException.addSuppressedException(catchException);
    1.15 +        // primaryException.addSuppressed(catchException);
    1.16          VarSymbol catchException =
    1.17              new VarSymbol(0, make.paramName(2),
    1.18                            syms.throwableType,
    1.19                            currentMethodSym);
    1.20          JCStatement addSuppressionStatement =
    1.21              make.Exec(makeCall(make.Ident(primaryException),
    1.22 -                               names.fromString("addSuppressedException"),
    1.23 +                               names.addSuppressed,
    1.24                                 List.<JCExpression>of(make.Ident(catchException))));
    1.25  
    1.26 -        // try { resource.close(); } catch (e) { primaryException.addSuppressedException(e); }
    1.27 +        // try { resource.close(); } catch (e) { primaryException.addSuppressed(e); }
    1.28          JCBlock tryBlock =
    1.29              make.Block(0L, List.<JCStatement>of(makeResourceCloseInvocation(resource)));
    1.30          JCVariableDecl catchExceptionDecl = make.VarDef(catchException, null);
     2.1 --- a/src/share/classes/com/sun/tools/javac/util/Names.java	Sat Nov 13 19:00:43 2010 -0800
     2.2 +++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Sun Nov 14 07:16:46 2010 -0800
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
     2.6 + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
     2.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.8   *
     2.9   * This code is free software; you can redistribute it and/or modify it
    2.10 @@ -150,6 +150,7 @@
    2.11      public final Name finalize;
    2.12      public final Name java_lang_AutoCloseable;
    2.13      public final Name close;
    2.14 +    public final Name addSuppressed;
    2.15  
    2.16      public final Name.Table table;
    2.17  
    2.18 @@ -268,6 +269,7 @@
    2.19  
    2.20          java_lang_AutoCloseable = fromString("java.lang.AutoCloseable");
    2.21          close = fromString("close");
    2.22 +        addSuppressed = fromString("addSuppressed");
    2.23      }
    2.24  
    2.25      protected Name.Table createTable(Options options) {
     3.1 --- a/test/tools/javac/TryWithResources/TwrSuppression.java	Sat Nov 13 19:00:43 2010 -0800
     3.2 +++ b/test/tools/javac/TryWithResources/TwrSuppression.java	Sun Nov 14 07:16:46 2010 -0800
     3.3 @@ -36,7 +36,7 @@
     3.4                  throw new RuntimeException();
     3.5              }
     3.6          } catch(RuntimeException e) {
     3.7 -            Throwable[] suppressedExceptions = e.getSuppressedExceptions();
     3.8 +            Throwable[] suppressedExceptions = e.getSuppressed();
     3.9              int length = suppressedExceptions.length;
    3.10              if (length != 2)
    3.11                  throw new RuntimeException("Unexpected length " + length);
     4.1 --- a/test/tools/javac/TryWithResources/TwrTests.java	Sat Nov 13 19:00:43 2010 -0800
     4.2 +++ b/test/tools/javac/TryWithResources/TwrTests.java	Sun Nov 14 07:16:46 2010 -0800
     4.3 @@ -90,7 +90,7 @@
     4.4                  } catch (Resource.CreateFailException e) {
     4.5                      creationFailuresDetected++;
     4.6                      checkCreateFailureId(e.resourceId(), createFailureId);
     4.7 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
     4.8 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
     4.9                  } catch (Resource.CloseFailException e) {
    4.10                      throw new AssertionError("Secondary exception suppression failed");
    4.11                  }
    4.12 @@ -112,7 +112,7 @@
    4.13                  } catch (Resource.CreateFailException e) {
    4.14                      creationFailuresDetected++;
    4.15                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.16 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.17 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.18                  } catch (Resource.CloseFailException e) {
    4.19                      throw new AssertionError("Secondary exception suppression failed");
    4.20                  }
    4.21 @@ -134,7 +134,7 @@
    4.22                  } catch (Resource.CreateFailException e) {
    4.23                      creationFailuresDetected++;
    4.24                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.25 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.26 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.27                  } catch (Resource.CloseFailException e) {
    4.28                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.29                  }
    4.30 @@ -158,7 +158,7 @@
    4.31                  } catch (Resource.CreateFailException e) {
    4.32                      creationFailuresDetected++;
    4.33                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.34 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.35 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.36                  } catch (Resource.CloseFailException e) {
    4.37                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.38                  }
    4.39 @@ -181,7 +181,7 @@
    4.40                  } catch (Resource.CreateFailException e) {
    4.41                      creationFailuresDetected++;
    4.42                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.43 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.44 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.45                  } catch (Resource.CloseFailException e) {
    4.46                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.47                  }
    4.48 @@ -207,7 +207,7 @@
    4.49                  } catch (Resource.CreateFailException e) {
    4.50                      creationFailuresDetected++;
    4.51                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.52 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.53 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.54                  } catch (Resource.CloseFailException e) {
    4.55                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.56                  }
    4.57 @@ -231,7 +231,7 @@
    4.58                  } catch (Resource.CreateFailException e) {
    4.59                      creationFailuresDetected++;
    4.60                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.61 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.62 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.63                  } catch (Resource.CloseFailException e) {
    4.64                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.65                  }
    4.66 @@ -259,7 +259,7 @@
    4.67                  } catch (Resource.CreateFailException e) {
    4.68                      creationFailuresDetected++;
    4.69                      checkCreateFailureId(e.resourceId(), createFailureId);
    4.70 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.71 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.72                  } catch (Resource.CloseFailException e) {
    4.73                      throw new AssertionError("Secondary exception suppression failed:" + e);
    4.74                  }
    4.75 @@ -310,7 +310,7 @@
    4.76       * Check for proper suppressed exceptions in proper order.
    4.77       *
    4.78       * @param suppressedExceptions the suppressed exceptions array returned by
    4.79 -     *        getSuppressedExceptions()
    4.80 +     *        getSuppressed()
    4.81       * @bitmap a bitmap indicating which suppressed exceptions are expected.
    4.82       *         Bit i is set iff id should throw a CloseFailException.
    4.83       */
    4.84 @@ -376,7 +376,7 @@
    4.85                  } catch (MyKindOfException e) {
    4.86                      if (failure == 0)
    4.87                          throw new AssertionError("Unexpected MyKindOfException");
    4.88 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
    4.89 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
    4.90                  } catch (Resource.CloseFailException e) {
    4.91                      if (failure == 1)
    4.92                          throw new AssertionError("Secondary exception suppression failed");
    4.93 @@ -388,7 +388,7 @@
    4.94                          throw new AssertionError("CloseFailException: got id " + id
    4.95                                                   + ", expected lg(" + highestCloseFailBit +")");
    4.96                      }
    4.97 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
    4.98 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
    4.99                  }
   4.100                  checkClosedList(closedList, 1);
   4.101              }
   4.102 @@ -409,7 +409,7 @@
   4.103                  } catch (MyKindOfException e) {
   4.104                      if (failure == 0)
   4.105                          throw new AssertionError("Unexpected MyKindOfException");
   4.106 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.107 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.108                  } catch (Resource.CloseFailException e) {
   4.109                      if (failure == 1)
   4.110                          throw new AssertionError("Secondary exception suppression failed");
   4.111 @@ -421,7 +421,7 @@
   4.112                          throw new AssertionError("CloseFailException: got id " + id
   4.113                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.114                      }
   4.115 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.116 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.117                  }
   4.118                  checkClosedList(closedList, 2);
   4.119              }
   4.120 @@ -443,7 +443,7 @@
   4.121                  } catch (MyKindOfException e) {
   4.122                      if (failure == 0)
   4.123                          throw new AssertionError("Unexpected MyKindOfException");
   4.124 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.125 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.126                  } catch (Resource.CloseFailException e) {
   4.127                      if (failure == 1)
   4.128                          throw new AssertionError("Secondary exception suppression failed");
   4.129 @@ -455,7 +455,7 @@
   4.130                          throw new AssertionError("CloseFailException: got id " + id
   4.131                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.132                      }
   4.133 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.134 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.135                  }
   4.136                  checkClosedList(closedList, 2);
   4.137              }
   4.138 @@ -477,7 +477,7 @@
   4.139                  } catch (MyKindOfException e) {
   4.140                      if (failure == 0)
   4.141                          throw new AssertionError("Unexpected MyKindOfException");
   4.142 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.143 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.144                  } catch (Resource.CloseFailException e) {
   4.145                      if (failure == 1)
   4.146                          throw new AssertionError("Secondary exception suppression failed");
   4.147 @@ -489,7 +489,7 @@
   4.148                          throw new AssertionError("CloseFailException: got id " + id
   4.149                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.150                      }
   4.151 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.152 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.153                  }
   4.154                  checkClosedList(closedList, 3);
   4.155              }
   4.156 @@ -513,7 +513,7 @@
   4.157                  } catch (MyKindOfException e) {
   4.158                      if (failure == 0)
   4.159                          throw new AssertionError("Unexpected MyKindOfException");
   4.160 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.161 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.162                  } catch (Resource.CloseFailException e) {
   4.163                      if (failure == 1)
   4.164                          throw new AssertionError("Secondary exception suppression failed");
   4.165 @@ -525,7 +525,7 @@
   4.166                          throw new AssertionError("CloseFailException: got id " + id
   4.167                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.168                      }
   4.169 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.170 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.171                  }
   4.172                  checkClosedList(closedList, 3);
   4.173              }
   4.174 @@ -548,7 +548,7 @@
   4.175                  } catch (MyKindOfException e) {
   4.176                      if (failure == 0)
   4.177                          throw new AssertionError("Unexpected MyKindOfException");
   4.178 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.179 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.180                  } catch (Resource.CloseFailException e) {
   4.181                      if (failure == 1)
   4.182                          throw new AssertionError("Secondary exception suppression failed");
   4.183 @@ -560,7 +560,7 @@
   4.184                          throw new AssertionError("CloseFailException: got id " + id
   4.185                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.186                      }
   4.187 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.188 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.189                  }
   4.190                  checkClosedList(closedList, 4);
   4.191              }
   4.192 @@ -586,7 +586,7 @@
   4.193                  } catch (MyKindOfException e) {
   4.194                      if (failure == 0)
   4.195                          throw new AssertionError("Unexpected MyKindOfException");
   4.196 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.197 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.198                  } catch (Resource.CloseFailException e) {
   4.199                      if (failure == 1)
   4.200                          throw new AssertionError("Secondary exception suppression failed");
   4.201 @@ -598,7 +598,7 @@
   4.202                          throw new AssertionError("CloseFailException: got id " + id
   4.203                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.204                      }
   4.205 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.206 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.207                  }
   4.208                  checkClosedList(closedList, 4);
   4.209              }
   4.210 @@ -621,7 +621,7 @@
   4.211                  } catch (MyKindOfException e) {
   4.212                      if (failure == 0)
   4.213                          throw new AssertionError("Unexpected MyKindOfException");
   4.214 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.215 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.216                  } catch (Resource.CloseFailException e) {
   4.217                      if (failure == 1)
   4.218                          throw new AssertionError("Secondary exception suppression failed");
   4.219 @@ -633,7 +633,7 @@
   4.220                          throw new AssertionError("CloseFailException: got id " + id
   4.221                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.222                      }
   4.223 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.224 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.225                  }
   4.226                  checkClosedList(closedList, 5);
   4.227              }
   4.228 @@ -660,7 +660,7 @@
   4.229                  } catch (MyKindOfException e) {
   4.230                      if (failure == 0)
   4.231                          throw new AssertionError("Unexpected MyKindOfException");
   4.232 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap);
   4.233 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap);
   4.234                  } catch (Resource.CloseFailException e) {
   4.235                      if (failure == 1)
   4.236                          throw new AssertionError("Secondary exception suppression failed");
   4.237 @@ -672,7 +672,7 @@
   4.238                          throw new AssertionError("CloseFailException: got id " + id
   4.239                                                   + ", expected lg(" + highestCloseFailBit +")");
   4.240                      }
   4.241 -                    checkSuppressedExceptions(e.getSuppressedExceptions(), bitMap & ~highestCloseFailBit);
   4.242 +                    checkSuppressedExceptions(e.getSuppressed(), bitMap & ~highestCloseFailBit);
   4.243                  }
   4.244                  checkClosedList(closedList, 5);
   4.245              }

mercurial