blob: d4dbf5bffae3591f020080e682428cbf6ce6e345 [file] [log] [blame]
Denis Vnukovad22ab42018-08-15 11:17:35 -07001// Copyright (c) 2018, 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.
4
5package twrcloseresource;
6
7import java.util.jar.JarFile;
8
9public class TwrCloseResourceTest implements Iface {
10 public static void main(String[] args) {
11 TwrCloseResourceTest o = new TwrCloseResourceTest();
12 o.foo(args[0]);
13 o.iFoo(args[0]);
14 bar(args[0]);
15 Iface.iBar(args[0]);
16 }
17
18 synchronized void foo(String arg) {
19 try {
20 try (JarFile a = new JarFile(arg)) {
21 System.out.println("A");
22 } catch (Exception e) {
23 System.out.println("B");
24 try (JarFile a = new JarFile(arg)) {
25 System.out.println("C");
26 }
27 System.out.println("D");
28 throw new RuntimeException();
29 }
30 try (JarFile a = new JarFile(arg)) {
31 System.out.println("E");
32 }
33 } catch (Exception e) {
34 System.out.println("F");
35 }
36 try (JarFile a = new JarFile(arg)) {
37 System.out.println("G");
38 try (JarFile b = new JarFile(arg)) {
39 System.out.println("H");
40 } finally {
41 System.out.println("I");
42 throw new RuntimeException();
43 }
44 } catch (Exception e) {
45 System.out.println("J");
46 }
47 System.out.println("K");
48 }
49
50 static synchronized void bar(String arg) {
51 try (JarFile a = new JarFile(arg)) {
52 System.out.println("1");
53 throw new RuntimeException();
54 } catch (Exception e) {
55 System.out.println("2");
56 }
57 try (JarFile a = new JarFile(arg)) {
58 System.out.println("3");
59 throw new RuntimeException();
60 } catch (Exception e) {
61 System.out.println("4");
62 }
63 try (JarFile a = new JarFile(arg)) {
64 System.out.println("5");
65 throw new RuntimeException();
66 } catch (Exception e) {
67 System.out.println("6");
68 }
69 try (JarFile a = new JarFile(arg)) {
70 System.out.println("7");
71 throw new RuntimeException();
72 } catch (Exception e) {
73 System.out.println("8");
74 }
75 System.out.println("99");
76 }
77}
78
79interface Iface {
80 default void iFoo(String arg) {
81 try {
82 try (JarFile a = new JarFile(arg)) {
83 System.out.println("iA");
84 } catch (Exception e) {
85 System.out.println("iB");
86 try (JarFile a = new JarFile(arg)) {
87 System.out.println("iC");
88 }
89 System.out.println("iD");
90 throw new RuntimeException();
91 }
92 try (JarFile a = new JarFile(arg)) {
93 System.out.println("iE");
94 }
95 } catch (Exception e) {
96 System.out.println("iF");
97 }
98 try (JarFile a = new JarFile(arg)) {
99 System.out.println("iG");
100 try (JarFile b = new JarFile(arg)) {
101 System.out.println("iH");
102 } finally {
103 System.out.println("iI");
104 throw new RuntimeException();
105 }
106 } catch (Exception e) {
107 System.out.println("iJ");
108 }
109 System.out.println("iK");
110 }
111
112 static void iBar(String arg) {
113 try (JarFile a = new JarFile(arg)) {
114 System.out.println("i1");
115 throw new RuntimeException();
116 } catch (Exception e) {
117 System.out.println("i2");
118 }
119 try (JarFile a = new JarFile(arg)) {
120 System.out.println("i3");
121 throw new RuntimeException();
122 } catch (Exception e) {
123 System.out.println("i4");
124 }
125 try (JarFile a = new JarFile(arg)) {
126 System.out.println("i5");
127 throw new RuntimeException();
128 } catch (Exception e) {
129 System.out.println("i6");
130 }
131 try (JarFile a = new JarFile(arg)) {
132 System.out.println("i7");
133 throw new RuntimeException();
134 } catch (Exception e) {
135 System.out.println("i8");
136 }
137 System.out.println("i99");
138 }
139}