author | hseigel |
Wed, 02 Mar 2016 23:48:41 +0000 | |
changeset 36397 | c487ced7231c |
parent 17579 | cd92ab6433e9 |
permissions | -rw-r--r-- |
17579
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
1 |
/* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
4 |
* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
8 |
* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
13 |
* accompanied this code). |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
14 |
* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
18 |
* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
21 |
* questions. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
22 |
*/ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
23 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
24 |
/* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
25 |
* @test |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
26 |
* @bug 8013163 |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
27 |
* @author sogoel |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
28 |
* @summary Test multiple nested multi-catch blocks with Exception hierarchies |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
29 |
* @run main Pos11 |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
30 |
*/ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
31 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
32 |
/* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
33 |
* For this test, exception hierarchy used: |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
34 |
* |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
35 |
* Throwable |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
36 |
* / \ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
37 |
* Exception Error |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
38 |
* | | | |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
39 |
* A B D |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
40 |
* | |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
41 |
* C |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
42 |
* | |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
43 |
* E |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
44 |
* As an exception is thrown within a nested try-catch block, outer catch blocks |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
45 |
* will catch an exception or its child exceptions, so the same exception can |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
46 |
* be caught and rethrown multiple times. |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
47 |
*/ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
48 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
49 |
public class Pos11 { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
50 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
51 |
public static String results = ""; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
52 |
public static String sExpected = "-AB:A-AB:B-CD:C-AB:C-CD:D-Throwable:D-CD:E" + |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
53 |
"-AB:E-Exception:Exception-Throwable:Exception"; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
54 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
55 |
enum TestExceptions { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
56 |
A("A"), |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
57 |
B("B"), |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
58 |
C("C"), |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
59 |
D("D"), |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
60 |
E("E"), |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
61 |
U("U"); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
62 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
63 |
String exType; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
64 |
TestExceptions(String type) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
65 |
this.exType = type; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
66 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
67 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
68 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
69 |
public static void main(String... args) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
70 |
Pos11 pos11 = new Pos11(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
71 |
for(TestExceptions t : TestExceptions.values()) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
72 |
pos11.rethrower(t.exType); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
73 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
74 |
if (results.compareTo(sExpected) != 0) |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
75 |
throw new RuntimeException("FAIL: final strings did not match:\n" |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
76 |
+ results + "!=\n" + sExpected); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
77 |
System.out.println("PASS"); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
78 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
79 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
80 |
void rethrower(String T) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
81 |
try { /* try1 */ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
82 |
try { /* try2 */ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
83 |
try { /* try3 */ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
84 |
try { /* try4 */ |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
85 |
switch (T) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
86 |
case "A": |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
87 |
throw new A(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
88 |
case "B": |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
89 |
throw new B(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
90 |
case "C": |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
91 |
throw new C(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
92 |
case "D": |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
93 |
throw new D(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
94 |
case "E": |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
95 |
throw new E(); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
96 |
default: |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
97 |
throw new Exception( |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
98 |
new Throwable()); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
99 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
100 |
} catch ( final C|D cd) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
101 |
results=results.concat("-CD:" + cd.getClass().getSimpleName()); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
102 |
throw cd; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
103 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
104 |
} catch (final A|B ab) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
105 |
results=results.concat("-AB:" + ab.getClass().getSimpleName()); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
106 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
107 |
} catch (final Exception e ) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
108 |
results=results.concat("-Exception:" + e.getClass().getSimpleName()); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
109 |
throw e; |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
110 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
111 |
} catch (Throwable t) { |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
112 |
results=results.concat("-Throwable:" + t.getClass().getSimpleName()); |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
113 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
114 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
115 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
116 |
// Test Exception |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
117 |
static class A extends Exception {} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
118 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
119 |
// Test Exception |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
120 |
static class B extends Exception {} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
121 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
122 |
// Test Exception |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
123 |
static class C extends B {} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
124 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
125 |
// Not a descendant of Exception |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
126 |
static class D extends Error {} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
127 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
128 |
// Test Exception |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
129 |
static class E extends C {} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
130 |
|
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
131 |
} |
cd92ab6433e9
8013163: Convert 4 tools multicatch tests to jtreg format
sogoel
parents:
diff
changeset
|
132 |