|
1 |
|
2 import java.io.PrintWriter; |
|
3 import java.io.StringWriter; |
|
4 import java.nio.file.Paths; |
|
5 |
|
6 /* |
|
7 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
|
8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
9 * |
|
10 * This code is free software; you can redistribute it and/or modify it |
|
11 * under the terms of the GNU General Public License version 2 only, as |
|
12 * published by the Free Software Foundation. |
|
13 * |
|
14 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
17 * version 2 for more details (a copy is included in the LICENSE file that |
|
18 * accompanied this code). |
|
19 * |
|
20 * You should have received a copy of the GNU General Public License version |
|
21 * 2 along with this work; if not, write to the Free Software Foundation, |
|
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
23 * |
|
24 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
25 * or visit www.oracle.com if you need additional information or have any |
|
26 * questions. |
|
27 */ |
|
28 |
|
29 /* |
|
30 * @test |
|
31 * @bug 6181889 |
|
32 * @summary Empty try/finally results in bytecodes being generated |
|
33 */ |
|
34 |
|
35 public class EmptyFinallyTest { |
|
36 private static final String assertionErrorMsg = |
|
37 "No \"Exception table\" should be generated in this case"; |
|
38 |
|
39 public static void main(String[] args) { |
|
40 new EmptyFinallyTest().run(); |
|
41 } |
|
42 |
|
43 void run() { |
|
44 check("-c", Paths.get(System.getProperty("test.classes"), |
|
45 "EmptyFinally.class").toString()); |
|
46 } |
|
47 |
|
48 void check(String... params) { |
|
49 StringWriter s; |
|
50 String out; |
|
51 try (PrintWriter pw = new PrintWriter(s = new StringWriter())) { |
|
52 com.sun.tools.javap.Main.run(params, pw); |
|
53 out = s.toString(); |
|
54 } |
|
55 if (out.contains("Exception table")) { |
|
56 throw new AssertionError(assertionErrorMsg); |
|
57 } |
|
58 } |
|
59 } |
|
60 |
|
61 class EmptyFinally { |
|
62 void m() { |
|
63 try { |
|
64 System.out.println("EMPTY TRY!"); |
|
65 } finally {} |
|
66 } |
|
67 } |