1 /*******************************************************************************
2 * Copyright (c) 2011, 2018 IBM Corporation and others.
3 *
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
8 *
9 * SPDX-License-Identifier: EPL-2.0
10 *
11 * Contributors:
12 * IBM Corporation - initial API and implementation
13 * Stephan Herrmann - Contributions for
14 * bug 358827 - [1.7] exception analysis for t-w-r spoils null analysis
15 * bug 349326 - [1.7] new warning for missing try-with-resources
16 * bug 359334 - Analysis for resource leak warnings does not consider exceptions as method exit points
17 *******************************************************************************/
18 package org.eclipse.jdt.core.tests.compiler.regression;
19
20 import java.io.File;
21 import java.util.Map;
22
23 import junit.framework.Test;
24
25 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
26
27 @SuppressWarnings({ "unchecked", "rawtypes" })
28 public class TryWithResourcesStatementTest extends AbstractRegressionTest {
29
30 static {
31 // TESTS_NAMES = new String[] { "test380112e"};
32 // TESTS_NUMBERS = new int[] { 50 };
33 // TESTS_RANGE = new int[] { 11, -1 };
34 }
TryWithResourcesStatementTest(String name)35 public TryWithResourcesStatementTest(String name) {
36 super(name);
37 }
suite()38 public static Test suite() {
39 return buildMinimalComplianceTestSuite(testClass(), F_1_7);
40 }
41 // Test resource type related errors
test001()42 public void test001() {
43 this.runNegativeTest(
44 new String[] {
45 "X.java",
46 "public class X {\n" +
47 " public void method1(){\n" +
48 " try (int i = 0) {\n" +
49 " System.out.println();\n" +
50 " }\n" +
51 " }\n" +
52 "}\n",
53 },
54 "----------\n" +
55 "1. ERROR in X.java (at line 3)\n" +
56 " try (int i = 0) {\n" +
57 " ^^^\n" +
58 "The resource type int does not implement java.lang.AutoCloseable\n" +
59 "----------\n");
60 }
61 // Test resource type related errors
test002()62 public void test002() {
63 this.runNegativeTest(
64 new String[] {
65 "X.java",
66 "public class X {\n" +
67 " public void method1(){\n" +
68 " try (int[] tab = {}) {\n" +
69 " System.out.println();\n" +
70 " }\n" +
71 " }\n" +
72 "}\n",
73 },
74 "----------\n" +
75 "1. ERROR in X.java (at line 3)\n" +
76 " try (int[] tab = {}) {\n" +
77 " ^^^^^\n" +
78 "The resource type int[] does not implement java.lang.AutoCloseable\n" +
79 "----------\n");
80 }
81 // Test that resource type could be interface type.
test003()82 public void test003() {
83 this.runNegativeTest(
84 new String[] {
85 "X.java",
86 "public class X implements AutoCloseable{\n" +
87 " public void method1(){\n" +
88 " try (AutoCloseable a = new X()) {\n" +
89 " System.out.println();\n" +
90 " }\n" +
91 " }\n" +
92 "}\n",
93 },
94 "----------\n" +
95 "1. ERROR in X.java (at line 1)\n" +
96 " public class X implements AutoCloseable{\n" +
97 " ^\n" +
98 "The type X must implement the inherited abstract method AutoCloseable.close()\n" +
99 "----------\n" +
100 "2. ERROR in X.java (at line 3)\n" +
101 " try (AutoCloseable a = new X()) {\n" +
102 " ^\n" +
103 "Unhandled exception type Exception thrown by automatic close() invocation on a\n" +
104 "----------\n");
105 }
106 // Type resource type related errors
test003a()107 public void test003a() {
108 this.runNegativeTest(
109 new String[] {
110 "X.java",
111 "public class X {\n" +
112 " public void method1(){\n" +
113 " try (Y y = new Y()) { \n" +
114 " System.out.println();\n" +
115 " } catch (Exception e) {\n" +
116 " } finally {\n" +
117 " Zork z;\n" +
118 " }\n" +
119 " }\n" +
120 "}\n" +
121 "class Y implements Managed {\n" +
122 " public void close () throws Exception {\n" +
123 " }\n" +
124 "}\n" +
125 "interface Managed extends AutoCloseable {}\n",
126 },
127 "----------\n" +
128 "1. ERROR in X.java (at line 7)\n" +
129 " Zork z;\n" +
130 " ^^^^\n" +
131 "Zork cannot be resolved to a type\n" +
132 "----------\n");
133 }
134 // Scope, visibility related tests.
test004()135 public void test004() {
136 this.runNegativeTest(
137 new String[] {
138 "X.java",
139 "import java.io.*;\n" +
140 "public class X {\n" +
141 " public static void main(String[] args) throws IOException {\n" +
142 " int i = 0;\n" +
143 " try (LineNumberReader reader = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" +
144 " String s;\n" +
145 " int i = 0;\n" +
146 " while ((s = reader.readLine()) != null) {\n" +
147 " System.out.println(s);\n" +
148 " i++;\n" +
149 " }\n" +
150 " System.out.println(\"\" + i + \" lines\");\n" +
151 " }\n" +
152 " }\n" +
153 "}",
154 },
155 "----------\n" +
156 "1. ERROR in X.java (at line 7)\n" +
157 " int i = 0;\n" +
158 " ^\n" +
159 "Duplicate local variable i\n" +
160 "----------\n");
161 }
162 //Scope, visibility related tests.
test004a()163 public void test004a() {
164 this.runNegativeTest(
165 new String[] {
166 "X.java",
167 "import java.io.*;\n" +
168 "public class X {\n" +
169 " public static void main(String[] args) throws IOException {\n" +
170 " try (LineNumberReader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" +
171 " String s;\n" +
172 " int r = 0;\n" +
173 " while ((s = r.readLine()) != null) {\n" +
174 " System.out.println(s);\n" +
175 " r++;\n" +
176 " }\n" +
177 " System.out.println(\"\" + r + \" lines\");\n" +
178 " }\n" +
179 " }\n" +
180 "}",
181 },
182 "----------\n" +
183 "1. ERROR in X.java (at line 6)\n" +
184 " int r = 0;\n" +
185 " ^\n" +
186 "Duplicate local variable r\n" +
187 "----------\n" +
188 "2. ERROR in X.java (at line 7)\n" +
189 " while ((s = r.readLine()) != null) {\n" +
190 " ^^^^^^^^^^^^\n" +
191 "Cannot invoke readLine() on the primitive type int\n" +
192 "----------\n");
193 }
194 // check that resources are implicitly final
test005()195 public void test005() {
196 this.runNegativeTest(
197 new String[] {
198 "X.java",
199 "import java.io.*;\n" +
200 "public class X {\n" +
201 " public static void main(String[] args) throws IOException {\n" +
202 " try (Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" +
203 " r = new FileReader(args[0]);\n" +
204 " }\n" +
205 " }\n" +
206 "}",
207 },
208 "----------\n" +
209 "1. ERROR in X.java (at line 5)\n" +
210 " r = new FileReader(args[0]);\n" +
211 " ^\n" +
212 "The resource r of a try-with-resources statement cannot be assigned\n" +
213 "----------\n");
214 }
215 //check that try statement can be empty
test006()216 public void test006() {
217 this.runNegativeTest( // cannot be a conform test as this triggers an AIOOB.
218 new String[] {
219 "X.java",
220 "import java.io.*;\n" +
221 "public class X {\n" +
222 " public static void main(String[] args) throws IOException {\n" +
223 " try (Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" +
224 " } catch(Zork z) {" +
225 " }\n" +
226 " }\n" +
227 "}",
228 },
229 "----------\n" +
230 "1. ERROR in X.java (at line 5)\n" +
231 " } catch(Zork z) { }\n" +
232 " ^^^^\n" +
233 "Zork cannot be resolved to a type\n" +
234 "----------\n");
235 }
236 //check that resources are implicitly final but they can be explicitly final
test007()237 public void test007() {
238 this.runNegativeTest(
239 new String[] {
240 "X.java",
241 "import java.io.*;\n" +
242 "public class X {\n" +
243 " public static void main(String[] args) throws IOException {\n" +
244 " try (final Reader r = new LineNumberReader(new BufferedReader(new FileReader(args[0])))) {\n" +
245 " r = new FileReader(args[0]);\n" +
246 " }\n" +
247 " }\n" +
248 "}",
249 },
250 "----------\n" +
251 "1. ERROR in X.java (at line 5)\n" +
252 " r = new FileReader(args[0]);\n" +
253 " ^\n" +
254 "The resource r of a try-with-resources statement cannot be assigned\n" +
255 "----------\n");
256 }
257 // resource type tests
test008()258 public void test008() {
259 this.runNegativeTest(
260 new String[] {
261 "X.java",
262 "public class X {\n" +
263 " public void method1(){\n" +
264 " try (Y [] i = null) {\n" +
265 " System.out.println();\n" +
266 " }\n" +
267 " }\n" +
268 "}\n" +
269 "class Y implements AutoCloseable {\n" +
270 " public void close () {}\n" +
271 "}",
272 },
273 "----------\n" +
274 "1. ERROR in X.java (at line 3)\n" +
275 " try (Y [] i = null) {\n" +
276 " ^^^^\n" +
277 "The resource type Y[] does not implement java.lang.AutoCloseable\n" +
278 "----------\n");
279 }
280 // Resource Type tests
test009()281 public void test009() {
282 this.runNegativeTest(
283 new String[] {
284 "X.java",
285 "public class X {\n" +
286 " public void method1(){\n" +
287 " try (Y i [] = null) {\n" +
288 " System.out.println();\n" +
289 " }\n" +
290 " }\n" +
291 "}\n" +
292 "class Y implements AutoCloseable {\n" +
293 " public void close () {}\n" +
294 "}",
295 },
296 "----------\n" +
297 "1. ERROR in X.java (at line 3)\n" +
298 " try (Y i [] = null) {\n" +
299 " ^\n" +
300 "The resource type Y[] does not implement java.lang.AutoCloseable\n" +
301 "----------\n");
302 }
303 // Scope, visibility tests
test010()304 public void test010() {
305 this.runNegativeTest(
306 new String[] {
307 "X.java",
308 "public class X {\n" +
309 " public void method1(int p){\n" +
310 " int k;\n" +
311 " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
312 " System.out.println();\n" +
313 " }\n" +
314 " }\n" +
315 "}\n" +
316 "class Y implements AutoCloseable {\n" +
317 " public void close () {}\n" +
318 "}",
319 },
320 "----------\n" +
321 "1. ERROR in X.java (at line 4)\n" +
322 " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
323 " ^\n" +
324 "Duplicate local variable i\n" +
325 "----------\n" +
326 "2. ERROR in X.java (at line 4)\n" +
327 " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
328 " ^\n" +
329 "Duplicate local variable p\n" +
330 "----------\n" +
331 "3. ERROR in X.java (at line 4)\n" +
332 " try (Y i = new Y(); Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
333 " ^\n" +
334 "Duplicate local variable k\n" +
335 "----------\n");
336 }
337 // Scope, visibility tests
test011()338 public void test011() {
339 this.runNegativeTest(
340 new String[] {
341 "X.java",
342 "public class X {\n" +
343 " public void method1(){\n" +
344 " try (Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
345 " System.out.println();\n" +
346 " }\n" +
347 " catch (Exception e) {\n" +
348 " System.out.println(i);\n" +
349 " }\n" +
350 " finally {\n" +
351 " System.out.println(p);\n" +
352 " }\n" +
353 " }\n" +
354 "}\n" +
355 "class Y implements AutoCloseable {\n" +
356 " public void close () {}\n" +
357 "}",
358 },
359 "----------\n" +
360 "1. ERROR in X.java (at line 7)\n" +
361 " System.out.println(i);\n" +
362 " ^\n" +
363 "i cannot be resolved to a variable\n" +
364 "----------\n" +
365 "2. ERROR in X.java (at line 10)\n" +
366 " System.out.println(p);\n" +
367 " ^\n" +
368 "p cannot be resolved to a variable\n" +
369 "---" +
370 "-------\n");
371 }
372 // Scope, visibility related tests.
test012()373 public void test012() {
374 this.runNegativeTest(
375 new String[] {
376 "X.java",
377 "public class X {\n" +
378 " public void method1(){\n" +
379 " try (Y i = new Y(); Y p = new Y(); Y k = new Y();) {\n" +
380 " try {\n" +
381 " System.out.println();\n" +
382 " } catch (Exception i) {\n" +
383 " }\n" +
384 " }\n" +
385 " catch (Exception e) {\n" +
386 " System.out.println(i);\n" +
387 " }\n" +
388 " finally {\n" +
389 " System.out.println(p);\n" +
390 " }\n" +
391 " }\n" +
392 "}\n" +
393 "class Y implements AutoCloseable {\n" +
394 " public void close () {}\n" +
395 "}",
396 },
397 "----------\n" +
398 "1. ERROR in X.java (at line 6)\n" +
399 " } catch (Exception i) {\n" +
400 " ^\n" +
401 "Duplicate parameter i\n" +
402 "----------\n" +
403 "2. ERROR in X.java (at line 10)\n" +
404 " System.out.println(i);\n" +
405 " ^\n" +
406 "i cannot be resolved to a variable\n" +
407 "----------\n" +
408 "3. ERROR in X.java (at line 13)\n" +
409 " System.out.println(p);\n" +
410 " ^\n" +
411 "p cannot be resolved to a variable\n" +
412 "----------\n");
413 }
414 // Shadowing behavior tests
test013()415 public void test013() {
416 this.runNegativeTest(
417 new String[] {
418 "X.java",
419 "public class X {\n" +
420 " public static void main(String [] args) {\n" +
421 " try (Y y = new Y(); Y p = new Y()) {\n" +
422 " X x = new X() {\n" +
423 " public void foo(int p) {\n" +
424 " try {\n" +
425 " System.out.println();\n" +
426 " } catch (Exception y) {\n" +
427 " }\n" +
428 " }\n" +
429 " };\n" +
430 " } finally {\n" +
431 " System.out.println(y);\n" +
432 " }\n" +
433 " }\n" +
434 "}\n" +
435 "\n" +
436 "class Y implements AutoCloseable {\n" +
437 " public void close() {\n" +
438 " System.out.println();\n" +
439 " }\n" +
440 "}\n",
441 },
442 "----------\n" +
443 "1. WARNING in X.java (at line 5)\n" +
444 " public void foo(int p) {\n" +
445 " ^\n" +
446 "The parameter p is hiding another local variable defined in an enclosing scope\n" +
447 "----------\n" +
448 "2. WARNING in X.java (at line 8)\n" +
449 " } catch (Exception y) {\n" +
450 " ^\n" +
451 "The parameter y is hiding another local variable defined in an enclosing scope\n" +
452 "----------\n" +
453 "3. ERROR in X.java (at line 13)\n" +
454 " System.out.println(y);\n" +
455 " ^\n" +
456 "y cannot be resolved to a variable\n" +
457 "----------\n");
458 }
459 // Test for unhandled exceptions
test014()460 public void test014() {
461 Map options = getCompilerOptions();
462 options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING);
463 this.runNegativeTest(
464 new String[] {
465 "X.java",
466 "public class X {\n" +
467 " public static void main(String [] args) { \n" +
468 " try (Y y = new Y();) {\n" +
469 " if (y == null) {}\n" +
470 " Y why = new Y();\n" +
471 " System.out.println(\"Try block\");\n" +
472 " } finally {\n" +
473 " System.out.println(\"Finally block\");\n" +
474 " }\n" +
475 " }\n" +
476 "} \n" +
477 "\n" +
478 "class Y implements AutoCloseable {\n" +
479 " public Y() throws WeirdException {\n" +
480 " throw new WeirdException();\n" +
481 " }\n" +
482 " public void close() {\n" +
483 " System.out.println(\"Closing resource\");\n" +
484 " }\n" +
485 "}\n" +
486 "\n" +
487 "class WeirdException extends Throwable {}\n",
488 },
489 "----------\n" +
490 "1. ERROR in X.java (at line 3)\n" +
491 " try (Y y = new Y();) {\n" +
492 " ^^^^^^^\n" +
493 "Unhandled exception type WeirdException\n" +
494 "----------\n" +
495 "2. WARNING in X.java (at line 4)\n" +
496 " if (y == null) {}\n" +
497 " ^^\n" +
498 "Dead code\n" +
499 "----------\n" +
500 "3. WARNING in X.java (at line 5)\n" +
501 " Y why = new Y();\n" +
502 " ^^^\n" +
503 "Resource leak: 'why' is never closed\n" +
504 "----------\n" +
505 "4. ERROR in X.java (at line 5)\n" +
506 " Y why = new Y();\n" +
507 " ^^^^^^^\n" +
508 "Unhandled exception type WeirdException\n" +
509 "----------\n" +
510 "5. WARNING in X.java (at line 22)\n" +
511 " class WeirdException extends Throwable {}\n" +
512 " ^^^^^^^^^^^^^^\n" +
513 "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" +
514 "----------\n",
515 null, true, options);
516 }
517 // Resource nullness tests
test015()518 public void test015() {
519 Runner runner = new Runner();
520 runner.testFiles =
521 new String[] {
522 "X.java",
523 "public class X {\n" +
524 " public static void main(String [] args) { \n" +
525 " try (Y y = new Y();) {\n" +
526 " if (y == null)\n" +
527 " {}\n" +
528 " }\n" +
529 " }\n" +
530 "} \n" +
531 "\n" +
532 "class Y implements AutoCloseable {\n" +
533 " public void close() {\n" +
534 " }\n" +
535 "}\n"
536 };
537 runner.expectedCompilerLog =
538 "----------\n" +
539 "1. WARNING in X.java (at line 5)\n" +
540 " {}\n" +
541 " ^^\n" +
542 "Dead code\n" +
543 "----------\n";
544 runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
545 runner.runWarningTest();
546 }
547 // Dead code tests, resource nullness, unhandled exception tests
test016()548 public void test016() {
549 Map options = getCompilerOptions();
550 options.put(CompilerOptions.OPTION_ReportUnclosedCloseable, CompilerOptions.WARNING);
551 this.runNegativeTest(
552 new String[] {
553 "X.java",
554 "public class X {\n" +
555 " public static void main(String [] args) { \n" +
556 " try (Y y = new Y();) {\n" +
557 " if (y == null) {}\n" +
558 " Y why = new Y();\n" +
559 " System.out.println(\"Try block\");\n" +
560 " }\n" +
561 " }\n" +
562 "} \n" +
563 "\n" +
564 "class Y implements AutoCloseable {\n" +
565 " public Y() throws WeirdException {\n" +
566 " throw new WeirdException();\n" +
567 " }\n" +
568 " public void close() {\n" +
569 " System.out.println(\"Closing resource\");\n" +
570 " }\n" +
571 "}\n" +
572 "\n" +
573 "class WeirdException extends Throwable {}\n",
574 },
575 "----------\n" +
576 "1. ERROR in X.java (at line 3)\n" +
577 " try (Y y = new Y();) {\n" +
578 " ^^^^^^^\n" +
579 "Unhandled exception type WeirdException\n" +
580 "----------\n" +
581 "2. WARNING in X.java (at line 4)\n" +
582 " if (y == null) {}\n" +
583 " ^^\n" +
584 "Dead code\n" +
585 "----------\n" +
586 "3. WARNING in X.java (at line 5)\n" +
587 " Y why = new Y();\n" +
588 " ^^^\n" +
589 "Resource leak: 'why' is never closed\n" +
590 "----------\n" +
591 "4. ERROR in X.java (at line 5)\n" +
592 " Y why = new Y();\n" +
593 " ^^^^^^^\n" +
594 "Unhandled exception type WeirdException\n" +
595 "----------\n" +
596 "5. WARNING in X.java (at line 20)\n" +
597 " class WeirdException extends Throwable {}\n" +
598 " ^^^^^^^^^^^^^^\n" +
599 "The serializable class WeirdException does not declare a static final serialVersionUID field of type long\n" +
600 "----------\n",
601 null,
602 true,
603 options);
604 }
605 // Dead code tests
test017()606 public void test017() {
607 Runner runner = new Runner();
608 runner.testFiles =
609 new String[] {
610 "X.java",
611 "public class X {\n" +
612 " public static void main(String [] args) { \n" +
613 " try (Y y = new Y();) {\n" +
614 " if (y == null)\n" +
615 " {}\n" +
616 " } finally {\n" +
617 " }\n" +
618 " }\n" +
619 "} \n" +
620 "\n" +
621 "class Y implements AutoCloseable {\n" +
622 " public void close() {\n" +
623 " }\n" +
624 "}\n"
625 };
626 runner.expectedCompilerLog =
627 "----------\n" +
628 "1. WARNING in X.java (at line 5)\n" +
629 " {}\n" +
630 " ^^\n" +
631 "Dead code\n" +
632 "----------\n";
633 runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
634 runner.runWarningTest();
635 }
636 // Syntax error tests
test018()637 public void test018() {
638 this.runNegativeTest(
639 new String[] {
640 "X.java",
641 "public class X {\n" +
642 " public static void main(String [] args) { \n" +
643 " try () {\n" +
644 " } finally {\n" +
645 " }\n" +
646 " }\n" +
647 "} \n"
648 },
649 "----------\n" +
650 "1. ERROR in X.java (at line 3)\n" +
651 " try () {\n" +
652 " ^\n" +
653 "Syntax error on token \"(\", Resources expected after this token\n" +
654 "----------\n");
655 }
656 // Unhandled exception tests
test020()657 public void test020() {
658 this.runNegativeTest(
659 new String[] {
660 "X.java",
661 "public class X implements AutoCloseable {\n" +
662 " public static void main(String [] args) {\n" +
663 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
664 " throw new XXException();\n" +
665 " } catch (XException x) {\n" +
666 " } catch (YException y) {\n" +
667 " } catch (ZException z) {\n" +
668 " } finally {\n" +
669 " }\n" +
670 " }\n" +
671 " public X() throws XException {\n" +
672 " throw new XException();\n" +
673 " }\n" +
674 " public void close() throws XXException {\n" +
675 " throw new XXException();\n" +
676 " }\n" +
677 "}\n" +
678 "class Y implements AutoCloseable {\n" +
679 " public Y() throws YException {\n" +
680 " throw new YException();\n" +
681 " }\n" +
682 " public void close() throws YYException {\n" +
683 " throw new YYException();\n" +
684 " }\n" +
685 "}\n" +
686 "class Z implements AutoCloseable {\n" +
687 " public Z() throws ZException {\n" +
688 " throw new ZException();\n" +
689 " }\n" +
690 " public void close() throws ZZException {\n" +
691 " throw new ZZException();\n" +
692 " }\n" +
693 "}\n" +
694 "class XException extends Exception {}\n" +
695 "class XXException extends Exception {}\n" +
696 "class YException extends Exception {}\n" +
697 "class YYException extends Exception {}\n" +
698 "class ZException extends Exception {}\n" +
699 "class ZZException extends Exception {}\n"
700 },
701 "----------\n" +
702 "1. ERROR in X.java (at line 3)\n" +
703 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
704 " ^\n" +
705 "Unhandled exception type XXException thrown by automatic close() invocation on x\n" +
706 "----------\n" +
707 "2. ERROR in X.java (at line 3)\n" +
708 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
709 " ^\n" +
710 "Unhandled exception type YYException thrown by automatic close() invocation on y\n" +
711 "----------\n" +
712 "3. ERROR in X.java (at line 3)\n" +
713 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
714 " ^\n" +
715 "Unhandled exception type ZZException thrown by automatic close() invocation on z\n" +
716 "----------\n" +
717 "4. ERROR in X.java (at line 4)\n" +
718 " throw new XXException();\n" +
719 " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
720 "Unhandled exception type XXException\n" +
721 "----------\n" +
722 "5. WARNING in X.java (at line 34)\n" +
723 " class XException extends Exception {}\n" +
724 " ^^^^^^^^^^\n" +
725 "The serializable class XException does not declare a static final serialVersionUID field of type long\n" +
726 "----------\n" +
727 "6. WARNING in X.java (at line 35)\n" +
728 " class XXException extends Exception {}\n" +
729 " ^^^^^^^^^^^\n" +
730 "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" +
731 "----------\n" +
732 "7. WARNING in X.java (at line 36)\n" +
733 " class YException extends Exception {}\n" +
734 " ^^^^^^^^^^\n" +
735 "The serializable class YException does not declare a static final serialVersionUID field of type long\n" +
736 "----------\n" +
737 "8. WARNING in X.java (at line 37)\n" +
738 " class YYException extends Exception {}\n" +
739 " ^^^^^^^^^^^\n" +
740 "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" +
741 "----------\n" +
742 "9. WARNING in X.java (at line 38)\n" +
743 " class ZException extends Exception {}\n" +
744 " ^^^^^^^^^^\n" +
745 "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" +
746 "----------\n" +
747 "10. WARNING in X.java (at line 39)\n" +
748 " class ZZException extends Exception {}\n" +
749 " ^^^^^^^^^^^\n" +
750 "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" +
751 "----------\n");
752 }
753 // Resource type test
test021()754 public void test021() {
755 this.runNegativeTest(
756 new String[] {
757 "X.java",
758 "public class X {\n" +
759 " public void method1(){\n" +
760 " try (Y i = null) {\n" +
761 " System.out.println();\n" +
762 " }\n" +
763 " }\n" +
764 "}\n" +
765 "class Y {\n" +
766 " public void close () {}\n" +
767 "}",
768 },
769 "----------\n" +
770 "1. ERROR in X.java (at line 3)\n" +
771 " try (Y i = null) {\n" +
772 " ^\n" +
773 "The resource type Y does not implement java.lang.AutoCloseable\n" +
774 "----------\n");
775 }
776 // Interface method return type compatibility test
test022()777 public void test022() {
778 this.runNegativeTest(
779 new String[] {
780 "X.java",
781 "public class X {\n" +
782 " public void method1(){\n" +
783 " try (Y i = null) {\n" +
784 " System.out.println();\n" +
785 " }\n" +
786 " }\n" +
787 "}\n" +
788 "class Y implements AutoCloseable {\n" +
789 " public int close () { return 0; }\n" +
790 "}",
791 },
792 "----------\n" +
793 "1. ERROR in X.java (at line 9)\n" +
794 " public int close () { return 0; }\n" +
795 " ^^^\n" +
796 "The return type is incompatible with AutoCloseable.close()\n" +
797 "----------\n");
798 }
799 // Exception handling, compatibility tests
test023()800 public void test023() {
801 this.runNegativeTest(
802 new String[] {
803 "X.java",
804 "public class X {\n" +
805 " public void method1(){\n" +
806 " try (Y i = null) {\n" +
807 " System.out.println();\n" +
808 " }\n" +
809 " }\n" +
810 "}\n" +
811 "class Y implements AutoCloseable {\n" +
812 " public void close () throws Blah {}\n" +
813 "}\n" +
814 "class Blah extends Throwable {}\n",
815 },
816 "----------\n" +
817 "1. ERROR in X.java (at line 3)\n" +
818 " try (Y i = null) {\n" +
819 " ^\n" +
820 "Unhandled exception type Blah thrown by automatic close() invocation on i\n" +
821 "----------\n" +
822 "2. ERROR in X.java (at line 9)\n" +
823 " public void close () throws Blah {}\n" +
824 " ^^^^^^^^^^^^^^^^^^^^\n" +
825 "Exception Blah is not compatible with throws clause in AutoCloseable.close()\n" +
826 "----------\n" +
827 "3. WARNING in X.java (at line 11)\n" +
828 " class Blah extends Throwable {}\n" +
829 " ^^^^\n" +
830 "The serializable class Blah does not declare a static final serialVersionUID field of type long\n" +
831 "----------\n");
832 }
833 // Exception handling tests
test024()834 public void test024() {
835 this.runNegativeTest(
836 new String[] {
837 "X.java",
838 "public class X implements AutoCloseable {\n" +
839 " public static void main(String [] args) {\n" +
840 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
841 " throw new XXException();\n" +
842 " } catch (XException x) {\n" +
843 " } catch (YException y) {\n" +
844 " } catch (ZException z) {\n" +
845 " } catch (XXException x) {\n" +
846 " } catch (YYException y) {\n" +
847 " } catch (ZZException z) {\n" +
848 " } finally {\n" +
849 " }\n" +
850 " }\n" +
851 " public X() throws XException {\n" +
852 " throw new XException();\n" +
853 " }\n" +
854 " public void close() throws XXException {\n" +
855 " throw new XXException();\n" +
856 " }\n" +
857 "}\n" +
858 "class Y implements AutoCloseable {\n" +
859 " public Y() throws YException {\n" +
860 " throw new YException();\n" +
861 " }\n" +
862 " public void close() throws YYException {\n" +
863 " throw new YYException();\n" +
864 " }\n" +
865 "}\n" +
866 "class Z implements AutoCloseable {\n" +
867 " public Z() throws ZException {\n" +
868 " throw new ZException();\n" +
869 " }\n" +
870 " public void close() throws ZZException {\n" +
871 " throw new ZZException();\n" +
872 " }\n" +
873 "}\n" +
874 "class XException extends Exception {}\n" +
875 "class XXException extends Exception {}\n" +
876 "class YException extends Exception {}\n" +
877 "class YYException extends Exception {}\n" +
878 "class ZException extends Exception {}\n" +
879 "class ZZException extends Exception {}\n"
880 },
881 "----------\n" +
882 "1. WARNING in X.java (at line 37)\n" +
883 " class XException extends Exception {}\n" +
884 " ^^^^^^^^^^\n" +
885 "The serializable class XException does not declare a static final serialVersionUID field of type long\n" +
886 "----------\n" +
887 "2. WARNING in X.java (at line 38)\n" +
888 " class XXException extends Exception {}\n" +
889 " ^^^^^^^^^^^\n" +
890 "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" +
891 "----------\n" +
892 "3. WARNING in X.java (at line 39)\n" +
893 " class YException extends Exception {}\n" +
894 " ^^^^^^^^^^\n" +
895 "The serializable class YException does not declare a static final serialVersionUID field of type long\n" +
896 "----------\n" +
897 "4. WARNING in X.java (at line 40)\n" +
898 " class YYException extends Exception {}\n" +
899 " ^^^^^^^^^^^\n" +
900 "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" +
901 "----------\n" +
902 "5. WARNING in X.java (at line 41)\n" +
903 " class ZException extends Exception {}\n" +
904 " ^^^^^^^^^^\n" +
905 "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" +
906 "----------\n" +
907 "6. WARNING in X.java (at line 42)\n" +
908 " class ZZException extends Exception {}\n" +
909 " ^^^^^^^^^^^\n" +
910 "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" +
911 "----------\n");
912 }
913 // Unhandled exception tests
test025()914 public void test025() {
915 this.runNegativeTest(
916 new String[] {
917 "X.java",
918 "public class X implements AutoCloseable {\n" +
919 " public static void main(String [] args) {\n" +
920 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
921 " throw new XXException();\n" +
922 " } catch (XException x) {\n" +
923 " } catch (YException y) {\n" +
924 " } catch (ZException z) {\n" +
925 " \n" +
926 " }\n" +
927 " }\n" +
928 " public X() throws XException {\n" +
929 " throw new XException();\n" +
930 " }\n" +
931 " public void close() throws XXException {\n" +
932 " throw new XXException();\n" +
933 " }\n" +
934 "}\n" +
935 "class Y implements AutoCloseable {\n" +
936 " public Y() throws YException {\n" +
937 " throw new YException();\n" +
938 " }\n" +
939 " public void close() throws YYException {\n" +
940 " throw new YYException();\n" +
941 " }\n" +
942 "}\n" +
943 "class Z implements AutoCloseable {\n" +
944 " public Z() throws ZException {\n" +
945 " throw new ZException();\n" +
946 " }\n" +
947 " public void close() throws ZZException {\n" +
948 " throw new ZZException();\n" +
949 " }\n" +
950 "}\n" +
951 "class XException extends Exception {}\n" +
952 "class XXException extends Exception {}\n" +
953 "class YException extends Exception {}\n" +
954 "class YYException extends Exception {}\n" +
955 "class ZException extends Exception {}\n" +
956 "class ZZException extends Exception {}\n"
957 },
958 "----------\n" +
959 "1. ERROR in X.java (at line 3)\n" +
960 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
961 " ^\n" +
962 "Unhandled exception type XXException thrown by automatic close() invocation on x\n" +
963 "----------\n" +
964 "2. ERROR in X.java (at line 3)\n" +
965 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
966 " ^\n" +
967 "Unhandled exception type YYException thrown by automatic close() invocation on y\n" +
968 "----------\n" +
969 "3. ERROR in X.java (at line 3)\n" +
970 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
971 " ^\n" +
972 "Unhandled exception type ZZException thrown by automatic close() invocation on z\n" +
973 "----------\n" +
974 "4. ERROR in X.java (at line 4)\n" +
975 " throw new XXException();\n" +
976 " ^^^^^^^^^^^^^^^^^^^^^^^^\n" +
977 "Unhandled exception type XXException\n" +
978 "----------\n" +
979 "5. WARNING in X.java (at line 34)\n" +
980 " class XException extends Exception {}\n" +
981 " ^^^^^^^^^^\n" +
982 "The serializable class XException does not declare a static final serialVersionUID field of type long\n" +
983 "----------\n" +
984 "6. WARNING in X.java (at line 35)\n" +
985 " class XXException extends Exception {}\n" +
986 " ^^^^^^^^^^^\n" +
987 "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" +
988 "----------\n" +
989 "7. WARNING in X.java (at line 36)\n" +
990 " class YException extends Exception {}\n" +
991 " ^^^^^^^^^^\n" +
992 "The serializable class YException does not declare a static final serialVersionUID field of type long\n" +
993 "----------\n" +
994 "8. WARNING in X.java (at line 37)\n" +
995 " class YYException extends Exception {}\n" +
996 " ^^^^^^^^^^^\n" +
997 "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" +
998 "----------\n" +
999 "9. WARNING in X.java (at line 38)\n" +
1000 " class ZException extends Exception {}\n" +
1001 " ^^^^^^^^^^\n" +
1002 "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" +
1003 "----------\n" +
1004 "10. WARNING in X.java (at line 39)\n" +
1005 " class ZZException extends Exception {}\n" +
1006 " ^^^^^^^^^^^\n" +
1007 "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" +
1008 "----------\n");
1009 }
test026()1010 public void test026() {
1011 this.runNegativeTest(
1012 new String[] {
1013 "X.java",
1014 "public class X implements AutoCloseable {\n" +
1015 " public static void main(String [] args) {\n" +
1016 " try (X x = new X(); Y y = new Y(); Z z = new Z()) {\n" +
1017 " throw new XXException();\n" +
1018 " } catch (XException x) {\n" +
1019 " } catch (YException y) {\n" +
1020 " } catch (ZException z) {\n" +
1021 " } catch (XXException x) {\n" +
1022 " } catch (YYException y) {\n" +
1023 " } catch (ZZException z) {\n\n" +
1024 " }\n" +
1025 " }\n" +
1026 " public X() throws XException {\n" +
1027 " throw new XException();\n" +
1028 " }\n" +
1029 " public void close() throws XXException {\n" +
1030 " throw new XXException();\n" +
1031 " }\n" +
1032 "}\n" +
1033 "class Y implements AutoCloseable {\n" +
1034 " public Y() throws YException {\n" +
1035 " throw new YException();\n" +
1036 " }\n" +
1037 " public void close() throws YYException {\n" +
1038 " throw new YYException();\n" +
1039 " }\n" +
1040 "}\n" +
1041 "class Z implements AutoCloseable {\n" +
1042 " public Z() throws ZException {\n" +
1043 " throw new ZException();\n" +
1044 " }\n" +
1045 " public void close() throws ZZException {\n" +
1046 " throw new ZZException();\n" +
1047 " }\n" +
1048 "}\n" +
1049 "class XException extends Exception {}\n" +
1050 "class XXException extends Exception {}\n" +
1051 "class YException extends Exception {}\n" +
1052 "class YYException extends Exception {}\n" +
1053 "class ZException extends Exception {}\n" +
1054 "class ZZException extends Exception {}\n"
1055 },
1056 "----------\n" +
1057 "1. WARNING in X.java (at line 37)\n" +
1058 " class XException extends Exception {}\n" +
1059 " ^^^^^^^^^^\n" +
1060 "The serializable class XException does not declare a static final serialVersionUID field of type long\n" +
1061 "----------\n" +
1062 "2. WARNING in X.java (at line 38)\n" +
1063 " class XXException extends Exception {}\n" +
1064 " ^^^^^^^^^^^\n" +
1065 "The serializable class XXException does not declare a static final serialVersionUID field of type long\n" +
1066 "----------\n" +
1067 "3. WARNING in X.java (at line 39)\n" +
1068 " class YException extends Exception {}\n" +
1069 " ^^^^^^^^^^\n" +
1070 "The serializable class YException does not declare a static final serialVersionUID field of type long\n" +
1071 "----------\n" +
1072 "4. WARNING in X.java (at line 40)\n" +
1073 " class YYException extends Exception {}\n" +
1074 " ^^^^^^^^^^^\n" +
1075 "The serializable class YYException does not declare a static final serialVersionUID field of type long\n" +
1076 "----------\n" +
1077 "5. WARNING in X.java (at line 41)\n" +
1078 " class ZException extends Exception {}\n" +
1079 " ^^^^^^^^^^\n" +
1080 "The serializable class ZException does not declare a static final serialVersionUID field of type long\n" +
1081 "----------\n" +
1082 "6. WARNING in X.java (at line 42)\n" +
1083 " class ZZException extends Exception {}\n" +
1084 " ^^^^^^^^^^^\n" +
1085 "The serializable class ZZException does not declare a static final serialVersionUID field of type long\n" +
1086 "----------\n");
1087 }
test027()1088 public void test027() {
1089 this.runConformTest(
1090 new String[] {
1091 "X.java",
1092 "public class X implements AutoCloseable {\n" +
1093 " public static void main(String [] args) throws Exception {\n" +
1094 " try (X x = new X(); Y y = new Y()) {\n" +
1095 " System.out.println(\"Body\");\n" +
1096 " throw new Exception(\"Body\");\n" +
1097 " } catch (Exception e) {\n" +
1098 " System.out.println(e);\n" +
1099 " Throwable [] suppressed = e.getSuppressed();\n" +
1100 " for (int i = 0; i < suppressed.length; i++) {\n" +
1101 " System.out.println(\"Suppressed:\" + suppressed[i]);\n" +
1102 " }\n" +
1103 " } finally {\n" +
1104 " int finallyVar = 10;\n" +
1105 " System.out.println(finallyVar);\n" +
1106 " }\n" +
1107 " }\n" +
1108 " public X() {\n" +
1109 " System.out.println(\"X CTOR\");\n" +
1110 " }\n" +
1111 " public void close() throws Exception {\n" +
1112 " System.out.println(\"X Close\");\n" +
1113 " throw new Exception(\"X Close\");\n" +
1114 " }\n" +
1115 "}\n" +
1116 "class Y implements AutoCloseable {\n" +
1117 " public Y() {\n" +
1118 " System.out.println(\"Y CTOR\");\n" +
1119 " }\n" +
1120 " public void close() throws Exception {\n" +
1121 " System.out.println(\"Y Close\");\n" +
1122 " throw new Exception(\"Y Close\");\n" +
1123 " }\n" +
1124 "}\n"
1125 },
1126 "X CTOR\n" +
1127 "Y CTOR\n" +
1128 "Body\n" +
1129 "Y Close\n" +
1130 "X Close\n" +
1131 "java.lang.Exception: Body\n" +
1132 "Suppressed:java.lang.Exception: Y Close\n" +
1133 "Suppressed:java.lang.Exception: X Close\n" +
1134 "10");
1135 }
test028()1136 public void test028() {
1137 this.runConformTest(
1138 new String[] {
1139 "X.java",
1140 "public class X implements AutoCloseable {\n" +
1141 " public static void main(String [] args) throws Exception {\n" +
1142 " try (X x = new X(); Y y = new Y()) {\n" +
1143 " System.out.println(\"Body\");\n" +
1144 " } catch (Exception e) {\n" +
1145 " e.printStackTrace();\n" +
1146 " }\n" +
1147 " }\n" +
1148 " public X() {\n" +
1149 " System.out.println(\"X CTOR\");\n" +
1150 " }\n" +
1151 " public void close() {\n" +
1152 " System.out.println(\"X DTOR\");\n" +
1153 " }\n" +
1154 "}\n" +
1155 "class Y implements AutoCloseable {\n" +
1156 " public Y() {\n" +
1157 " System.out.println(\"Y CTOR\");\n" +
1158 " }\n" +
1159 " public void close() {\n" +
1160 " System.out.println(\"Y DTOR\");\n" +
1161 " }\n" +
1162 "}\n"
1163 },
1164 "X CTOR\n" +
1165 "Y CTOR\n" +
1166 "Body\n" +
1167 "Y DTOR\n" +
1168 "X DTOR");
1169 }
1170 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=338881
test029()1171 public void test029() {
1172 this.runConformTest(
1173 new String[] {
1174 "X.java",
1175 "import java.io.File;\n" +
1176 "import java.io.FileReader;\n" +
1177 "import java.io.IOException;\n" +
1178 "public class X {\n" +
1179 " void foo() {\n" +
1180 " File file = new File(\"somefile\");\n" +
1181 " try(FileReader fileReader = new FileReader(file);) {\n" +
1182 " char[] in = new char[50];\n" +
1183 " fileReader.read(in);\n" +
1184 " } catch (IOException e) {\n" +
1185 " System.out.println(\"Got IO exception\");\n" +
1186 " } finally{\n" +
1187 " }\n" +
1188 " }\n" +
1189 " public static void main(String[] args) {\n" +
1190 " new X().foo();\n" +
1191 " }\n" +
1192 "}\n"
1193 },
1194 "Got IO exception");
1195 }
test030()1196 public void test030() { // test return + resources
1197 this.runConformTest(
1198 new String[] {
1199 "X.java",
1200 "public class X implements AutoCloseable {\n" +
1201 " public static void main(String [] args) throws Exception { \n" +
1202 " final boolean getOut = true;\n" +
1203 " System.out.println(\"Main\");\n" +
1204 " try (X x1 = new X(); X x2 = new X()) {\n" +
1205 " System.out.println(\"Outer Try\");\n" +
1206 " while (true) {\n" +
1207 " try (Y y1 = new Y(); Y y2 = new Y()) {\n" +
1208 " System.out.println(\"Middle Try\");\n" +
1209 " try (Z z1 = new Z(); Z z2 = new Z()) {\n" +
1210 " System.out.println(\"Inner Try\");\n" +
1211 " if (getOut) \n" +
1212 " return;\n" +
1213 " else\n" +
1214 " break;\n" +
1215 " }\n" +
1216 " }\n" +
1217 " }\n" +
1218 " System.out.println(\"Out of while\");\n" +
1219 " }\n" +
1220 " }\n" +
1221 " public X() {\n" +
1222 " System.out.println(\"X::X\");\n" +
1223 " }\n" +
1224 " public void close() throws Exception {\n" +
1225 " System.out.println(\"X::~X\");\n" +
1226 " }\n" +
1227 "}\n" +
1228 "class Y implements AutoCloseable {\n" +
1229 " public Y() {\n" +
1230 " System.out.println(\"Y::Y\");\n" +
1231 " }\n" +
1232 " public void close() throws Exception {\n" +
1233 " System.out.println(\"Y::~Y\");\n" +
1234 " }\n" +
1235 "}\n" +
1236 "class Z implements AutoCloseable {\n" +
1237 " public Z() {\n" +
1238 " System.out.println(\"Z::Z\");\n" +
1239 " }\n" +
1240 " public void close() throws Exception {\n" +
1241 " System.out.println(\"Z::~Z\");\n" +
1242 " }\n" +
1243 "}\n"
1244 },
1245 "Main\n" +
1246 "X::X\n" +
1247 "X::X\n" +
1248 "Outer Try\n" +
1249 "Y::Y\n" +
1250 "Y::Y\n" +
1251 "Middle Try\n" +
1252 "Z::Z\n" +
1253 "Z::Z\n" +
1254 "Inner Try\n" +
1255 "Z::~Z\n" +
1256 "Z::~Z\n" +
1257 "Y::~Y\n" +
1258 "Y::~Y\n" +
1259 "X::~X\n" +
1260 "X::~X");
1261 }
test030a()1262 public void test030a() { // test return + resources + with exceptions being thrown by close()
1263 this.runConformTest(
1264 new String[] {
1265 "X.java",
1266 "public class X implements AutoCloseable {\n" +
1267 " public static void main(String [] args) throws Exception { \n" +
1268 " final boolean getOut = true;\n" +
1269 " System.out.println(\"Main\");\n" +
1270 " try (X x1 = new X(); X x2 = new X()) {\n" +
1271 " System.out.println(\"Outer Try\");\n" +
1272 " while (true) {\n" +
1273 " try (Y y1 = new Y(); Y y2 = new Y()) {\n" +
1274 " System.out.println(\"Middle Try\");\n" +
1275 " try (Z z1 = new Z(); Z z2 = new Z()) {\n" +
1276 " System.out.println(\"Inner Try\");\n" +
1277 " if (getOut) \n" +
1278 " return;\n" +
1279 " else\n" +
1280 " break;\n" +
1281 " }\n" +
1282 " }\n" +
1283 " }\n" +
1284 " System.out.println(\"Out of while\");\n" +
1285 " } catch (Exception e) {\n" +
1286 " System.out.println(e);\n" +
1287 " Throwable suppressed [] = e.getSuppressed();\n" +
1288 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1289 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
1290 " }\n" +
1291 " }\n" +
1292 " }\n" +
1293 " public X() {\n" +
1294 " System.out.println(\"X::X\");\n" +
1295 " }\n" +
1296 " public void close() throws Exception {\n" +
1297 " System.out.println(\"X::~X\");\n" +
1298 " throw new Exception(\"X::~X\");\n" +
1299 " }\n" +
1300 "}\n" +
1301 "class Y implements AutoCloseable {\n" +
1302 " public Y() {\n" +
1303 " System.out.println(\"Y::Y\");\n" +
1304 " }\n" +
1305 " public void close() throws Exception {\n" +
1306 " System.out.println(\"Y::~Y\");\n" +
1307 " throw new Exception(\"Y::~Y\");\n" +
1308 " }\n" +
1309 "}\n" +
1310 "class Z implements AutoCloseable {\n" +
1311 " public Z() {\n" +
1312 " System.out.println(\"Z::Z\");\n" +
1313 " }\n" +
1314 " public void close() throws Exception {\n" +
1315 " System.out.println(\"Z::~Z\");\n" +
1316 " throw new Exception(\"Z::~Z\");\n" +
1317 " }\n" +
1318 "}\n"
1319 },
1320 "Main\n" +
1321 "X::X\n" +
1322 "X::X\n" +
1323 "Outer Try\n" +
1324 "Y::Y\n" +
1325 "Y::Y\n" +
1326 "Middle Try\n" +
1327 "Z::Z\n" +
1328 "Z::Z\n" +
1329 "Inner Try\n" +
1330 "Z::~Z\n" +
1331 "Z::~Z\n" +
1332 "Y::~Y\n" +
1333 "Y::~Y\n" +
1334 "X::~X\n" +
1335 "X::~X\n" +
1336 "java.lang.Exception: Z::~Z\n" +
1337 "Suppressed: java.lang.Exception: Z::~Z\n" +
1338 "Suppressed: java.lang.Exception: Y::~Y\n" +
1339 "Suppressed: java.lang.Exception: Y::~Y\n" +
1340 "Suppressed: java.lang.Exception: X::~X\n" +
1341 "Suppressed: java.lang.Exception: X::~X");
1342 }
test031()1343 public void test031() { // test break + resources
1344 this.runConformTest(
1345 new String[] {
1346 "X.java",
1347 "public class X implements AutoCloseable {\n" +
1348 " public static void main(String [] args) throws Exception { \n" +
1349 " final boolean getOut = false;\n" +
1350 " System.out.println(\"Main\");\n" +
1351 " try (X x1 = new X(); X x2 = new X()) {\n" +
1352 " System.out.println(\"Outer Try\");\n" +
1353 " while (true) {\n" +
1354 " try (Y y1 = new Y(); Y y2 = new Y()) {\n" +
1355 " System.out.println(\"Middle Try\");\n" +
1356 " try (Z z1 = new Z(); Z z2 = new Z()) {\n" +
1357 " System.out.println(\"Inner Try\");\n" +
1358 " if (getOut) \n" +
1359 " return;\n" +
1360 " else\n" +
1361 " break;\n" +
1362 " }\n" +
1363 " }\n" +
1364 " }\n" +
1365 " System.out.println(\"Out of while\");\n" +
1366 " }\n" +
1367 " }\n" +
1368 " public X() {\n" +
1369 " System.out.println(\"X::X\");\n" +
1370 " }\n" +
1371 " public void close() throws Exception {\n" +
1372 " System.out.println(\"X::~X\");\n" +
1373 " }\n" +
1374 "}\n" +
1375 "class Y implements AutoCloseable {\n" +
1376 " public Y() {\n" +
1377 " System.out.println(\"Y::Y\");\n" +
1378 " }\n" +
1379 " public void close() throws Exception {\n" +
1380 " System.out.println(\"Y::~Y\");\n" +
1381 " }\n" +
1382 "}\n" +
1383 "class Z implements AutoCloseable {\n" +
1384 " public Z() {\n" +
1385 " System.out.println(\"Z::Z\");\n" +
1386 " }\n" +
1387 " public void close() throws Exception {\n" +
1388 " System.out.println(\"Z::~Z\");\n" +
1389 " }\n" +
1390 "}\n"
1391 },
1392 "Main\n" +
1393 "X::X\n" +
1394 "X::X\n" +
1395 "Outer Try\n" +
1396 "Y::Y\n" +
1397 "Y::Y\n" +
1398 "Middle Try\n" +
1399 "Z::Z\n" +
1400 "Z::Z\n" +
1401 "Inner Try\n" +
1402 "Z::~Z\n" +
1403 "Z::~Z\n" +
1404 "Y::~Y\n" +
1405 "Y::~Y\n" +
1406 "Out of while\n" +
1407 "X::~X\n" +
1408 "X::~X");
1409 }
test032()1410 public void test032() { // test continue + resources
1411 this.runConformTest(
1412 new String[] {
1413 "X.java",
1414 "public class X implements AutoCloseable {\n" +
1415 " public static void main(String [] args) throws Exception { \n" +
1416 " final boolean getOut = false;\n" +
1417 " System.out.println(\"Main\");\n" +
1418 " try (X x1 = new X(); X x2 = new X()) {\n" +
1419 " System.out.println(\"Outer Try\");\n" +
1420 " boolean more = true;\n" +
1421 " while (more) {\n" +
1422 " try (Y y1 = new Y(); Y y2 = new Y()) {\n" +
1423 " System.out.println(\"Middle Try\");\n" +
1424 " try (Z z1 = new Z(); Z z2 = new Z()) {\n" +
1425 " System.out.println(\"Inner Try\");\n" +
1426 " more = false;\n" +
1427 " continue;\n" +
1428 " } finally { \n" +
1429 " System.out.println(\"Inner Finally\");\n" +
1430 " }\n" +
1431 " } finally {\n" +
1432 " System.out.println(\"Middle Finally\");\n" +
1433 " }\n" +
1434 " }\n" +
1435 " System.out.println(\"Out of while\");\n" +
1436 " } finally {\n" +
1437 " System.out.println(\"Outer Finally\");\n" +
1438 " }\n" +
1439 " }\n" +
1440 " public X() {\n" +
1441 " System.out.println(\"X::X\");\n" +
1442 " }\n" +
1443 " public void close() throws Exception {\n" +
1444 " System.out.println(\"X::~X\");\n" +
1445 " }\n" +
1446 "}\n" +
1447 "class Y implements AutoCloseable {\n" +
1448 " public Y() {\n" +
1449 " System.out.println(\"Y::Y\");\n" +
1450 " }\n" +
1451 " public void close() throws Exception {\n" +
1452 " System.out.println(\"Y::~Y\");\n" +
1453 " }\n" +
1454 "}\n" +
1455 "class Z implements AutoCloseable {\n" +
1456 " public Z() {\n" +
1457 " System.out.println(\"Z::Z\");\n" +
1458 " }\n" +
1459 " public void close() throws Exception {\n" +
1460 " System.out.println(\"Z::~Z\");\n" +
1461 " }\n" +
1462 "}\n"
1463 },
1464 "Main\n" +
1465 "X::X\n" +
1466 "X::X\n" +
1467 "Outer Try\n" +
1468 "Y::Y\n" +
1469 "Y::Y\n" +
1470 "Middle Try\n" +
1471 "Z::Z\n" +
1472 "Z::Z\n" +
1473 "Inner Try\n" +
1474 "Z::~Z\n" +
1475 "Z::~Z\n" +
1476 "Inner Finally\n" +
1477 "Y::~Y\n" +
1478 "Y::~Y\n" +
1479 "Middle Finally\n" +
1480 "Out of while\n" +
1481 "X::~X\n" +
1482 "X::~X\n" +
1483 "Outer Finally");
1484 }
test033()1485 public void test033() { // test null resources
1486 this.runConformTest(
1487 new String[] {
1488 "X.java",
1489 "public class X implements AutoCloseable {\n" +
1490 " public static void main(String [] args) throws Exception { \n" +
1491 " final boolean getOut = false;\n" +
1492 " System.out.println(\"Main\");\n" +
1493 " try (X x1 = null; Y y = new Y(); Z z = null) {\n" +
1494 " System.out.println(\"Body\");\n" +
1495 " } finally {\n" +
1496 " System.out.println(\"Outer Finally\");\n" +
1497 " }\n" +
1498 " }\n" +
1499 " public X() {\n" +
1500 " System.out.println(\"X::X\");\n" +
1501 " }\n" +
1502 " public void close() throws Exception {\n" +
1503 " System.out.println(\"X::~X\");\n" +
1504 " }\n" +
1505 "}\n" +
1506 "class Y implements AutoCloseable {\n" +
1507 " public Y() {\n" +
1508 " System.out.println(\"Y::Y\");\n" +
1509 " }\n" +
1510 " public void close() throws Exception {\n" +
1511 " System.out.println(\"Y::~Y\");\n" +
1512 " }\n" +
1513 "}\n" +
1514 "class Z implements AutoCloseable {\n" +
1515 " public Z() {\n" +
1516 " System.out.println(\"Z::Z\");\n" +
1517 " }\n" +
1518 " public void close() throws Exception {\n" +
1519 " System.out.println(\"Z::~Z\");\n" +
1520 " }\n" +
1521 "}\n"
1522 },
1523 "Main\n" +
1524 "Y::Y\n" +
1525 "Body\n" +
1526 "Y::~Y\n" +
1527 "Outer Finally");
1528 }
test034()1529 public void test034() {
1530 this.runConformTest(
1531 new String[] {
1532 "X.java",
1533 "public class X {\n" +
1534 " public static void main(String [] args) {\n" +
1535 " System.out.println(\"Main\");\n" +
1536 " try (A a = new A(); B b = new B()) {\n" +
1537 " System.out.println(\"Outer try\");\n" +
1538 " try (C c = new C(); D d = new D();) {\n" +
1539 " System.out.println(\"Middle try\");\n" +
1540 " try (E e = new E(); F f = new F()) {\n" +
1541 " System.out.println(\"Inner try\");\n" +
1542 " throw new Exception(\"Body\");\n" +
1543 " } \n" +
1544 " }\n" +
1545 " } catch (Exception e) {\n" +
1546 " System.out.println(e);\n" +
1547 " Throwable suppressed [] = e.getSuppressed();\n" +
1548 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1549 " System.out.println(suppressed[i]);\n" +
1550 " }\n" +
1551 " } finally {\n" +
1552 " System.out.println(\"All done\");\n" +
1553 " }\n" +
1554 " }\n" +
1555 "}\n" +
1556 "class A implements AutoCloseable {\n" +
1557 " public A () throws Exception {\n" +
1558 " System.out.println(\"A::A\");\n" +
1559 " throw new Exception (\"A::A\");\n" +
1560 " }\n" +
1561 " public void close() throws Exception {\n" +
1562 " System.out.println(\"A::~A\");\n" +
1563 " throw new Exception (\"A::~A\");\n" +
1564 " }\n" +
1565 "}\n" +
1566 "class B implements AutoCloseable {\n" +
1567 " public B () throws Exception {\n" +
1568 " System.out.println(\"B::B\");\n" +
1569 " throw new Exception (\"B::B\");\n" +
1570 " }\n" +
1571 " public void close() throws Exception {\n" +
1572 " System.out.println(\"B::~B\");\n" +
1573 " throw new Exception (\"B::~B\");\n" +
1574 " }\n" +
1575 "}\n" +
1576 "class C implements AutoCloseable {\n" +
1577 " public C () throws Exception {\n" +
1578 " System.out.println(\"C::C\");\n" +
1579 " throw new Exception (\"C::C\");\n" +
1580 " }\n" +
1581 " public void close() throws Exception {\n" +
1582 " System.out.println(\"C::~C\");\n" +
1583 " throw new Exception (\"C::~C\");\n" +
1584 " }\n" +
1585 "}\n" +
1586 "class D implements AutoCloseable {\n" +
1587 " public D () throws Exception {\n" +
1588 " System.out.println(\"D::D\");\n" +
1589 " throw new Exception (\"D::D\");\n" +
1590 " }\n" +
1591 " public void close() throws Exception {\n" +
1592 " System.out.println(\"D::~D\");\n" +
1593 " throw new Exception (\"D::~D\");\n" +
1594 " }\n" +
1595 "}\n" +
1596 "class E implements AutoCloseable {\n" +
1597 " public E () throws Exception {\n" +
1598 " System.out.println(\"E::E\");\n" +
1599 " throw new Exception (\"E::E\");\n" +
1600 " }\n" +
1601 " public void close() throws Exception {\n" +
1602 " System.out.println(\"E::~E\");\n" +
1603 " throw new Exception (\"E::~E\");\n" +
1604 " }\n" +
1605 "}\n" +
1606 "class F implements AutoCloseable {\n" +
1607 " public F () throws Exception {\n" +
1608 " System.out.println(\"F::F\");\n" +
1609 " throw new Exception (\"F::F\");\n" +
1610 " }\n" +
1611 " public void close() throws Exception {\n" +
1612 " System.out.println(\"F::~F\");\n" +
1613 " throw new Exception (\"F::~F\");\n" +
1614 " }\n" +
1615 "}\n" +
1616 "class G implements AutoCloseable {\n" +
1617 " public G () throws Exception {\n" +
1618 " System.out.println(\"G::G\");\n" +
1619 " throw new Exception (\"G::G\");\n" +
1620 " }\n" +
1621 " public void close() throws Exception {\n" +
1622 " System.out.println(\"G::~G\");\n" +
1623 " throw new Exception (\"G::~G\");\n" +
1624 " }\n" +
1625 "}\n"
1626 },
1627 "Main\n" +
1628 "A::A\n" +
1629 "java.lang.Exception: A::A\n" +
1630 "All done");
1631 }
test035()1632 public void test035() {
1633 this.runConformTest(
1634 new String[] {
1635 "X.java",
1636 "public class X {\n" +
1637 " public static void main(String [] args) {\n" +
1638 " System.out.println(\"Main\");\n" +
1639 " try (A a = new A(); B b = new B()) {\n" +
1640 " System.out.println(\"Outer try\");\n" +
1641 " try (C c = new C(); D d = new D();) {\n" +
1642 " System.out.println(\"Middle try\");\n" +
1643 " try (E e = new E(); F f = new F()) {\n" +
1644 " System.out.println(\"Inner try\");\n" +
1645 " throw new Exception(\"Body\");\n" +
1646 " } \n" +
1647 " }\n" +
1648 " } catch (Exception e) {\n" +
1649 " System.out.println(e);\n" +
1650 " Throwable suppressed [] = e.getSuppressed();\n" +
1651 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1652 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
1653 " }\n" +
1654 " } finally {\n" +
1655 " System.out.println(\"All done\");\n" +
1656 " }\n" +
1657 " }\n" +
1658 "}\n" +
1659 "class A implements AutoCloseable {\n" +
1660 " public A () throws Exception {\n" +
1661 " System.out.println(\"A::A\");\n" +
1662 " }\n" +
1663 " public void close() throws Exception {\n" +
1664 " System.out.println(\"A::~A\");\n" +
1665 " throw new Exception (\"A::~A\");\n" +
1666 " }\n" +
1667 "}\n" +
1668 "class B implements AutoCloseable {\n" +
1669 " public B () throws Exception {\n" +
1670 " System.out.println(\"B::B\");\n" +
1671 " throw new Exception (\"B::B\");\n" +
1672 " }\n" +
1673 " public void close() throws Exception {\n" +
1674 " System.out.println(\"B::~B\");\n" +
1675 " throw new Exception (\"B::~B\");\n" +
1676 " }\n" +
1677 "}\n" +
1678 "class C implements AutoCloseable {\n" +
1679 " public C () throws Exception {\n" +
1680 " System.out.println(\"C::C\");\n" +
1681 " throw new Exception (\"C::C\");\n" +
1682 " }\n" +
1683 " public void close() throws Exception {\n" +
1684 " System.out.println(\"C::~C\");\n" +
1685 " throw new Exception (\"C::~C\");\n" +
1686 " }\n" +
1687 "}\n" +
1688 "class D implements AutoCloseable {\n" +
1689 " public D () throws Exception {\n" +
1690 " System.out.println(\"D::D\");\n" +
1691 " throw new Exception (\"D::D\");\n" +
1692 " }\n" +
1693 " public void close() throws Exception {\n" +
1694 " System.out.println(\"D::~D\");\n" +
1695 " throw new Exception (\"D::~D\");\n" +
1696 " }\n" +
1697 "}\n" +
1698 "class E implements AutoCloseable {\n" +
1699 " public E () throws Exception {\n" +
1700 " System.out.println(\"E::E\");\n" +
1701 " throw new Exception (\"E::E\");\n" +
1702 " }\n" +
1703 " public void close() throws Exception {\n" +
1704 " System.out.println(\"E::~E\");\n" +
1705 " throw new Exception (\"E::~E\");\n" +
1706 " }\n" +
1707 "}\n" +
1708 "class F implements AutoCloseable {\n" +
1709 " public F () throws Exception {\n" +
1710 " System.out.println(\"F::F\");\n" +
1711 " throw new Exception (\"F::F\");\n" +
1712 " }\n" +
1713 " public void close() throws Exception {\n" +
1714 " System.out.println(\"F::~F\");\n" +
1715 " throw new Exception (\"F::~F\");\n" +
1716 " }\n" +
1717 "}\n" +
1718 "class G implements AutoCloseable {\n" +
1719 " public G () throws Exception {\n" +
1720 " System.out.println(\"G::G\");\n" +
1721 " throw new Exception (\"G::G\");\n" +
1722 " }\n" +
1723 " public void close() throws Exception {\n" +
1724 " System.out.println(\"G::~G\");\n" +
1725 " throw new Exception (\"G::~G\");\n" +
1726 " }\n" +
1727 "}\n"
1728 },
1729 "Main\n" +
1730 "A::A\n" +
1731 "B::B\n" +
1732 "A::~A\n" +
1733 "java.lang.Exception: B::B\n" +
1734 "Suppressed: java.lang.Exception: A::~A\n" +
1735 "All done");
1736 }
test036()1737 public void test036() {
1738 this.runConformTest(
1739 new String[] {
1740 "X.java",
1741 "public class X {\n" +
1742 " public static void main(String [] args) {\n" +
1743 " System.out.println(\"Main\");\n" +
1744 " try (A a = new A(); B b = new B()) {\n" +
1745 " System.out.println(\"Outer try\");\n" +
1746 " try (C c = new C(); D d = new D();) {\n" +
1747 " System.out.println(\"Middle try\");\n" +
1748 " try (E e = new E(); F f = new F()) {\n" +
1749 " System.out.println(\"Inner try\");\n" +
1750 " throw new Exception(\"Body\");\n" +
1751 " } \n" +
1752 " }\n" +
1753 " } catch (Exception e) {\n" +
1754 " System.out.println(e);\n" +
1755 " Throwable suppressed [] = e.getSuppressed();\n" +
1756 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1757 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
1758 " }\n" +
1759 " } finally {\n" +
1760 " System.out.println(\"All done\");\n" +
1761 " }\n" +
1762 " }\n" +
1763 "}\n" +
1764 "class A implements AutoCloseable {\n" +
1765 " public A () throws Exception {\n" +
1766 " System.out.println(\"A::A\");\n" +
1767 " }\n" +
1768 " public void close() throws Exception {\n" +
1769 " System.out.println(\"A::~A\");\n" +
1770 " throw new Exception (\"A::~A\");\n" +
1771 " }\n" +
1772 "}\n" +
1773 "class B implements AutoCloseable {\n" +
1774 " public B () throws Exception {\n" +
1775 " System.out.println(\"B::B\");\n" +
1776 " }\n" +
1777 " public void close() throws Exception {\n" +
1778 " System.out.println(\"B::~B\");\n" +
1779 " throw new Exception (\"B::~B\");\n" +
1780 " }\n" +
1781 "}\n" +
1782 "class C implements AutoCloseable {\n" +
1783 " public C () throws Exception {\n" +
1784 " System.out.println(\"C::C\");\n" +
1785 " throw new Exception (\"C::C\");\n" +
1786 " }\n" +
1787 " public void close() throws Exception {\n" +
1788 " System.out.println(\"C::~C\");\n" +
1789 " throw new Exception (\"C::~C\");\n" +
1790 " }\n" +
1791 "}\n" +
1792 "class D implements AutoCloseable {\n" +
1793 " public D () throws Exception {\n" +
1794 " System.out.println(\"D::D\");\n" +
1795 " throw new Exception (\"D::D\");\n" +
1796 " }\n" +
1797 " public void close() throws Exception {\n" +
1798 " System.out.println(\"D::~D\");\n" +
1799 " throw new Exception (\"D::~D\");\n" +
1800 " }\n" +
1801 "}\n" +
1802 "class E implements AutoCloseable {\n" +
1803 " public E () throws Exception {\n" +
1804 " System.out.println(\"E::E\");\n" +
1805 " throw new Exception (\"E::E\");\n" +
1806 " }\n" +
1807 " public void close() throws Exception {\n" +
1808 " System.out.println(\"E::~E\");\n" +
1809 " throw new Exception (\"E::~E\");\n" +
1810 " }\n" +
1811 "}\n" +
1812 "class F implements AutoCloseable {\n" +
1813 " public F () throws Exception {\n" +
1814 " System.out.println(\"F::F\");\n" +
1815 " throw new Exception (\"F::F\");\n" +
1816 " }\n" +
1817 " public void close() throws Exception {\n" +
1818 " System.out.println(\"F::~F\");\n" +
1819 " throw new Exception (\"F::~F\");\n" +
1820 " }\n" +
1821 "}\n" +
1822 "class G implements AutoCloseable {\n" +
1823 " public G () throws Exception {\n" +
1824 " System.out.println(\"G::G\");\n" +
1825 " throw new Exception (\"G::G\");\n" +
1826 " }\n" +
1827 " public void close() throws Exception {\n" +
1828 " System.out.println(\"G::~G\");\n" +
1829 " throw new Exception (\"G::~G\");\n" +
1830 " }\n" +
1831 "}\n"
1832 },
1833 "Main\n" +
1834 "A::A\n" +
1835 "B::B\n" +
1836 "Outer try\n" +
1837 "C::C\n" +
1838 "B::~B\n" +
1839 "A::~A\n" +
1840 "java.lang.Exception: C::C\n" +
1841 "Suppressed: java.lang.Exception: B::~B\n" +
1842 "Suppressed: java.lang.Exception: A::~A\n" +
1843 "All done");
1844 }
test037()1845 public void test037() {
1846 this.runConformTest(
1847 new String[] {
1848 "X.java",
1849 "public class X {\n" +
1850 " public static void main(String [] args) {\n" +
1851 " System.out.println(\"Main\");\n" +
1852 " try (A a = new A(); B b = new B()) {\n" +
1853 " System.out.println(\"Outer try\");\n" +
1854 " try (C c = new C(); D d = new D();) {\n" +
1855 " System.out.println(\"Middle try\");\n" +
1856 " try (E e = new E(); F f = new F()) {\n" +
1857 " System.out.println(\"Inner try\");\n" +
1858 " throw new Exception(\"Body\");\n" +
1859 " } \n" +
1860 " }\n" +
1861 " } catch (Exception e) {\n" +
1862 " System.out.println(e);\n" +
1863 " Throwable suppressed [] = e.getSuppressed();\n" +
1864 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1865 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
1866 " }\n" +
1867 " } finally {\n" +
1868 " System.out.println(\"All done\");\n" +
1869 " }\n" +
1870 " }\n" +
1871 "}\n" +
1872 "class A implements AutoCloseable {\n" +
1873 " public A () throws Exception {\n" +
1874 " System.out.println(\"A::A\");\n" +
1875 " }\n" +
1876 " public void close() throws Exception {\n" +
1877 " System.out.println(\"A::~A\");\n" +
1878 " throw new Exception (\"A::~A\");\n" +
1879 " }\n" +
1880 "}\n" +
1881 "class B implements AutoCloseable {\n" +
1882 " public B () throws Exception {\n" +
1883 " System.out.println(\"B::B\");\n" +
1884 " }\n" +
1885 " public void close() throws Exception {\n" +
1886 " System.out.println(\"B::~B\");\n" +
1887 " throw new Exception (\"B::~B\");\n" +
1888 " }\n" +
1889 "}\n" +
1890 "class C implements AutoCloseable {\n" +
1891 " public C () throws Exception {\n" +
1892 " System.out.println(\"C::C\");\n" +
1893 " }\n" +
1894 " public void close() throws Exception {\n" +
1895 " System.out.println(\"C::~C\");\n" +
1896 " throw new Exception (\"C::~C\");\n" +
1897 " }\n" +
1898 "}\n" +
1899 "class D implements AutoCloseable {\n" +
1900 " public D () throws Exception {\n" +
1901 " System.out.println(\"D::D\");\n" +
1902 " throw new Exception (\"D::D\");\n" +
1903 " }\n" +
1904 " public void close() throws Exception {\n" +
1905 " System.out.println(\"D::~D\");\n" +
1906 " throw new Exception (\"D::~D\");\n" +
1907 " }\n" +
1908 "}\n" +
1909 "class E implements AutoCloseable {\n" +
1910 " public E () throws Exception {\n" +
1911 " System.out.println(\"E::E\");\n" +
1912 " throw new Exception (\"E::E\");\n" +
1913 " }\n" +
1914 " public void close() throws Exception {\n" +
1915 " System.out.println(\"E::~E\");\n" +
1916 " throw new Exception (\"E::~E\");\n" +
1917 " }\n" +
1918 "}\n" +
1919 "class F implements AutoCloseable {\n" +
1920 " public F () throws Exception {\n" +
1921 " System.out.println(\"F::F\");\n" +
1922 " throw new Exception (\"F::F\");\n" +
1923 " }\n" +
1924 " public void close() throws Exception {\n" +
1925 " System.out.println(\"F::~F\");\n" +
1926 " throw new Exception (\"F::~F\");\n" +
1927 " }\n" +
1928 "}\n" +
1929 "class G implements AutoCloseable {\n" +
1930 " public G () throws Exception {\n" +
1931 " System.out.println(\"G::G\");\n" +
1932 " throw new Exception (\"G::G\");\n" +
1933 " }\n" +
1934 " public void close() throws Exception {\n" +
1935 " System.out.println(\"G::~G\");\n" +
1936 " throw new Exception (\"G::~G\");\n" +
1937 " }\n" +
1938 "}\n"
1939 },
1940 "Main\n" +
1941 "A::A\n" +
1942 "B::B\n" +
1943 "Outer try\n" +
1944 "C::C\n" +
1945 "D::D\n" +
1946 "C::~C\n" +
1947 "B::~B\n" +
1948 "A::~A\n" +
1949 "java.lang.Exception: D::D\n" +
1950 "Suppressed: java.lang.Exception: C::~C\n" +
1951 "Suppressed: java.lang.Exception: B::~B\n" +
1952 "Suppressed: java.lang.Exception: A::~A\n" +
1953 "All done");
1954 }
test038()1955 public void test038() {
1956 this.runConformTest(
1957 new String[] {
1958 "X.java",
1959 "public class X {\n" +
1960 " public static void main(String [] args) {\n" +
1961 " System.out.println(\"Main\");\n" +
1962 " try (A a = new A(); B b = new B()) {\n" +
1963 " System.out.println(\"Outer try\");\n" +
1964 " try (C c = new C(); D d = new D();) {\n" +
1965 " System.out.println(\"Middle try\");\n" +
1966 " try (E e = new E(); F f = new F()) {\n" +
1967 " System.out.println(\"Inner try\");\n" +
1968 " throw new Exception(\"Body\");\n" +
1969 " } \n" +
1970 " }\n" +
1971 " } catch (Exception e) {\n" +
1972 " System.out.println(e);\n" +
1973 " Throwable suppressed [] = e.getSuppressed();\n" +
1974 " for (int i = 0; i < suppressed.length; ++i) {\n" +
1975 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
1976 " }\n" +
1977 " } finally {\n" +
1978 " System.out.println(\"All done\");\n" +
1979 " }\n" +
1980 " }\n" +
1981 "}\n" +
1982 "class A implements AutoCloseable {\n" +
1983 " public A () throws Exception {\n" +
1984 " System.out.println(\"A::A\");\n" +
1985 " }\n" +
1986 " public void close() throws Exception {\n" +
1987 " System.out.println(\"A::~A\");\n" +
1988 " throw new Exception (\"A::~A\");\n" +
1989 " }\n" +
1990 "}\n" +
1991 "class B implements AutoCloseable {\n" +
1992 " public B () throws Exception {\n" +
1993 " System.out.println(\"B::B\");\n" +
1994 " }\n" +
1995 " public void close() throws Exception {\n" +
1996 " System.out.println(\"B::~B\");\n" +
1997 " throw new Exception (\"B::~B\");\n" +
1998 " }\n" +
1999 "}\n" +
2000 "class C implements AutoCloseable {\n" +
2001 " public C () throws Exception {\n" +
2002 " System.out.println(\"C::C\");\n" +
2003 " }\n" +
2004 " public void close() throws Exception {\n" +
2005 " System.out.println(\"C::~C\");\n" +
2006 " throw new Exception (\"C::~C\");\n" +
2007 " }\n" +
2008 "}\n" +
2009 "class D implements AutoCloseable {\n" +
2010 " public D () throws Exception {\n" +
2011 " System.out.println(\"D::D\");\n" +
2012 " }\n" +
2013 " public void close() throws Exception {\n" +
2014 " System.out.println(\"D::~D\");\n" +
2015 " throw new Exception (\"D::~D\");\n" +
2016 " }\n" +
2017 "}\n" +
2018 "class E implements AutoCloseable {\n" +
2019 " public E () throws Exception {\n" +
2020 " System.out.println(\"E::E\");\n" +
2021 " throw new Exception (\"E::E\");\n" +
2022 " }\n" +
2023 " public void close() throws Exception {\n" +
2024 " System.out.println(\"E::~E\");\n" +
2025 " throw new Exception (\"E::~E\");\n" +
2026 " }\n" +
2027 "}\n" +
2028 "class F implements AutoCloseable {\n" +
2029 " public F () throws Exception {\n" +
2030 " System.out.println(\"F::F\");\n" +
2031 " throw new Exception (\"F::F\");\n" +
2032 " }\n" +
2033 " public void close() throws Exception {\n" +
2034 " System.out.println(\"F::~F\");\n" +
2035 " throw new Exception (\"F::~F\");\n" +
2036 " }\n" +
2037 "}\n" +
2038 "class G implements AutoCloseable {\n" +
2039 " public G () throws Exception {\n" +
2040 " System.out.println(\"G::G\");\n" +
2041 " throw new Exception (\"G::G\");\n" +
2042 " }\n" +
2043 " public void close() throws Exception {\n" +
2044 " System.out.println(\"G::~G\");\n" +
2045 " throw new Exception (\"G::~G\");\n" +
2046 " }\n" +
2047 "}\n"
2048 },
2049 "Main\n" +
2050 "A::A\n" +
2051 "B::B\n" +
2052 "Outer try\n" +
2053 "C::C\n" +
2054 "D::D\n" +
2055 "Middle try\n" +
2056 "E::E\n" +
2057 "D::~D\n" +
2058 "C::~C\n" +
2059 "B::~B\n" +
2060 "A::~A\n" +
2061 "java.lang.Exception: E::E\n" +
2062 "Suppressed: java.lang.Exception: D::~D\n" +
2063 "Suppressed: java.lang.Exception: C::~C\n" +
2064 "Suppressed: java.lang.Exception: B::~B\n" +
2065 "Suppressed: java.lang.Exception: A::~A\n" +
2066 "All done");
2067 }
test039()2068 public void test039() {
2069 this.runConformTest(
2070 new String[] {
2071 "X.java",
2072 "public class X {\n" +
2073 " public static void main(String [] args) {\n" +
2074 " System.out.println(\"Main\");\n" +
2075 " try (A a = new A(); B b = new B()) {\n" +
2076 " System.out.println(\"Outer try\");\n" +
2077 " try (C c = new C(); D d = new D();) {\n" +
2078 " System.out.println(\"Middle try\");\n" +
2079 " try (E e = new E(); F f = new F()) {\n" +
2080 " System.out.println(\"Inner try\");\n" +
2081 " throw new Exception(\"Body\");\n" +
2082 " } \n" +
2083 " }\n" +
2084 " } catch (Exception e) {\n" +
2085 " System.out.println(e);\n" +
2086 " Throwable suppressed [] = e.getSuppressed();\n" +
2087 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2088 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2089 " }\n" +
2090 " } finally {\n" +
2091 " System.out.println(\"All done\");\n" +
2092 " }\n" +
2093 " }\n" +
2094 "}\n" +
2095 "class A implements AutoCloseable {\n" +
2096 " public A () throws Exception {\n" +
2097 " System.out.println(\"A::A\");\n" +
2098 " }\n" +
2099 " public void close() throws Exception {\n" +
2100 " System.out.println(\"A::~A\");\n" +
2101 " throw new Exception (\"A::~A\");\n" +
2102 " }\n" +
2103 "}\n" +
2104 "class B implements AutoCloseable {\n" +
2105 " public B () throws Exception {\n" +
2106 " System.out.println(\"B::B\");\n" +
2107 " }\n" +
2108 " public void close() throws Exception {\n" +
2109 " System.out.println(\"B::~B\");\n" +
2110 " throw new Exception (\"B::~B\");\n" +
2111 " }\n" +
2112 "}\n" +
2113 "class C implements AutoCloseable {\n" +
2114 " public C () throws Exception {\n" +
2115 " System.out.println(\"C::C\");\n" +
2116 " }\n" +
2117 " public void close() throws Exception {\n" +
2118 " System.out.println(\"C::~C\");\n" +
2119 " throw new Exception (\"C::~C\");\n" +
2120 " }\n" +
2121 "}\n" +
2122 "class D implements AutoCloseable {\n" +
2123 " public D () throws Exception {\n" +
2124 " System.out.println(\"D::D\");\n" +
2125 " }\n" +
2126 " public void close() throws Exception {\n" +
2127 " System.out.println(\"D::~D\");\n" +
2128 " throw new Exception (\"D::~D\");\n" +
2129 " }\n" +
2130 "}\n" +
2131 "class E implements AutoCloseable {\n" +
2132 " public E () throws Exception {\n" +
2133 " System.out.println(\"E::E\");\n" +
2134 " }\n" +
2135 " public void close() throws Exception {\n" +
2136 " System.out.println(\"E::~E\");\n" +
2137 " throw new Exception (\"E::~E\");\n" +
2138 " }\n" +
2139 "}\n" +
2140 "class F implements AutoCloseable {\n" +
2141 " public F () throws Exception {\n" +
2142 " System.out.println(\"F::F\");\n" +
2143 " throw new Exception (\"F::F\");\n" +
2144 " }\n" +
2145 " public void close() throws Exception {\n" +
2146 " System.out.println(\"F::~F\");\n" +
2147 " throw new Exception (\"F::~F\");\n" +
2148 " }\n" +
2149 "}\n" +
2150 "class G implements AutoCloseable {\n" +
2151 " public G () throws Exception {\n" +
2152 " System.out.println(\"G::G\");\n" +
2153 " throw new Exception (\"G::G\");\n" +
2154 " }\n" +
2155 " public void close() throws Exception {\n" +
2156 " System.out.println(\"G::~G\");\n" +
2157 " throw new Exception (\"G::~G\");\n" +
2158 " }\n" +
2159 "}\n"
2160 },
2161 "Main\n" +
2162 "A::A\n" +
2163 "B::B\n" +
2164 "Outer try\n" +
2165 "C::C\n" +
2166 "D::D\n" +
2167 "Middle try\n" +
2168 "E::E\n" +
2169 "F::F\n" +
2170 "E::~E\n" +
2171 "D::~D\n" +
2172 "C::~C\n" +
2173 "B::~B\n" +
2174 "A::~A\n" +
2175 "java.lang.Exception: F::F\n" +
2176 "Suppressed: java.lang.Exception: E::~E\n" +
2177 "Suppressed: java.lang.Exception: D::~D\n" +
2178 "Suppressed: java.lang.Exception: C::~C\n" +
2179 "Suppressed: java.lang.Exception: B::~B\n" +
2180 "Suppressed: java.lang.Exception: A::~A\n" +
2181 "All done");
2182 }
test040()2183 public void test040() {
2184 this.runConformTest(
2185 new String[] {
2186 "X.java",
2187 "public class X {\n" +
2188 " public static void main(String [] args) {\n" +
2189 " System.out.println(\"Main\");\n" +
2190 " try (A a = new A(); B b = new B()) {\n" +
2191 " System.out.println(\"Outer try\");\n" +
2192 " try (C c = new C(); D d = new D();) {\n" +
2193 " System.out.println(\"Middle try\");\n" +
2194 " try (E e = new E(); F f = new F()) {\n" +
2195 " System.out.println(\"Inner try\");\n" +
2196 " throw new Exception(\"Body\");\n" +
2197 " } \n" +
2198 " }\n" +
2199 " } catch (Exception e) {\n" +
2200 " System.out.println(e);\n" +
2201 " Throwable suppressed [] = e.getSuppressed();\n" +
2202 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2203 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2204 " }\n" +
2205 " } finally {\n" +
2206 " System.out.println(\"All done\");\n" +
2207 " }\n" +
2208 " }\n" +
2209 "}\n" +
2210 "class A implements AutoCloseable {\n" +
2211 " public A () throws Exception {\n" +
2212 " System.out.println(\"A::A\");\n" +
2213 " }\n" +
2214 " public void close() throws Exception {\n" +
2215 " System.out.println(\"A::~A\");\n" +
2216 " throw new Exception (\"A::~A\");\n" +
2217 " }\n" +
2218 "}\n" +
2219 "class B implements AutoCloseable {\n" +
2220 " public B () throws Exception {\n" +
2221 " System.out.println(\"B::B\");\n" +
2222 " }\n" +
2223 " public void close() throws Exception {\n" +
2224 " System.out.println(\"B::~B\");\n" +
2225 " throw new Exception (\"B::~B\");\n" +
2226 " }\n" +
2227 "}\n" +
2228 "class C implements AutoCloseable {\n" +
2229 " public C () throws Exception {\n" +
2230 " System.out.println(\"C::C\");\n" +
2231 " }\n" +
2232 " public void close() throws Exception {\n" +
2233 " System.out.println(\"C::~C\");\n" +
2234 " throw new Exception (\"C::~C\");\n" +
2235 " }\n" +
2236 "}\n" +
2237 "class D implements AutoCloseable {\n" +
2238 " public D () throws Exception {\n" +
2239 " System.out.println(\"D::D\");\n" +
2240 " }\n" +
2241 " public void close() throws Exception {\n" +
2242 " System.out.println(\"D::~D\");\n" +
2243 " throw new Exception (\"D::~D\");\n" +
2244 " }\n" +
2245 "}\n" +
2246 "class E implements AutoCloseable {\n" +
2247 " public E () throws Exception {\n" +
2248 " System.out.println(\"E::E\");\n" +
2249 " }\n" +
2250 " public void close() throws Exception {\n" +
2251 " System.out.println(\"E::~E\");\n" +
2252 " throw new Exception (\"E::~E\");\n" +
2253 " }\n" +
2254 "}\n" +
2255 "class F implements AutoCloseable {\n" +
2256 " public F () throws Exception {\n" +
2257 " System.out.println(\"F::F\");\n" +
2258 " }\n" +
2259 " public void close() throws Exception {\n" +
2260 " System.out.println(\"F::~F\");\n" +
2261 " throw new Exception (\"F::~F\");\n" +
2262 " }\n" +
2263 "}\n" +
2264 "class G implements AutoCloseable {\n" +
2265 " public G () throws Exception {\n" +
2266 " System.out.println(\"G::G\");\n" +
2267 " throw new Exception (\"G::G\");\n" +
2268 " }\n" +
2269 " public void close() throws Exception {\n" +
2270 " System.out.println(\"G::~G\");\n" +
2271 " throw new Exception (\"G::~G\");\n" +
2272 " }\n" +
2273 "}\n"
2274 },
2275 "Main\n" +
2276 "A::A\n" +
2277 "B::B\n" +
2278 "Outer try\n" +
2279 "C::C\n" +
2280 "D::D\n" +
2281 "Middle try\n" +
2282 "E::E\n" +
2283 "F::F\n" +
2284 "Inner try\n" +
2285 "F::~F\n" +
2286 "E::~E\n" +
2287 "D::~D\n" +
2288 "C::~C\n" +
2289 "B::~B\n" +
2290 "A::~A\n" +
2291 "java.lang.Exception: Body\n" +
2292 "Suppressed: java.lang.Exception: F::~F\n" +
2293 "Suppressed: java.lang.Exception: E::~E\n" +
2294 "Suppressed: java.lang.Exception: D::~D\n" +
2295 "Suppressed: java.lang.Exception: C::~C\n" +
2296 "Suppressed: java.lang.Exception: B::~B\n" +
2297 "Suppressed: java.lang.Exception: A::~A\n" +
2298 "All done");
2299 }
test041()2300 public void test041() {
2301 this.runConformTest(
2302 new String[] {
2303 "X.java",
2304 "public class X {\n" +
2305 " public static void main(String [] args) {\n" +
2306 " System.out.println(\"Main\");\n" +
2307 " try (A a = new A(); B b = new B()) {\n" +
2308 " System.out.println(\"Outer try\");\n" +
2309 " try (C c = new C(); D d = new D();) {\n" +
2310 " System.out.println(\"Middle try\");\n" +
2311 " try (E e = new E(); F f = new F()) {\n" +
2312 " System.out.println(\"Inner try\");\n" +
2313 " } \n" +
2314 " }\n" +
2315 " } catch (Exception e) {\n" +
2316 " System.out.println(e);\n" +
2317 " Throwable suppressed [] = e.getSuppressed();\n" +
2318 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2319 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2320 " }\n" +
2321 " } finally {\n" +
2322 " System.out.println(\"All done\");\n" +
2323 " }\n" +
2324 " }\n" +
2325 "}\n" +
2326 "class A implements AutoCloseable {\n" +
2327 " public A () throws Exception {\n" +
2328 " System.out.println(\"A::A\");\n" +
2329 " }\n" +
2330 " public void close() throws Exception {\n" +
2331 " System.out.println(\"A::~A\");\n" +
2332 " throw new Exception (\"A::~A\");\n" +
2333 " }\n" +
2334 "}\n" +
2335 "class B implements AutoCloseable {\n" +
2336 " public B () throws Exception {\n" +
2337 " System.out.println(\"B::B\");\n" +
2338 " }\n" +
2339 " public void close() throws Exception {\n" +
2340 " System.out.println(\"B::~B\");\n" +
2341 " throw new Exception (\"B::~B\");\n" +
2342 " }\n" +
2343 "}\n" +
2344 "class C implements AutoCloseable {\n" +
2345 " public C () throws Exception {\n" +
2346 " System.out.println(\"C::C\");\n" +
2347 " }\n" +
2348 " public void close() throws Exception {\n" +
2349 " System.out.println(\"C::~C\");\n" +
2350 " throw new Exception (\"C::~C\");\n" +
2351 " }\n" +
2352 "}\n" +
2353 "class D implements AutoCloseable {\n" +
2354 " public D () throws Exception {\n" +
2355 " System.out.println(\"D::D\");\n" +
2356 " }\n" +
2357 " public void close() throws Exception {\n" +
2358 " System.out.println(\"D::~D\");\n" +
2359 " throw new Exception (\"D::~D\");\n" +
2360 " }\n" +
2361 "}\n" +
2362 "class E implements AutoCloseable {\n" +
2363 " public E () throws Exception {\n" +
2364 " System.out.println(\"E::E\");\n" +
2365 " }\n" +
2366 " public void close() throws Exception {\n" +
2367 " System.out.println(\"E::~E\");\n" +
2368 " throw new Exception (\"E::~E\");\n" +
2369 " }\n" +
2370 "}\n" +
2371 "class F implements AutoCloseable {\n" +
2372 " public F () throws Exception {\n" +
2373 " System.out.println(\"F::F\");\n" +
2374 " }\n" +
2375 " public void close() throws Exception {\n" +
2376 " System.out.println(\"F::~F\");\n" +
2377 " throw new Exception (\"F::~F\");\n" +
2378 " }\n" +
2379 "}\n" +
2380 "class G implements AutoCloseable {\n" +
2381 " public G () throws Exception {\n" +
2382 " System.out.println(\"G::G\");\n" +
2383 " throw new Exception (\"G::G\");\n" +
2384 " }\n" +
2385 " public void close() throws Exception {\n" +
2386 " System.out.println(\"G::~G\");\n" +
2387 " throw new Exception (\"G::~G\");\n" +
2388 " }\n" +
2389 "}\n"
2390 },
2391 "Main\n" +
2392 "A::A\n" +
2393 "B::B\n" +
2394 "Outer try\n" +
2395 "C::C\n" +
2396 "D::D\n" +
2397 "Middle try\n" +
2398 "E::E\n" +
2399 "F::F\n" +
2400 "Inner try\n" +
2401 "F::~F\n" +
2402 "E::~E\n" +
2403 "D::~D\n" +
2404 "C::~C\n" +
2405 "B::~B\n" +
2406 "A::~A\n" +
2407 "java.lang.Exception: F::~F\n" +
2408 "Suppressed: java.lang.Exception: E::~E\n" +
2409 "Suppressed: java.lang.Exception: D::~D\n" +
2410 "Suppressed: java.lang.Exception: C::~C\n" +
2411 "Suppressed: java.lang.Exception: B::~B\n" +
2412 "Suppressed: java.lang.Exception: A::~A\n" +
2413 "All done");
2414 }
test042()2415 public void test042() {
2416 this.runConformTest(
2417 new String[] {
2418 "X.java",
2419 "public class X {\n" +
2420 " public static void main(String [] args) {\n" +
2421 " System.out.println(\"Main\");\n" +
2422 " try (A a = new A(); B b = new B()) {\n" +
2423 " System.out.println(\"Outer try\");\n" +
2424 " try (C c = new C(); D d = new D();) {\n" +
2425 " System.out.println(\"Middle try\");\n" +
2426 " try (E e = new E(); F f = new F()) {\n" +
2427 " System.out.println(\"Inner try\");\n" +
2428 " } \n" +
2429 " }\n" +
2430 " } catch (Exception e) {\n" +
2431 " System.out.println(e);\n" +
2432 " Throwable suppressed [] = e.getSuppressed();\n" +
2433 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2434 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2435 " }\n" +
2436 " } finally {\n" +
2437 " System.out.println(\"All done\");\n" +
2438 " }\n" +
2439 " }\n" +
2440 "}\n" +
2441 "class A implements AutoCloseable {\n" +
2442 " public A () throws Exception {\n" +
2443 " System.out.println(\"A::A\");\n" +
2444 " }\n" +
2445 " public void close() throws Exception {\n" +
2446 " System.out.println(\"A::~A\");\n" +
2447 " throw new Exception (\"A::~A\");\n" +
2448 " }\n" +
2449 "}\n" +
2450 "class B implements AutoCloseable {\n" +
2451 " public B () throws Exception {\n" +
2452 " System.out.println(\"B::B\");\n" +
2453 " }\n" +
2454 " public void close() throws Exception {\n" +
2455 " System.out.println(\"B::~B\");\n" +
2456 " throw new Exception (\"B::~B\");\n" +
2457 " }\n" +
2458 "}\n" +
2459 "class C implements AutoCloseable {\n" +
2460 " public C () throws Exception {\n" +
2461 " System.out.println(\"C::C\");\n" +
2462 " }\n" +
2463 " public void close() throws Exception {\n" +
2464 " System.out.println(\"C::~C\");\n" +
2465 " throw new Exception (\"C::~C\");\n" +
2466 " }\n" +
2467 "}\n" +
2468 "class D implements AutoCloseable {\n" +
2469 " public D () throws Exception {\n" +
2470 " System.out.println(\"D::D\");\n" +
2471 " }\n" +
2472 " public void close() throws Exception {\n" +
2473 " System.out.println(\"D::~D\");\n" +
2474 " throw new Exception (\"D::~D\");\n" +
2475 " }\n" +
2476 "}\n" +
2477 "class E implements AutoCloseable {\n" +
2478 " public E () throws Exception {\n" +
2479 " System.out.println(\"E::E\");\n" +
2480 " }\n" +
2481 " public void close() throws Exception {\n" +
2482 " System.out.println(\"E::~E\");\n" +
2483 " throw new Exception (\"E::~E\");\n" +
2484 " }\n" +
2485 "}\n" +
2486 "class F implements AutoCloseable {\n" +
2487 " public F () throws Exception {\n" +
2488 " System.out.println(\"F::F\");\n" +
2489 " }\n" +
2490 " public void close() throws Exception {\n" +
2491 " System.out.println(\"F::~F\");\n" +
2492 " }\n" +
2493 "}\n" +
2494 "class G implements AutoCloseable {\n" +
2495 " public G () throws Exception {\n" +
2496 " System.out.println(\"G::G\");\n" +
2497 " throw new Exception (\"G::G\");\n" +
2498 " }\n" +
2499 " public void close() throws Exception {\n" +
2500 " System.out.println(\"G::~G\");\n" +
2501 " throw new Exception (\"G::~G\");\n" +
2502 " }\n" +
2503 "}\n"
2504 },
2505 "Main\n" +
2506 "A::A\n" +
2507 "B::B\n" +
2508 "Outer try\n" +
2509 "C::C\n" +
2510 "D::D\n" +
2511 "Middle try\n" +
2512 "E::E\n" +
2513 "F::F\n" +
2514 "Inner try\n" +
2515 "F::~F\n" +
2516 "E::~E\n" +
2517 "D::~D\n" +
2518 "C::~C\n" +
2519 "B::~B\n" +
2520 "A::~A\n" +
2521 "java.lang.Exception: E::~E\n" +
2522 "Suppressed: java.lang.Exception: D::~D\n" +
2523 "Suppressed: java.lang.Exception: C::~C\n" +
2524 "Suppressed: java.lang.Exception: B::~B\n" +
2525 "Suppressed: java.lang.Exception: A::~A\n" +
2526 "All done");
2527 }
test043()2528 public void test043() {
2529 this.runConformTest(
2530 new String[] {
2531 "X.java",
2532 "public class X {\n" +
2533 " public static void main(String [] args) {\n" +
2534 " System.out.println(\"Main\");\n" +
2535 " try (A a = new A(); B b = new B()) {\n" +
2536 " System.out.println(\"Outer try\");\n" +
2537 " try (C c = new C(); D d = new D();) {\n" +
2538 " System.out.println(\"Middle try\");\n" +
2539 " try (E e = new E(); F f = new F()) {\n" +
2540 " System.out.println(\"Inner try\");\n" +
2541 " } \n" +
2542 " }\n" +
2543 " } catch (Exception e) {\n" +
2544 " System.out.println(e);\n" +
2545 " Throwable suppressed [] = e.getSuppressed();\n" +
2546 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2547 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2548 " }\n" +
2549 " } finally {\n" +
2550 " System.out.println(\"All done\");\n" +
2551 " }\n" +
2552 " }\n" +
2553 "}\n" +
2554 "class A implements AutoCloseable {\n" +
2555 " public A () throws Exception {\n" +
2556 " System.out.println(\"A::A\");\n" +
2557 " }\n" +
2558 " public void close() throws Exception {\n" +
2559 " System.out.println(\"A::~A\");\n" +
2560 " throw new Exception (\"A::~A\");\n" +
2561 " }\n" +
2562 "}\n" +
2563 "class B implements AutoCloseable {\n" +
2564 " public B () throws Exception {\n" +
2565 " System.out.println(\"B::B\");\n" +
2566 " }\n" +
2567 " public void close() throws Exception {\n" +
2568 " System.out.println(\"B::~B\");\n" +
2569 " throw new Exception (\"B::~B\");\n" +
2570 " }\n" +
2571 "}\n" +
2572 "class C implements AutoCloseable {\n" +
2573 " public C () throws Exception {\n" +
2574 " System.out.println(\"C::C\");\n" +
2575 " }\n" +
2576 " public void close() throws Exception {\n" +
2577 " System.out.println(\"C::~C\");\n" +
2578 " throw new Exception (\"C::~C\");\n" +
2579 " }\n" +
2580 "}\n" +
2581 "class D implements AutoCloseable {\n" +
2582 " public D () throws Exception {\n" +
2583 " System.out.println(\"D::D\");\n" +
2584 " }\n" +
2585 " public void close() throws Exception {\n" +
2586 " System.out.println(\"D::~D\");\n" +
2587 " throw new Exception (\"D::~D\");\n" +
2588 " }\n" +
2589 "}\n" +
2590 "class E implements AutoCloseable {\n" +
2591 " public E () throws Exception {\n" +
2592 " System.out.println(\"E::E\");\n" +
2593 " }\n" +
2594 " public void close() throws Exception {\n" +
2595 " System.out.println(\"E::~E\");\n" +
2596 " }\n" +
2597 "}\n" +
2598 "class F implements AutoCloseable {\n" +
2599 " public F () throws Exception {\n" +
2600 " System.out.println(\"F::F\");\n" +
2601 " }\n" +
2602 " public void close() throws Exception {\n" +
2603 " System.out.println(\"F::~F\");\n" +
2604 " }\n" +
2605 "}\n" +
2606 "class G implements AutoCloseable {\n" +
2607 " public G () throws Exception {\n" +
2608 " System.out.println(\"G::G\");\n" +
2609 " throw new Exception (\"G::G\");\n" +
2610 " }\n" +
2611 " public void close() throws Exception {\n" +
2612 " System.out.println(\"G::~G\");\n" +
2613 " throw new Exception (\"G::~G\");\n" +
2614 " }\n" +
2615 "}\n"
2616 },
2617 "Main\n" +
2618 "A::A\n" +
2619 "B::B\n" +
2620 "Outer try\n" +
2621 "C::C\n" +
2622 "D::D\n" +
2623 "Middle try\n" +
2624 "E::E\n" +
2625 "F::F\n" +
2626 "Inner try\n" +
2627 "F::~F\n" +
2628 "E::~E\n" +
2629 "D::~D\n" +
2630 "C::~C\n" +
2631 "B::~B\n" +
2632 "A::~A\n" +
2633 "java.lang.Exception: D::~D\n" +
2634 "Suppressed: java.lang.Exception: C::~C\n" +
2635 "Suppressed: java.lang.Exception: B::~B\n" +
2636 "Suppressed: java.lang.Exception: A::~A\n" +
2637 "All done");
2638 }
test044()2639 public void test044() {
2640 this.runConformTest(
2641 new String[] {
2642 "X.java",
2643 "public class X {\n" +
2644 " public static void main(String [] args) {\n" +
2645 " System.out.println(\"Main\");\n" +
2646 " try (A a = new A(); B b = new B()) {\n" +
2647 " System.out.println(\"Outer try\");\n" +
2648 " try (C c = new C(); D d = new D();) {\n" +
2649 " System.out.println(\"Middle try\");\n" +
2650 " try (E e = new E(); F f = new F()) {\n" +
2651 " System.out.println(\"Inner try\");\n" +
2652 " } \n" +
2653 " }\n" +
2654 " } catch (Exception e) {\n" +
2655 " System.out.println(e);\n" +
2656 " Throwable suppressed [] = e.getSuppressed();\n" +
2657 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2658 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2659 " }\n" +
2660 " } finally {\n" +
2661 " System.out.println(\"All done\");\n" +
2662 " }\n" +
2663 " }\n" +
2664 "}\n" +
2665 "class A implements AutoCloseable {\n" +
2666 " public A () throws Exception {\n" +
2667 " System.out.println(\"A::A\");\n" +
2668 " }\n" +
2669 " public void close() throws Exception {\n" +
2670 " System.out.println(\"A::~A\");\n" +
2671 " throw new Exception (\"A::~A\");\n" +
2672 " }\n" +
2673 "}\n" +
2674 "class B implements AutoCloseable {\n" +
2675 " public B () throws Exception {\n" +
2676 " System.out.println(\"B::B\");\n" +
2677 " }\n" +
2678 " public void close() throws Exception {\n" +
2679 " System.out.println(\"B::~B\");\n" +
2680 " throw new Exception (\"B::~B\");\n" +
2681 " }\n" +
2682 "}\n" +
2683 "class C implements AutoCloseable {\n" +
2684 " public C () throws Exception {\n" +
2685 " System.out.println(\"C::C\");\n" +
2686 " }\n" +
2687 " public void close() throws Exception {\n" +
2688 " System.out.println(\"C::~C\");\n" +
2689 " throw new Exception (\"C::~C\");\n" +
2690 " }\n" +
2691 "}\n" +
2692 "class D implements AutoCloseable {\n" +
2693 " public D () throws Exception {\n" +
2694 " System.out.println(\"D::D\");\n" +
2695 " }\n" +
2696 " public void close() throws Exception {\n" +
2697 " System.out.println(\"D::~D\");\n" +
2698 " }\n" +
2699 "}\n" +
2700 "class E implements AutoCloseable {\n" +
2701 " public E () throws Exception {\n" +
2702 " System.out.println(\"E::E\");\n" +
2703 " }\n" +
2704 " public void close() throws Exception {\n" +
2705 " System.out.println(\"E::~E\");\n" +
2706 " }\n" +
2707 "}\n" +
2708 "class F implements AutoCloseable {\n" +
2709 " public F () throws Exception {\n" +
2710 " System.out.println(\"F::F\");\n" +
2711 " }\n" +
2712 " public void close() throws Exception {\n" +
2713 " System.out.println(\"F::~F\");\n" +
2714 " }\n" +
2715 "}\n" +
2716 "class G implements AutoCloseable {\n" +
2717 " public G () throws Exception {\n" +
2718 " System.out.println(\"G::G\");\n" +
2719 " throw new Exception (\"G::G\");\n" +
2720 " }\n" +
2721 " public void close() throws Exception {\n" +
2722 " System.out.println(\"G::~G\");\n" +
2723 " throw new Exception (\"G::~G\");\n" +
2724 " }\n" +
2725 "}\n"
2726 },
2727 "Main\n" +
2728 "A::A\n" +
2729 "B::B\n" +
2730 "Outer try\n" +
2731 "C::C\n" +
2732 "D::D\n" +
2733 "Middle try\n" +
2734 "E::E\n" +
2735 "F::F\n" +
2736 "Inner try\n" +
2737 "F::~F\n" +
2738 "E::~E\n" +
2739 "D::~D\n" +
2740 "C::~C\n" +
2741 "B::~B\n" +
2742 "A::~A\n" +
2743 "java.lang.Exception: C::~C\n" +
2744 "Suppressed: java.lang.Exception: B::~B\n" +
2745 "Suppressed: java.lang.Exception: A::~A\n" +
2746 "All done");
2747 }
test045()2748 public void test045() {
2749 this.runConformTest(
2750 new String[] {
2751 "X.java",
2752 "public class X {\n" +
2753 " public static void main(String [] args) {\n" +
2754 " System.out.println(\"Main\");\n" +
2755 " try (A a = new A(); B b = new B()) {\n" +
2756 " System.out.println(\"Outer try\");\n" +
2757 " try (C c = new C(); D d = new D();) {\n" +
2758 " System.out.println(\"Middle try\");\n" +
2759 " try (E e = new E(); F f = new F()) {\n" +
2760 " System.out.println(\"Inner try\");\n" +
2761 " } \n" +
2762 " }\n" +
2763 " } catch (Exception e) {\n" +
2764 " System.out.println(e);\n" +
2765 " Throwable suppressed [] = e.getSuppressed();\n" +
2766 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2767 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2768 " }\n" +
2769 " } finally {\n" +
2770 " System.out.println(\"All done\");\n" +
2771 " }\n" +
2772 " }\n" +
2773 "}\n" +
2774 "class A implements AutoCloseable {\n" +
2775 " public A () throws Exception {\n" +
2776 " System.out.println(\"A::A\");\n" +
2777 " }\n" +
2778 " public void close() throws Exception {\n" +
2779 " System.out.println(\"A::~A\");\n" +
2780 " throw new Exception (\"A::~A\");\n" +
2781 " }\n" +
2782 "}\n" +
2783 "class B implements AutoCloseable {\n" +
2784 " public B () throws Exception {\n" +
2785 " System.out.println(\"B::B\");\n" +
2786 " }\n" +
2787 " public void close() throws Exception {\n" +
2788 " System.out.println(\"B::~B\");\n" +
2789 " throw new Exception (\"B::~B\");\n" +
2790 " }\n" +
2791 "}\n" +
2792 "class C implements AutoCloseable {\n" +
2793 " public C () throws Exception {\n" +
2794 " System.out.println(\"C::C\");\n" +
2795 " }\n" +
2796 " public void close() throws Exception {\n" +
2797 " System.out.println(\"C::~C\");\n" +
2798 " }\n" +
2799 "}\n" +
2800 "class D implements AutoCloseable {\n" +
2801 " public D () throws Exception {\n" +
2802 " System.out.println(\"D::D\");\n" +
2803 " }\n" +
2804 " public void close() throws Exception {\n" +
2805 " System.out.println(\"D::~D\");\n" +
2806 " }\n" +
2807 "}\n" +
2808 "class E implements AutoCloseable {\n" +
2809 " public E () throws Exception {\n" +
2810 " System.out.println(\"E::E\");\n" +
2811 " }\n" +
2812 " public void close() throws Exception {\n" +
2813 " System.out.println(\"E::~E\");\n" +
2814 " }\n" +
2815 "}\n" +
2816 "class F implements AutoCloseable {\n" +
2817 " public F () throws Exception {\n" +
2818 " System.out.println(\"F::F\");\n" +
2819 " }\n" +
2820 " public void close() throws Exception {\n" +
2821 " System.out.println(\"F::~F\");\n" +
2822 " }\n" +
2823 "}\n" +
2824 "class G implements AutoCloseable {\n" +
2825 " public G () throws Exception {\n" +
2826 " System.out.println(\"G::G\");\n" +
2827 " throw new Exception (\"G::G\");\n" +
2828 " }\n" +
2829 " public void close() throws Exception {\n" +
2830 " System.out.println(\"G::~G\");\n" +
2831 " throw new Exception (\"G::~G\");\n" +
2832 " }\n" +
2833 "}\n"
2834 },
2835 "Main\n" +
2836 "A::A\n" +
2837 "B::B\n" +
2838 "Outer try\n" +
2839 "C::C\n" +
2840 "D::D\n" +
2841 "Middle try\n" +
2842 "E::E\n" +
2843 "F::F\n" +
2844 "Inner try\n" +
2845 "F::~F\n" +
2846 "E::~E\n" +
2847 "D::~D\n" +
2848 "C::~C\n" +
2849 "B::~B\n" +
2850 "A::~A\n" +
2851 "java.lang.Exception: B::~B\n" +
2852 "Suppressed: java.lang.Exception: A::~A\n" +
2853 "All done");
2854 }
test046()2855 public void test046() {
2856 this.runConformTest(
2857 new String[] {
2858 "X.java",
2859 "public class X {\n" +
2860 " public static void main(String [] args) {\n" +
2861 " System.out.println(\"Main\");\n" +
2862 " try (A a = new A(); B b = new B()) {\n" +
2863 " System.out.println(\"Outer try\");\n" +
2864 " try (C c = new C(); D d = new D();) {\n" +
2865 " System.out.println(\"Middle try\");\n" +
2866 " try (E e = new E(); F f = new F()) {\n" +
2867 " System.out.println(\"Inner try\");\n" +
2868 " } \n" +
2869 " }\n" +
2870 " } catch (Exception e) {\n" +
2871 " System.out.println(e);\n" +
2872 " Throwable suppressed [] = e.getSuppressed();\n" +
2873 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2874 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2875 " }\n" +
2876 " } finally {\n" +
2877 " System.out.println(\"All done\");\n" +
2878 " }\n" +
2879 " }\n" +
2880 "}\n" +
2881 "class A implements AutoCloseable {\n" +
2882 " public A () throws Exception {\n" +
2883 " System.out.println(\"A::A\");\n" +
2884 " }\n" +
2885 " public void close() throws Exception {\n" +
2886 " System.out.println(\"A::~A\");\n" +
2887 " throw new Exception (\"A::~A\");\n" +
2888 " }\n" +
2889 "}\n" +
2890 "class B implements AutoCloseable {\n" +
2891 " public B () throws Exception {\n" +
2892 " System.out.println(\"B::B\");\n" +
2893 " }\n" +
2894 " public void close() throws Exception {\n" +
2895 " System.out.println(\"B::~B\");\n" +
2896 " }\n" +
2897 "}\n" +
2898 "class C implements AutoCloseable {\n" +
2899 " public C () throws Exception {\n" +
2900 " System.out.println(\"C::C\");\n" +
2901 " }\n" +
2902 " public void close() throws Exception {\n" +
2903 " System.out.println(\"C::~C\");\n" +
2904 " }\n" +
2905 "}\n" +
2906 "class D implements AutoCloseable {\n" +
2907 " public D () throws Exception {\n" +
2908 " System.out.println(\"D::D\");\n" +
2909 " }\n" +
2910 " public void close() throws Exception {\n" +
2911 " System.out.println(\"D::~D\");\n" +
2912 " }\n" +
2913 "}\n" +
2914 "class E implements AutoCloseable {\n" +
2915 " public E () throws Exception {\n" +
2916 " System.out.println(\"E::E\");\n" +
2917 " }\n" +
2918 " public void close() throws Exception {\n" +
2919 " System.out.println(\"E::~E\");\n" +
2920 " }\n" +
2921 "}\n" +
2922 "class F implements AutoCloseable {\n" +
2923 " public F () throws Exception {\n" +
2924 " System.out.println(\"F::F\");\n" +
2925 " }\n" +
2926 " public void close() throws Exception {\n" +
2927 " System.out.println(\"F::~F\");\n" +
2928 " }\n" +
2929 "}\n" +
2930 "class G implements AutoCloseable {\n" +
2931 " public G () throws Exception {\n" +
2932 " System.out.println(\"G::G\");\n" +
2933 " throw new Exception (\"G::G\");\n" +
2934 " }\n" +
2935 " public void close() throws Exception {\n" +
2936 " System.out.println(\"G::~G\");\n" +
2937 " throw new Exception (\"G::~G\");\n" +
2938 " }\n" +
2939 "}\n"
2940 },
2941 "Main\n" +
2942 "A::A\n" +
2943 "B::B\n" +
2944 "Outer try\n" +
2945 "C::C\n" +
2946 "D::D\n" +
2947 "Middle try\n" +
2948 "E::E\n" +
2949 "F::F\n" +
2950 "Inner try\n" +
2951 "F::~F\n" +
2952 "E::~E\n" +
2953 "D::~D\n" +
2954 "C::~C\n" +
2955 "B::~B\n" +
2956 "A::~A\n" +
2957 "java.lang.Exception: A::~A\n" +
2958 "All done");
2959 }
test047()2960 public void test047() {
2961 this.runConformTest(
2962 new String[] {
2963 "X.java",
2964 "public class X {\n" +
2965 " public static void main(String [] args) {\n" +
2966 " System.out.println(\"Main\");\n" +
2967 " try (A a = new A(); B b = new B()) {\n" +
2968 " System.out.println(\"Outer try\");\n" +
2969 " try (C c = new C(); D d = new D();) {\n" +
2970 " System.out.println(\"Middle try\");\n" +
2971 " try (E e = new E(); F f = new F()) {\n" +
2972 " System.out.println(\"Inner try\");\n" +
2973 " } \n" +
2974 " }\n" +
2975 " } catch (Exception e) {\n" +
2976 " System.out.println(e);\n" +
2977 " Throwable suppressed [] = e.getSuppressed();\n" +
2978 " for (int i = 0; i < suppressed.length; ++i) {\n" +
2979 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
2980 " }\n" +
2981 " } finally {\n" +
2982 " System.out.println(\"All done\");\n" +
2983 " }\n" +
2984 " }\n" +
2985 "}\n" +
2986 "class A implements AutoCloseable {\n" +
2987 " public A () throws Exception {\n" +
2988 " System.out.println(\"A::A\");\n" +
2989 " }\n" +
2990 " public void close() throws Exception {\n" +
2991 " System.out.println(\"A::~A\");\n" +
2992 " }\n" +
2993 "}\n" +
2994 "class B implements AutoCloseable {\n" +
2995 " public B () throws Exception {\n" +
2996 " System.out.println(\"B::B\");\n" +
2997 " }\n" +
2998 " public void close() throws Exception {\n" +
2999 " System.out.println(\"B::~B\");\n" +
3000 " }\n" +
3001 "}\n" +
3002 "class C implements AutoCloseable {\n" +
3003 " public C () throws Exception {\n" +
3004 " System.out.println(\"C::C\");\n" +
3005 " }\n" +
3006 " public void close() throws Exception {\n" +
3007 " System.out.println(\"C::~C\");\n" +
3008 " }\n" +
3009 "}\n" +
3010 "class D implements AutoCloseable {\n" +
3011 " public D () throws Exception {\n" +
3012 " System.out.println(\"D::D\");\n" +
3013 " }\n" +
3014 " public void close() throws Exception {\n" +
3015 " System.out.println(\"D::~D\");\n" +
3016 " }\n" +
3017 "}\n" +
3018 "class E implements AutoCloseable {\n" +
3019 " public E () throws Exception {\n" +
3020 " System.out.println(\"E::E\");\n" +
3021 " }\n" +
3022 " public void close() throws Exception {\n" +
3023 " System.out.println(\"E::~E\");\n" +
3024 " }\n" +
3025 "}\n" +
3026 "class F implements AutoCloseable {\n" +
3027 " public F () throws Exception {\n" +
3028 " System.out.println(\"F::F\");\n" +
3029 " }\n" +
3030 " public void close() throws Exception {\n" +
3031 " System.out.println(\"F::~F\");\n" +
3032 " }\n" +
3033 "}\n" +
3034 "class G implements AutoCloseable {\n" +
3035 " public G () throws Exception {\n" +
3036 " System.out.println(\"G::G\");\n" +
3037 " throw new Exception (\"G::G\");\n" +
3038 " }\n" +
3039 " public void close() throws Exception {\n" +
3040 " System.out.println(\"G::~G\");\n" +
3041 " throw new Exception (\"G::~G\");\n" +
3042 " }\n" +
3043 "}\n"
3044 },
3045 "Main\n" +
3046 "A::A\n" +
3047 "B::B\n" +
3048 "Outer try\n" +
3049 "C::C\n" +
3050 "D::D\n" +
3051 "Middle try\n" +
3052 "E::E\n" +
3053 "F::F\n" +
3054 "Inner try\n" +
3055 "F::~F\n" +
3056 "E::~E\n" +
3057 "D::~D\n" +
3058 "C::~C\n" +
3059 "B::~B\n" +
3060 "A::~A\n" +
3061 "All done");
3062 }
test048()3063 public void test048() {
3064 this.runConformTest(
3065 new String[] {
3066 "X.java",
3067 "public class X {\n" +
3068 " public static void main(String [] args) {\n" +
3069 " System.out.println(\"Main\");\n" +
3070 " try (A a = new A()) {\n" +
3071 " System.out.println(\"X::Try\");\n" +
3072 " throw new Exception(\"X::Main\");\n" +
3073 " } catch (Exception e) {\n" +
3074 " System.out.println(e);\n" +
3075 " Throwable suppressed [] = e.getSuppressed();\n" +
3076 " for (int i = 0; i < suppressed.length; ++i) {\n" +
3077 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
3078 " }\n" +
3079 " } finally {\n" +
3080 " System.out.println(\"All done\");\n" +
3081 " }\n" +
3082 " }\n" +
3083 "}\n" +
3084 "\n" +
3085 "class A implements AutoCloseable {\n" +
3086 " public A () throws Exception {\n" +
3087 " System.out.println(\"A::A\");\n" +
3088 " }\n" +
3089 " public void close() throws Exception {\n" +
3090 " System.out.println(\"A::~A\");\n" +
3091 " try (B b = new B()) {\n" +
3092 " System.out.println(\"A::~A::Try\");\n" +
3093 " throw new Exception(\"A::~A\");\n" +
3094 " } catch (Exception e) {\n" +
3095 " System.out.println(e);\n" +
3096 " Throwable suppressed [] = e.getSuppressed();\n" +
3097 " for (int i = 0; i < suppressed.length; ++i) {\n" +
3098 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
3099 " }\n" +
3100 " throw e;\n" +
3101 " } \n" +
3102 " }\n" +
3103 "}\n" +
3104 "\n" +
3105 "class B implements AutoCloseable {\n" +
3106 " public B () throws Exception {\n" +
3107 " System.out.println(\"B::B\");\n" +
3108 " }\n" +
3109 " public void close() throws Exception {\n" +
3110 " System.out.println(\"B::~B\");\n" +
3111 " try (C c = new C()) {\n" +
3112 " System.out.println(\"B::~B::Try\");\n" +
3113 " throw new Exception (\"B::~B\");\n" +
3114 " } catch (Exception e) {\n" +
3115 " System.out.println(e);\n" +
3116 " Throwable suppressed [] = e.getSuppressed();\n" +
3117 " for (int i = 0; i < suppressed.length; ++i) {\n" +
3118 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
3119 " }\n" +
3120 " throw e;\n" +
3121 " } \n" +
3122 " }\n" +
3123 "}\n" +
3124 "class C implements AutoCloseable {\n" +
3125 " public C () throws Exception {\n" +
3126 " System.out.println(\"C::C\");\n" +
3127 " }\n" +
3128 " public void close() throws Exception {\n" +
3129 " System.out.println(\"C::~C\");\n" +
3130 " throw new Exception (\"C::~C\");\n" +
3131 " } \n" +
3132 "}\n"
3133 },
3134 "Main\n" +
3135 "A::A\n" +
3136 "X::Try\n" +
3137 "A::~A\n" +
3138 "B::B\n" +
3139 "A::~A::Try\n" +
3140 "B::~B\n" +
3141 "C::C\n" +
3142 "B::~B::Try\n" +
3143 "C::~C\n" +
3144 "java.lang.Exception: B::~B\n" +
3145 "Suppressed: java.lang.Exception: C::~C\n" +
3146 "java.lang.Exception: A::~A\n" +
3147 "Suppressed: java.lang.Exception: B::~B\n" +
3148 "java.lang.Exception: X::Main\n" +
3149 "Suppressed: java.lang.Exception: A::~A\n" +
3150 "All done");
3151 }
3152 //ensure that it doesn't completely fail when using TWR and 1.5 mode
test049()3153 public void test049() {
3154 Runner runner = new Runner();
3155 runner.customOptions = getCompilerOptions();
3156 runner.customOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
3157 runner.customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
3158 runner.customOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
3159 runner.testFiles =
3160 new String[] {
3161 "X.java",
3162 "import java.io.File;\n" +
3163 "import java.io.FileReader;\n" +
3164 "import java.io.IOException;\n" +
3165 "public class X {\n" +
3166 " void foo() {\n" +
3167 " File file = new File(\"somefile\");\n" +
3168 " try(FileReader fileReader = new FileReader(file);) {\n" +
3169 " char[] in = new char[50];\n" +
3170 " fileReader.read(in);\n" +
3171 " } catch (IOException e) {\n" +
3172 " System.out.println(\"Got IO exception\");\n" +
3173 " } finally{\n" +
3174 " }\n" +
3175 " }\n" +
3176 " public static void main(String[] args) {\n" +
3177 " new X().foo();\n" +
3178 " }\n" +
3179 "}\n"
3180 };
3181 runner.expectedCompilerLog =
3182 "----------\n" +
3183 "1. ERROR in X.java (at line 7)\n" +
3184 " try(FileReader fileReader = new FileReader(file);) {\n" +
3185 " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
3186 "Resource specification not allowed here for source level below 1.7\n" +
3187 "----------\n";
3188 runner.javacTestOptions = JavacTestOptions.forRelease("5");
3189 runner.runNegativeTest();
3190 }
test050()3191 public void test050() {
3192 this.runConformTest(
3193 new String[] {
3194 "X.java",
3195 "public class X {\n" +
3196 " public static void main(String [] args) {\n" +
3197 " System.out.println(\"Main\");\n" +
3198 " try (E e = E.CONST) {\n" +
3199 " System.out.println(\"Outer try\");\n" +
3200 " } catch (Exception e) {\n" +
3201 " System.out.println(e);\n" +
3202 " Throwable suppressed [] = e.getSuppressed();\n" +
3203 " for (int i = 0; i < suppressed.length; ++i) {\n" +
3204 " System.out.println(\"Suppressed: \" + suppressed[i]);\n" +
3205 " }\n" +
3206 " } finally {\n" +
3207 " System.out.println(\"All done\");\n" +
3208 " }\n" +
3209 " }\n" +
3210 "}",
3211 "E.java",
3212 "public enum E implements AutoCloseable {\n" +
3213 " CONST;\n" +
3214 " private E () {\n" +
3215 " System.out.println(\"E::E\");\n" +
3216 " }\n" +
3217 " public void close() throws Exception {\n" +
3218 " System.out.println(\"E::~E\");\n" +
3219 " throw new Exception (\"E::~E\");\n" +
3220 " }\n" +
3221 "}"
3222 },
3223 "Main\n" +
3224 "E::E\n" +
3225 "Outer try\n" +
3226 "E::~E\n" +
3227 "java.lang.Exception: E::~E\n" +
3228 "All done");
3229 }
test051()3230 public void test051() {
3231 this.runConformTest(
3232 new String[] {
3233 "X.java",
3234 "public class X {\n" +
3235 " public static void main(String[] args) throws Throwable {\n" +
3236 " try (Test t = new Test()) {\n" +
3237 " for (int i = 0; i < 10; i++) {\n" +
3238 " }\n" +
3239 "\n" +
3240 "\n" +
3241 " } \n" +
3242 "\n" +
3243 " catch (Exception e) {\n" +
3244 " StackTraceElement t = e.getStackTrace()[1];\n" +
3245 " String file = t.getFileName();\n" +
3246 " int line = t.getLineNumber();\n" +
3247 " System.out.println(\"File = \" + file + \" \" + \"line = \" + line);\n" +
3248 " }\n" +
3249 " }\n" +
3250 "}\n" +
3251 "class Test implements AutoCloseable {\n" +
3252 " public void close() throws Exception {\n" +
3253 " throw new Exception();\n" +
3254 " }\n" +
3255 "}\n"
3256 },
3257 "File = X.java line = 8");
3258 }
3259 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348406
test052()3260 public void test052() {
3261 Map options = getCompilerOptions();
3262 options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
3263 options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
3264 options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
3265 this.runNegativeTest(
3266 new String[] {
3267 "X.java",
3268 "public class X {\n" +
3269 " public static void main(String[] args) throws Throwable {\n" +
3270 " try (Test t = new Test()) {\n" +
3271 " } \n" +
3272 " }\n" +
3273 "}\n" +
3274 "class Test {\n" +
3275 " public void close() throws Exception {\n" +
3276 " throw new Exception();\n" +
3277 " }\n" +
3278 "}\n"
3279 },
3280 "----------\n" +
3281 "1. ERROR in X.java (at line 3)\n" +
3282 " try (Test t = new Test()) {\n" +
3283 " ^^^^^^^^^^^^^^^^^^^\n" +
3284 "Resource specification not allowed here for source level below 1.7\n" +
3285 "----------\n",
3286 null,
3287 true,
3288 options);
3289 }
3290 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348705
3291 // Unhandled exception due to autoclose should be reported separately
test053()3292 public void test053() {
3293 this.runNegativeTest(
3294 new String[] {
3295 "X.java",
3296 "public class X {\n" +
3297 " public void method1(){\n" +
3298 " try (Y y = new Y()) { \n" +
3299 " y.close();\n" +
3300 " System.out.println();\n" +
3301 " } catch (RuntimeException e) {\n" +
3302 " }\n" +
3303 " }\n" +
3304 "}\n" +
3305 "class Y implements Managed {\n" +
3306 " public Y() throws CloneNotSupportedException {}\n" +
3307 " public void close () throws ClassNotFoundException, java.io.IOException {\n" +
3308 " }\n" +
3309 "}\n" +
3310 "interface Managed extends AutoCloseable {}\n",
3311 },
3312 "----------\n" +
3313 "1. ERROR in X.java (at line 3)\n" +
3314 " try (Y y = new Y()) { \n" +
3315 " ^\n" +
3316 "Unhandled exception type ClassNotFoundException thrown by automatic close() invocation on y\n" +
3317 "----------\n" +
3318 "2. ERROR in X.java (at line 3)\n" +
3319 " try (Y y = new Y()) { \n" +
3320 " ^\n" +
3321 "Unhandled exception type IOException thrown by automatic close() invocation on y\n" +
3322 "----------\n" +
3323 "3. ERROR in X.java (at line 3)\n" +
3324 " try (Y y = new Y()) { \n" +
3325 " ^^^^^^^\n" +
3326 "Unhandled exception type CloneNotSupportedException\n" +
3327 "----------\n" +
3328 "4. ERROR in X.java (at line 4)\n" +
3329 " y.close();\n" +
3330 " ^^^^^^^^^\n" +
3331 "Unhandled exception type ClassNotFoundException\n" +
3332 "----------\n" +
3333 "5. ERROR in X.java (at line 4)\n" +
3334 " y.close();\n" +
3335 " ^^^^^^^^^\n" +
3336 "Unhandled exception type IOException\n" +
3337 "----------\n");
3338 }
3339 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=348705
3340 // Variant of the above, witness for https://bugs.eclipse.org/358827#c6
test053a()3341 public void test053a() {
3342 this.runNegativeTest(
3343 new String[] {
3344 "X.java",
3345 "public class X {\n" +
3346 " public void method1(){\n" +
3347 " try (Y y = new Y()) { \n" +
3348 " y.close();\n" +
3349 " System.out.println();\n" +
3350 " } catch (RuntimeException e) {\n" +
3351 " } finally {\n" +
3352 " System.out.println();\n" +
3353 " }\n" +
3354 " }\n" +
3355 "}\n" +
3356 "class Y implements Managed {\n" +
3357 " public Y() throws CloneNotSupportedException {}\n" +
3358 " public void close () throws ClassNotFoundException, java.io.IOException {\n" +
3359 " }\n" +
3360 "}\n" +
3361 "interface Managed extends AutoCloseable {}\n",
3362 },
3363 "----------\n" +
3364 "1. ERROR in X.java (at line 3)\n" +
3365 " try (Y y = new Y()) { \n" +
3366 " ^\n" +
3367 "Unhandled exception type ClassNotFoundException thrown by automatic close() invocation on y\n" +
3368 "----------\n" +
3369 "2. ERROR in X.java (at line 3)\n" +
3370 " try (Y y = new Y()) { \n" +
3371 " ^\n" +
3372 "Unhandled exception type IOException thrown by automatic close() invocation on y\n" +
3373 "----------\n" +
3374 "3. ERROR in X.java (at line 3)\n" +
3375 " try (Y y = new Y()) { \n" +
3376 " ^^^^^^^\n" +
3377 "Unhandled exception type CloneNotSupportedException\n" +
3378 "----------\n" +
3379 "4. ERROR in X.java (at line 4)\n" +
3380 " y.close();\n" +
3381 " ^^^^^^^^^\n" +
3382 "Unhandled exception type ClassNotFoundException\n" +
3383 "----------\n" +
3384 "5. ERROR in X.java (at line 4)\n" +
3385 " y.close();\n" +
3386 " ^^^^^^^^^\n" +
3387 "Unhandled exception type IOException\n" +
3388 "----------\n");
3389 }
3390 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=349862 (NPE when union type is used in the resource section.)
test054()3391 public void test054() {
3392 this.runNegativeTest(
3393 new String[] {
3394 "X.java",
3395 "public class X {\n" +
3396 " void foo() {\n" +
3397 " try (Object | Integer res = null) {\n" +
3398 " } catch (Exception e) {\n" +
3399 " }\n" +
3400 " }\n" +
3401 "}\n",
3402 },
3403 "----------\n" +
3404 "1. ERROR in X.java (at line 3)\n" +
3405 " try (Object | Integer res = null) {\n" +
3406 " ^\n" +
3407 "Syntax error on token \"|\", . expected\n" +
3408 "----------\n");
3409 }
3410 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=349862 (NPE when union type is used in the resource section.)
test054a()3411 public void test054a() {
3412 this.runNegativeTest(
3413 new String[] {
3414 "X.java",
3415 "public class X {\n" +
3416 " void foo() {\n" +
3417 " try (Object.Integer res = null) {\n" +
3418 " } catch (Exception e) {\n" +
3419 " }\n" +
3420 " }\n" +
3421 "}\n",
3422 },
3423 "----------\n" +
3424 "1. ERROR in X.java (at line 3)\n" +
3425 " try (Object.Integer res = null) {\n" +
3426 " ^^^^^^^^^^^^^^\n" +
3427 "Object.Integer cannot be resolved to a type\n" +
3428 "----------\n");
3429 }
3430 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=353535 (verify error with try with resources)
test055()3431 public void test055() {
3432 this.runConformTest(
3433 new String[] {
3434 "X.java",
3435 "import java.io.ByteArrayInputStream;\n" +
3436 "import java.io.InputStream;\n" +
3437 "public class X {\n" +
3438 "public static void main(String[] args) throws Exception {\n" +
3439 " int b;\n" +
3440 " try (final InputStream in = new ByteArrayInputStream(new byte[] { 42 })) {\n" +
3441 " b = in.read();\n" +
3442 " }\n" +
3443 " System.out.println(\"Done\");\n" +
3444 "}\n" +
3445 "}\n",
3446 },
3447 "Done");
3448 }
3449 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=353535 (verify error with try with resources)
test055a()3450 public void test055a() {
3451 this.runConformTest(
3452 new String[] {
3453 "X.java",
3454 "public class X {\n" +
3455 " public static void main(String[] args) throws Throwable {\n" +
3456 " int tmp;\n" +
3457 " try (A a = null) {\n" +
3458 " try (A b = null) {\n" +
3459 " tmp = 0;\n" +
3460 " }\n" +
3461 " }\n" +
3462 " System.out.println(\"Done\");\n" +
3463 " }\n" +
3464 "}\n" +
3465 "class A implements AutoCloseable {\n" +
3466 " @Override\n" +
3467 " public void close() {\n" +
3468 " }\n" +
3469 "}\n",
3470 },
3471 "Done");
3472 }
3473
3474 // Note: test056* have been moved to ResourceLeakTests.java
3475
3476 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=361053
test057()3477 public void test057() {
3478 this.runConformTest(
3479 new String[] {
3480 "X.java",
3481 "public class X implements AutoCloseable {\n" +
3482 " @Override\n" +
3483 " public void close() throws Exception {\n" +
3484 " throw new Exception();\n" +
3485 " }\n" +
3486 " public static void main(String[] args) {\n" +
3487 " final boolean foo;\n" +
3488 " try (X a = new X(); X b = new X()) {\n" +
3489 " foo = true;\n" +
3490 " } catch (final Exception exception) {\n" +
3491 " return;\n" +
3492 " }\n" +
3493 " }\n" +
3494 "}\n"
3495 }, "");
3496 }
3497 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364008
test058()3498 public void test058() {
3499 this.runConformTest(
3500 new String[] {
3501 "X.java",
3502 "import java.io.ByteArrayOutputStream;\n" +
3503 "import java.io.FileOutputStream;\n" +
3504 "import java.io.IOException;\n" +
3505 "\n" +
3506 "public class X {\n" +
3507 "\n" +
3508 " public static void main(final String[] args) throws IOException {\n" +
3509 " byte[] data;\n" +
3510 " try (final ByteArrayOutputStream os = new ByteArrayOutputStream();\n" +
3511 " final FileOutputStream out = new FileOutputStream(\"test.dat\")) {\n" +
3512 " data = os.toByteArray();\n" +
3513 " }\n" +
3514 " }\n" +
3515 "}\n"
3516 }, "");
3517 }
3518 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367566 - In try-with-resources statement close() method of resource is not called
test059()3519 public void test059() {
3520 this.runConformTest(
3521 new String[] {
3522 "X.java",
3523 "import java.io.IOException;\n" +
3524 "\n" +
3525 "public class X implements java.lang.AutoCloseable {\n" +
3526 " static boolean isOpen = true;\n" +
3527 " public static void main(final String[] args) throws IOException {\n" +
3528 " foo();\n" +
3529 " System.out.println(isOpen);\n" +
3530 " }\n" +
3531 " static boolean foo() {\n" +
3532 " try (final X x = new X()) {\n" +
3533 " return x.num() >= 1;\n" +
3534 " }\n" +
3535 " }\n" +
3536 " int num() { return 2; }\n" +
3537 " public void close() {\n" +
3538 " isOpen = false;\n" +
3539 " }\n" +
3540 "}\n"
3541 },
3542 "false");
3543 }
3544
3545 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=367566 - In try-with-resources statement close() method of resource is not called
test060()3546 public void test060() {
3547 this.runConformTest(
3548 new String[] {
3549 "X.java",
3550 "public class X implements AutoCloseable {\n" +
3551 " static int num = 10 ;\n" +
3552 " public static void main(String [] args) throws Exception { \n" +
3553 " System.out.println(foo(1));\n" +
3554 " System.out.println(foo(2));\n" +
3555 " System.out.println(foo(3));\n" +
3556 " }\n" +
3557 " private static boolean foo(int where) throws Exception {\n" +
3558 " final boolean getOut = true;\n" +
3559 " System.out.println(\"Main\");\n" +
3560 " try (X x1 = new X(); X x2 = new X()) {\n" +
3561 " if (where == 1) {\n" +
3562 " return where == 1;\n" +
3563 " }\n" +
3564 " System.out.println(\"Outer Try\");\n" +
3565 " while (true) {\n" +
3566 " try (Y y1 = new Y(); Y y2 = new Y()) { \n" +
3567 " if (where == 2) {\n" +
3568 " return where == 2;\n" +
3569 " } \n" +
3570 " System.out.println(\"Middle Try\");\n" +
3571 " try (Z z1 = new Z(); Z z2 = new Z()) {\n" +
3572 " System.out.println(\"Inner Try\");\n" +
3573 " if (getOut) \n" +
3574 " return num >= 10;\n" +
3575 " else\n" +
3576 " break; \n" +
3577 " }\n" +
3578 " }\n" +
3579 " }\n" +
3580 " System.out.println(\"Out of while\");\n" +
3581 " }\n" +
3582 " return false;\n" +
3583 " }\n" +
3584 " public X() {\n" +
3585 " System.out.println(\"X::X\");\n" +
3586 " }\n" +
3587 " @Override\n" +
3588 " public void close() throws Exception {\n" +
3589 " System.out.println(\"X::~X\");\n" +
3590 " }\n" +
3591 "}\n" +
3592 "class Y implements AutoCloseable {\n" +
3593 " public Y() {\n" +
3594 " System.out.println(\"Y::Y\");\n" +
3595 " }\n" +
3596 " @Override\n" +
3597 " public void close() throws Exception {\n" +
3598 " System.out.println(\"Y::~Y\");\n" +
3599 " }\n" +
3600 "}\n" +
3601 "class Z implements AutoCloseable {\n" +
3602 " public Z() {\n" +
3603 " System.out.println(\"Z::Z\");\n" +
3604 " }\n" +
3605 " @Override\n" +
3606 " public void close() throws Exception {\n" +
3607 " System.out.println(\"Z::~Z\");\n" +
3608 " }\n" +
3609 "}\n"
3610 },
3611 "Main\n" +
3612 "X::X\n" +
3613 "X::X\n" +
3614 "X::~X\n" +
3615 "X::~X\n" +
3616 "true\n" +
3617 "Main\n" +
3618 "X::X\n" +
3619 "X::X\n" +
3620 "Outer Try\n" +
3621 "Y::Y\n" +
3622 "Y::Y\n" +
3623 "Y::~Y\n" +
3624 "Y::~Y\n" +
3625 "X::~X\n" +
3626 "X::~X\n" +
3627 "true\n" +
3628 "Main\n" +
3629 "X::X\n" +
3630 "X::X\n" +
3631 "Outer Try\n" +
3632 "Y::Y\n" +
3633 "Y::Y\n" +
3634 "Middle Try\n" +
3635 "Z::Z\n" +
3636 "Z::Z\n" +
3637 "Inner Try\n" +
3638 "Z::~Z\n" +
3639 "Z::~Z\n" +
3640 "Y::~Y\n" +
3641 "Y::~Y\n" +
3642 "X::~X\n" +
3643 "X::~X\n" +
3644 "true");
3645 }
3646 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
test375248()3647 public void test375248() {
3648 this.runConformTest(
3649 new String[] {
3650 "X.java",
3651 "import java.io.IOException;\n" +
3652 "import java.io.InputStream;\n" +
3653 "import java.net.MalformedURLException;\n" +
3654 "import java.net.URL;\n" +
3655 "\n" +
3656 "public class X {\n" +
3657 " public static void main(String[] args) throws Exception {\n" +
3658 " System.out.println(\"Done\");\n" +
3659 " }\n" +
3660 " public void foo() throws MalformedURLException {\n" +
3661 " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" +
3662 " try (InputStream is = url.openStream()) {\n" +
3663 " } catch (IOException e) {\n" +
3664 " return;\n" +
3665 " } finally {\n" +
3666 " try {\n" +
3667 " java.nio.file.Files.delete(null);\n" +
3668 " } catch (IOException e1) {\n" +
3669 " }\n" +
3670 " }\n" +
3671 " }\n" +
3672 "}\n",
3673 },
3674 "Done");
3675 }
3676 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
test375248a()3677 public void test375248a() {
3678 this.runConformTest(
3679 new String[] {
3680 "X.java",
3681 "import java.io.File;\n" +
3682 "import java.io.IOException;\n" +
3683 "import java.io.InputStream;\n" +
3684 "import java.net.MalformedURLException;\n" +
3685 "import java.net.URL;\n" +
3686 "import java.nio.file.Path;\n" +
3687 "import java.nio.file.StandardCopyOption;\n" +
3688 "\n" +
3689 "public class X {\n" +
3690 " public static void main(String[] args) throws Exception {\n" +
3691 " System.out.println(\"Done\");\n" +
3692 " }\n" +
3693 " public void executeImports() throws MalformedURLException {\n" +
3694 " for (int i = 0; i < 3; i++) {\n" +
3695 " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" +
3696 " if (url != null) {\n" +
3697 " Path target = new File(\"dummy\").toPath();\n" +
3698 " try (InputStream is = url.openStream()) {\n" +
3699 " java.nio.file.Files.copy(is, target,\n" +
3700 " StandardCopyOption.REPLACE_EXISTING);\n" +
3701 " } catch (IOException e) {\n" +
3702 " break;\n" +
3703 " } finally {\n" +
3704 " try {\n" +
3705 " java.nio.file.Files.delete(target);\n" +
3706 " } catch (IOException e1) {\n" +
3707 "\n" +
3708 " }\n" +
3709 " }\n" +
3710 " }\n" +
3711 " }\n" +
3712 " }\n" +
3713 "}\n",
3714 },
3715 "Done");
3716 }
3717 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
test375248b()3718 public void test375248b() {
3719 this.runConformTest(
3720 new String[] {
3721 "X.java",
3722 "import java.io.File;\n" +
3723 "import java.io.IOException;\n" +
3724 "import java.io.InputStream;\n" +
3725 "import java.net.MalformedURLException;\n" +
3726 "import java.net.URL;\n" +
3727 "import java.nio.file.Path;\n" +
3728 "import java.nio.file.StandardCopyOption;\n" +
3729 "\n" +
3730 "public class X {\n" +
3731 " public static void main(String[] args) throws Exception {\n" +
3732 " System.out.println(\"Done\");\n" +
3733 " }\n" +
3734 " public void executeImports() throws MalformedURLException {\n" +
3735 " for (int i = 0; i < 3; i++) {\n" +
3736 " URL url = new URL(\"dummy\"); //$NON-NLS-1$\n" +
3737 " if (url != null) {\n" +
3738 " Path target = new File(\"dummy\").toPath();\n" +
3739 " try (InputStream is = url.openStream()) {\n" +
3740 " java.nio.file.Files.copy(is, target,\n" +
3741 " StandardCopyOption.REPLACE_EXISTING);\n" +
3742 " } catch (IOException e) {\n" +
3743 " continue;\n" +
3744 " } finally {\n" +
3745 " try {\n" +
3746 " java.nio.file.Files.delete(target);\n" +
3747 " } catch (IOException e1) {\n" +
3748 "\n" +
3749 " }\n" +
3750 " }\n" +
3751 " }\n" +
3752 " }\n" +
3753 " }\n" +
3754 "}\n",
3755 },
3756 "Done");
3757 }
3758 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
test375248c()3759 public void test375248c() {
3760 this.runConformTest(
3761 new String[] {
3762 "X.java",
3763 "import java.io.File;\n" +
3764 "import java.io.IOException;\n" +
3765 "import java.io.InputStream;\n" +
3766 "import java.net.MalformedURLException;\n" +
3767 "import java.net.URL;\n" +
3768 "import java.nio.file.Path;\n" +
3769 "import java.nio.file.StandardCopyOption;\n" +
3770 "\n" +
3771 "public class X implements AutoCloseable {\n" +
3772 " public void foo() {\n" +
3773 " try (X x = new X()) {\n" +
3774 " System.out.println(\"Try\");\n" +
3775 " throw new Exception();\n" +
3776 " } catch (Exception e) {\n" +
3777 " System.out.println(\"Catch\");\n"+
3778 " return;\n" +
3779 " } finally {\n" +
3780 " System.out.println(\"Finally\");\n" +
3781 " }\n" +
3782 " }\n" +
3783 " public void close() {\n" +
3784 " System.out.println(\"Close\");\n" +
3785 " }\n" +
3786 " public static void main(String[] args) {\n" +
3787 " new X().foo();\n" +
3788 " }\n" +
3789 "}\n"
3790 },
3791 "Try\n" +
3792 "Close\n" +
3793 "Catch\n" +
3794 "Finally");
3795 }
3796 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375248 (AIOOB with try with resources)
test375248d()3797 public void test375248d() {
3798 this.runConformTest(
3799 new String[] {
3800 "X.java",
3801 "import java.io.File;\n" +
3802 "import java.io.IOException;\n" +
3803 "import java.io.InputStream;\n" +
3804 "import java.net.MalformedURLException;\n" +
3805 "import java.net.URL;\n" +
3806 "import java.nio.file.Path;\n" +
3807 "import java.nio.file.StandardCopyOption;\n" +
3808 "\n" +
3809 "public class X implements AutoCloseable {\n" +
3810 " public void foo() {\n" +
3811 " try (X x = new X()) {\n" +
3812 " System.out.println(\"Try\");\n" +
3813 " } catch (Exception e) {\n" +
3814 " System.out.println(\"Catch\");\n"+
3815 " return;\n" +
3816 " } finally {\n" +
3817 " System.out.println(\"Finally\");\n" +
3818 " return;\n" +
3819 " }\n" +
3820 " }\n" +
3821 " public void close() {\n" +
3822 " System.out.println(\"Close\");\n" +
3823 " }\n" +
3824 " public static void main(String[] args) {\n" +
3825 " new X().foo();\n" +
3826 " }\n" +
3827 "}\n"
3828 },
3829 "Try\n" +
3830 "Close\n" +
3831 "Finally");
3832 }
3833 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326()3834 public void test375326() {
3835 this.runConformTest(
3836 new String[] {
3837 "X.java",
3838 "public class X {\n" +
3839 " public static void main(String[] args) throws Exception {\n" +
3840 " HasAutoCloseable a;\n" +
3841 " try(AutoCloseable b=(a=new HasAutoCloseable()).a) {\n" +
3842 " }\n" +
3843 " System.out.println(a);\n" +
3844 " }\n" +
3845 " public static class AutoCloseableA implements AutoCloseable {\n" +
3846 " @Override\n" +
3847 " public void close() {\n" +
3848 " // TODO Auto-generated method stub\n" +
3849 " }\n" +
3850 " }\n" +
3851 " public static class HasAutoCloseable {\n" +
3852 " AutoCloseable a = new AutoCloseableA();\n" +
3853 " public String toString() {\n" +
3854 " return \"SUCCESS\";\n" +
3855 " }\n" +
3856 " }\n" +
3857 "}"
3858 },
3859 "SUCCESS");
3860 }
3861 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326a()3862 public void test375326a() {
3863 this.runNegativeTest(
3864 new String[] {
3865 "X.java",
3866 "public class X {\n" +
3867 " public static void main(String [] args) throws Exception {\n" +
3868 " HasAutoCloseable aLocal;\n" +
3869 " try(AutoCloseable b=(new HasAutoCloseable()).a){\n" +
3870 " aLocal = new HasAutoCloseable();\n" +
3871 " }\n" +
3872 " catch (Throwable e) {\n" +
3873 " }\n" +
3874 " System.out.println(aLocal.toString()); \n" +
3875 " } \n" +
3876 " public static class AutoCloseableA implements AutoCloseable{\n" +
3877 " @Override\n" +
3878 " public void close() {\n" +
3879 " }\n" +
3880 " }\n" +
3881 " public static class HasAutoCloseable{\n" +
3882 " AutoCloseable a=new AutoCloseableA(); \n" +
3883 " }\n" +
3884 "}\n"
3885 },
3886 "----------\n" +
3887 "1. ERROR in X.java (at line 9)\n" +
3888 " System.out.println(aLocal.toString()); \n" +
3889 " ^^^^^^\n" +
3890 "The local variable aLocal may not have been initialized\n" +
3891 "----------\n");
3892 }
3893 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326b()3894 public void test375326b() {
3895 this.runNegativeTest(
3896 new String[] {
3897 "X.java",
3898 "public class X {\n" +
3899 " public static void main(String [] args) throws Exception {\n" +
3900 " HasAutoCloseable aLocal;\n" +
3901 " try(AutoCloseable b=(aLocal = new HasAutoCloseable()).a){\n" +
3902 " \n" +
3903 " }\n" +
3904 " catch (Throwable e) {\n" +
3905 " }\n" +
3906 " System.out.println(aLocal.toString()); \n" +
3907 " } \n" +
3908 " public static class AutoCloseableA implements AutoCloseable{\n" +
3909 " @Override\n" +
3910 " public void close() {\n" +
3911 " }\n" +
3912 " }\n" +
3913 " public static class HasAutoCloseable{\n" +
3914 " AutoCloseable a=new AutoCloseableA(); \n" +
3915 " }\n" +
3916 "}\n"
3917 },
3918 "----------\n" +
3919 "1. ERROR in X.java (at line 9)\n" +
3920 " System.out.println(aLocal.toString()); \n" +
3921 " ^^^^^^\n" +
3922 "The local variable aLocal may not have been initialized\n" +
3923 "----------\n");
3924 }
3925 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326c()3926 public void test375326c() {
3927 this.runConformTest(
3928 new String[] {
3929 "X.java",
3930 "public class X {\n" +
3931 " public static void main(String[] args) throws Exception {\n" +
3932 " HasAutoCloseable a;\n" +
3933 " try(AutoCloseable b=(a=new HasAutoCloseable()).a) {\n" +
3934 " } finally {\n" +
3935 " System.out.println(\"Finally\");\n" +
3936 " }\n" +
3937 " System.out.println(a);\n" +
3938 " }\n" +
3939 " public static class AutoCloseableA implements AutoCloseable {\n" +
3940 " @Override\n" +
3941 " public void close() {\n" +
3942 " // TODO Auto-generated method stub\n" +
3943 " }\n" +
3944 " }\n" +
3945 " public static class HasAutoCloseable {\n" +
3946 " AutoCloseable a = new AutoCloseableA();\n" +
3947 " public String toString() {\n" +
3948 " return \"SUCCESS\";\n" +
3949 " }\n" +
3950 " }\n" +
3951 "}"
3952 },
3953 "Finally\n" +
3954 "SUCCESS");
3955 }
3956 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326d()3957 public void test375326d() {
3958 this.runNegativeTest(
3959 new String[] {
3960 "X.java",
3961 "public class X {\n" +
3962 " public static void main(String [] args) throws Exception {\n" +
3963 " HasAutoCloseable aLocal;\n" +
3964 " try(AutoCloseable b=(new HasAutoCloseable()).a){\n" +
3965 " aLocal = new HasAutoCloseable();\n" +
3966 " }\n" +
3967 " catch (Throwable e) {\n" +
3968 " } finally {\n" +
3969 " System.out.println(\"Finally\");\n" +
3970 " }\n" +
3971 " System.out.println(aLocal.toString()); \n" +
3972 " } \n" +
3973 " public static class AutoCloseableA implements AutoCloseable{\n" +
3974 " @Override\n" +
3975 " public void close() {\n" +
3976 " }\n" +
3977 " }\n" +
3978 " public static class HasAutoCloseable{\n" +
3979 " AutoCloseable a=new AutoCloseableA(); \n" +
3980 " }\n" +
3981 "}\n"
3982 },
3983 "----------\n" +
3984 "1. ERROR in X.java (at line 11)\n" +
3985 " System.out.println(aLocal.toString()); \n" +
3986 " ^^^^^^\n" +
3987 "The local variable aLocal may not have been initialized\n" +
3988 "----------\n");
3989 }
3990 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326e()3991 public void test375326e() {
3992 this.runNegativeTest(
3993 new String[] {
3994 "X.java",
3995 "public class X {\n" +
3996 " public static void main(String [] args) throws Exception {\n" +
3997 " HasAutoCloseable aLocal;\n" +
3998 " try(AutoCloseable b=(aLocal = new HasAutoCloseable()).a){\n" +
3999 " \n" +
4000 " }\n" +
4001 " catch (Throwable e) {\n" +
4002 " } finally {\n" +
4003 " System.out.println(\"Finally\");\n" +
4004 " }\n" +
4005 " System.out.println(aLocal.toString()); \n" +
4006 " } \n" +
4007 " public static class AutoCloseableA implements AutoCloseable{\n" +
4008 " @Override\n" +
4009 " public void close() {\n" +
4010 " }\n" +
4011 " }\n" +
4012 " public static class HasAutoCloseable{\n" +
4013 " AutoCloseable a=new AutoCloseableA(); \n" +
4014 " }\n" +
4015 "}\n"
4016 },
4017 "----------\n" +
4018 "1. ERROR in X.java (at line 11)\n" +
4019 " System.out.println(aLocal.toString()); \n" +
4020 " ^^^^^^\n" +
4021 "The local variable aLocal may not have been initialized\n" +
4022 "----------\n");
4023 }
4024 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326f()4025 public void test375326f() {
4026 this.runNegativeTest(
4027 new String[] {
4028 "X.java",
4029 "public class X {\n" +
4030 " public void testWithResourcesAssignment() throws Exception{\n" +
4031 " HasAutoCloseable a;\n" +
4032 " try(AutoCloseable b=(a=new HasAutoCloseable()).a){\n" +
4033 " } finally {\n" +
4034 " System.out.println(a);\n" +
4035 " }\n" +
4036 " }\n" +
4037 " public class AutoCloseableA implements AutoCloseable{\n" +
4038 " @Override\n" +
4039 " public void close() {\n" +
4040 " }\n" +
4041 " }\n" +
4042 " public class HasAutoCloseable{\n" +
4043 " AutoCloseable a=new AutoCloseableA();\n" +
4044 " }\n" +
4045 "}\n"
4046 },
4047 "----------\n" +
4048 "1. ERROR in X.java (at line 6)\n" +
4049 " System.out.println(a);\n" +
4050 " ^\n" +
4051 "The local variable a may not have been initialized\n" +
4052 "----------\n");
4053 }
4054 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=375326
test375326g()4055 public void test375326g() {
4056 this.runNegativeTest(
4057 new String[] {
4058 "X.java",
4059 "class CheckedException extends Throwable {}\n" +
4060 "public class X {\n" +
4061 " public void testWithResourcesAssignment() throws Exception{\n" +
4062 " HasAutoCloseable a;\n" +
4063 " try(AutoCloseable b=(a=new HasAutoCloseable()).a){\n" +
4064 " throw new CheckedException();\n" +
4065 " } catch (CheckedException e) {\n" +
4066 " System.out.println(a);\n" +
4067 " } finally {\n" +
4068 " System.out.println(a);\n" +
4069 " }\n" +
4070 " }\n" +
4071 " public class AutoCloseableA implements AutoCloseable{\n" +
4072 " @Override\n" +
4073 " public void close() {\n" +
4074 " }\n" +
4075 " }\n" +
4076 " public class HasAutoCloseable{\n" +
4077 " AutoCloseable a=new AutoCloseableA();\n" +
4078 " }\n" +
4079 "}\n"
4080 },
4081 "----------\n" +
4082 "1. WARNING in X.java (at line 1)\n" +
4083 " class CheckedException extends Throwable {}\n" +
4084 " ^^^^^^^^^^^^^^^^\n" +
4085 "The serializable class CheckedException does not declare a static final serialVersionUID field of type long\n" +
4086 "----------\n" +
4087 "2. ERROR in X.java (at line 8)\n" +
4088 " System.out.println(a);\n" +
4089 " ^\n" +
4090 "The local variable a may not have been initialized\n" +
4091 "----------\n" +
4092 "3. ERROR in X.java (at line 10)\n" +
4093 " System.out.println(a);\n" +
4094 " ^\n" +
4095 "The local variable a may not have been initialized\n" +
4096 "----------\n");
4097 }
4098 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112
test380112a()4099 public void test380112a() {
4100 this.runConformTest(
4101 new String[] {
4102 "X.java",
4103 "import java.io.*;\n" +
4104 "interface I extends Closeable, Serializable {}\n" +
4105 "public class X {\n"+
4106 " public static void main(String [] args) {\n" +
4107 " try (I i = getX()) {\n" +
4108 " } catch (IOException x) {\n" +
4109 " }\n"+
4110 " System.out.println(\"Done\");\n" +
4111 " }\n" +
4112 " public static I getX() { return null;}\n"+
4113 " public X(){}\n" +
4114 "}\n"
4115 },
4116 "Done");
4117 }
4118 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112
4119 //variant with finally
test380112b()4120 public void test380112b() {
4121 this.runConformTest(
4122 new String[] {
4123 "X.java",
4124 "import java.io.*;\n" +
4125 "interface I extends Closeable, Serializable {}\n" +
4126 "public class X {\n"+
4127 " public static void main(String [] args) {\n" +
4128 " try (I i = getX()) {\n" +
4129 " } catch (IOException x) {\n" +
4130 " } finally {\n"+
4131 " System.out.println(\"Done\");\n" +
4132 " }\n" +
4133 " }\n" +
4134 " public static I getX() { return null;}\n"+
4135 " public X(){}\n" +
4136 "}\n"
4137 },
4138 "Done");
4139 }
4140 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112
4141 //variant with two methods throwing different Exceptions (one subtype of other)
4142 //subtype should be the one to be caught
test380112c()4143 public void test380112c() {
4144 this.runConformTest(
4145 new String[] {
4146 "X.java",
4147 "import java.io.*;\n" +
4148 "interface I2 { public void close() throws FileNotFoundException; }\n"+
4149 "interface I extends Closeable, I2 {}\n" +
4150 "public class X {\n"+
4151 " public static void main(String [] args) {\n" +
4152 " try (I i = getX()) {\n" +
4153 " } catch (FileNotFoundException x) {\n" +
4154 " }\n"+
4155 " System.out.println(\"Done\");\n" +
4156 " }\n" +
4157 " public static I getX() { return null;}\n"+
4158 " public X(){}\n" +
4159 "}\n"
4160 },
4161 "Done");
4162 }
4163 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112
4164 //test380112c's variant with finally
test380112d()4165 public void test380112d() {
4166 this.runConformTest(
4167 new String[] {
4168 "X.java",
4169 "import java.io.*;\n" +
4170 "interface I2 { public void close() throws FileNotFoundException; }\n"+
4171 "interface I extends Closeable, I2 {}\n" +
4172 "public class X {\n"+
4173 " public static void main(String [] args) {\n" +
4174 " try (I i = getX()) {\n" +
4175 " } catch (FileNotFoundException x) {\n" +
4176 " } finally {\n"+
4177 " System.out.println(\"Done\");\n" +
4178 " }\n" +
4179 " }\n" +
4180 " public static I getX() { return null;}\n"+
4181 " public X(){}\n" +
4182 "}\n"
4183 },
4184 "Done");
4185 }
4186 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=380112
4187 //test380112a variant moving the Interface into a binary
test380112e()4188 public void test380112e() {
4189 String path = this.getCompilerTestsPluginDirectoryPath() + File.separator + "workspace" + File.separator + "Test380112.jar";
4190 String[] defaultLibs = getDefaultClassPaths();
4191 String[] libs = new String[defaultLibs.length + 1];
4192 System.arraycopy(defaultLibs, 0, libs, 0, defaultLibs.length);
4193 libs[defaultLibs.length] = path;
4194 this.runConformTest(
4195 new String[] {
4196 "X.java",
4197 "import java.io.*;\n" +
4198 "import pkg380112.I;\n" +
4199 "public class X {\n"+
4200 " public static void main(String [] args) {\n" +
4201 " try (I i = getX()) {\n" +
4202 " } catch (IOException x) {\n" +
4203 " }\n"+
4204 " System.out.println(\"Done\");\n" +
4205 " }\n" +
4206 " public static I getX() { return null;}\n"+
4207 " public X(){}\n" +
4208 "}\n"
4209 }, "Done", libs, true, new String[] {"-cp", "."+File.pathSeparator+path});
4210 }
4211 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=394780
test394780()4212 public void test394780() {
4213 this.runConformTest(
4214 new String[] {
4215 "X.java",
4216 "public class X<R extends Resource> {\n" +
4217 " public static void main(String[] args) {\n" +
4218 " X<Resource> m = new X<>();\n" +
4219 " m.tryWithResource(new ResourceImpl());\n" +
4220 " }\n" +
4221 " public void tryWithResource(R resource) {\n" +
4222 " try (R r = resource) {\n" +
4223 " r.compute();\n" +
4224 " }\n" +
4225 " }\n" +
4226 "}",
4227 "Resource.java",
4228 "public interface Resource extends AutoCloseable {\n" +
4229 " void compute();\n" +
4230 " @Override\n" +
4231 " public void close();\n" +
4232 "}",
4233 "ResourceImpl.java",
4234 "public class ResourceImpl implements Resource {\n" +
4235 " @Override\n" +
4236 " public void close() {\n" +
4237 " System.out.print(\"close\");\n" +
4238 " }\n" +
4239 " @Override\n" +
4240 " public void compute() {\n" +
4241 " System.out.print(\"compute\");\n" +
4242 " }\n" +
4243 "}"
4244 },
4245 "computeclose");
4246 }
4247 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=533187
testBug533187()4248 public void testBug533187() {
4249 this.runConformTest(
4250 true,
4251 new String[] {
4252 "Stuck.java",
4253 "public class Stuck {\n" +
4254 " public static void main(String[] args) {\n" +
4255 " System.out.println(snippet1());\n" +
4256 " }\n" +
4257 " public static String snippet1() {\n" +
4258 " try {\n" +
4259 " synchronized (String.class) {\n" +
4260 " try (AutoCloseable scope = null) { \n" +
4261 " return \"RETURN\";\n" +
4262 " } catch (Throwable t) {\n" +
4263 " return t.toString();\n" +
4264 " }\n" +
4265 " }\n" +
4266 " } finally {\n" +
4267 " raise();\n" +
4268 " }\n" +
4269 " }\n" +
4270 " public static void raise() {\n" +
4271 " throw new RuntimeException();\n" +
4272 " }\n" +
4273 "}"
4274 },
4275 null,
4276 null,
4277 null,
4278 null,
4279 "java.lang.RuntimeException\n" +
4280 " at Stuck.raise(Stuck.java:19)\n" +
4281 " at Stuck.snippet1(Stuck.java:15)\n" +
4282 " at Stuck.main(Stuck.java:3)\n",
4283 null);
4284 }
4285 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=467230
testBug467230()4286 public void testBug467230() {
4287 this.runConformTest(
4288 true,
4289 new String[] {
4290 "Test.java",
4291 "public class Test {\n" +
4292 " static class C implements AutoCloseable {\n" +
4293 " @Override\n" +
4294 " public void close() {\n" +
4295 " System.out.println(\"close\");\n" +
4296 " }\n" +
4297 " }\n" +
4298 " public static void main(String[] args) {\n" +
4299 " try (C c = new C()) {\n" +
4300 " return;\n" +
4301 " } catch (Exception e) {\n" +
4302 " System.out.println(\"catch\");\n" +
4303 " } finally {\n" +
4304 " f();\n" +
4305 " }\n" +
4306 " }\n" +
4307 " private static void f() {\n" +
4308 " System.out.println(\"finally\");\n" +
4309 " throw new RuntimeException();\n" +
4310 " }\n" +
4311 "}"
4312 },
4313 null,
4314 null,
4315 null,
4316 "close\n" +
4317 "finally",
4318 "java.lang.RuntimeException\n" +
4319 " at Test.f(Test.java:19)\n" +
4320 " at Test.main(Test.java:14)\n",
4321 null);
4322 }
testClass()4323 public static Class testClass() {
4324 return TryWithResourcesStatementTest.class;
4325 }
4326 }
4327