blob: fcf0d6f9391e4d426d5841009122d9b661756ada [file] [log] [blame]
Ian Zerny9aafbd52022-04-29 13:15:17 +02001// Copyright (c) 2022, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4package twraddsuppressed;
5
6import java.io.Closeable;
7
8public class TestClass {
9
10 public static class MyClosable implements Closeable {
11
12 @Override
13 public void close() {
14 throw new RuntimeException("CLOSE");
15 }
16 }
17
18 public static void foo() {
19 throw new RuntimeException("FOO");
20 }
21
22 public static void bar() {
Søren Gjesse2fb9d7f2024-10-02 08:59:50 +020023 // NOTE: The $closeResource helper is _only_ generated by the JDK-9 compiler.
24 //
Ian Zerny9aafbd52022-04-29 13:15:17 +020025 // Use twr twice to have javac generate a shared $closeResource helper.
26 try (MyClosable closable = new MyClosable()) {
27 foo();
28 }
29 try (MyClosable closable = new MyClosable()) {
30 foo();
31 }
32 }
33
34 public static void main(String[] args) {
35 try {
36 bar();
37 } catch (Exception e) {
38 Throwable[] suppressed = e.getSuppressed();
39 if (suppressed.length == 0) {
40 System.out.println("NONE");
41 } else {
42 for (Throwable throwable : suppressed) {
43 System.out.println(throwable.getMessage());
44 }
45 }
46 }
47 }
48}