Tue, 14 May 2013 18:02:48 -0700
8013163: Convert 4 tools multicatch tests to jtreg format
Reviewed-by: jjg
test/tools/javac/multicatch/Pos11.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/multicatch/Pos12.java | file | annotate | diff | comparison | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/multicatch/Pos11.java Tue May 14 18:02:48 2013 -0700 1.3 @@ -0,0 +1,132 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 +/* 1.28 + * @test 1.29 + * @bug 8013163 1.30 + * @author sogoel 1.31 + * @summary Test multiple nested multi-catch blocks with Exception hierarchies 1.32 + * @run main Pos11 1.33 + */ 1.34 + 1.35 +/* 1.36 + * For this test, exception hierarchy used: 1.37 + * 1.38 + * Throwable 1.39 + * / \ 1.40 + * Exception Error 1.41 + * | | | 1.42 + * A B D 1.43 + * | 1.44 + * C 1.45 + * | 1.46 + * E 1.47 + * As an exception is thrown within a nested try-catch block, outer catch blocks 1.48 + * will catch an exception or its child exceptions, so the same exception can 1.49 + * be caught and rethrown multiple times. 1.50 + */ 1.51 + 1.52 +public class Pos11 { 1.53 + 1.54 + public static String results = ""; 1.55 + public static String sExpected = "-AB:A-AB:B-CD:C-AB:C-CD:D-Throwable:D-CD:E" + 1.56 + "-AB:E-Exception:Exception-Throwable:Exception"; 1.57 + 1.58 + enum TestExceptions { 1.59 + A("A"), 1.60 + B("B"), 1.61 + C("C"), 1.62 + D("D"), 1.63 + E("E"), 1.64 + U("U"); 1.65 + 1.66 + String exType; 1.67 + TestExceptions(String type) { 1.68 + this.exType = type; 1.69 + } 1.70 + } 1.71 + 1.72 + public static void main(String... args) { 1.73 + Pos11 pos11 = new Pos11(); 1.74 + for(TestExceptions t : TestExceptions.values()) { 1.75 + pos11.rethrower(t.exType); 1.76 + } 1.77 + if (results.compareTo(sExpected) != 0) 1.78 + throw new RuntimeException("FAIL: final strings did not match:\n" 1.79 + + results + "!=\n" + sExpected); 1.80 + System.out.println("PASS"); 1.81 + } 1.82 + 1.83 + void rethrower(String T) { 1.84 + try { /* try1 */ 1.85 + try { /* try2 */ 1.86 + try { /* try3 */ 1.87 + try { /* try4 */ 1.88 + switch (T) { 1.89 + case "A": 1.90 + throw new A(); 1.91 + case "B": 1.92 + throw new B(); 1.93 + case "C": 1.94 + throw new C(); 1.95 + case "D": 1.96 + throw new D(); 1.97 + case "E": 1.98 + throw new E(); 1.99 + default: 1.100 + throw new Exception( 1.101 + new Throwable()); 1.102 + } 1.103 + } catch ( final C|D cd) { 1.104 + results=results.concat("-CD:" + cd.getClass().getSimpleName()); 1.105 + throw cd; 1.106 + } 1.107 + } catch (final A|B ab) { 1.108 + results=results.concat("-AB:" + ab.getClass().getSimpleName()); 1.109 + } 1.110 + } catch (final Exception e ) { 1.111 + results=results.concat("-Exception:" + e.getClass().getSimpleName()); 1.112 + throw e; 1.113 + } 1.114 + } catch (Throwable t) { 1.115 + results=results.concat("-Throwable:" + t.getClass().getSimpleName()); 1.116 + } 1.117 + } 1.118 + 1.119 + // Test Exception 1.120 + static class A extends Exception {} 1.121 + 1.122 + // Test Exception 1.123 + static class B extends Exception {} 1.124 + 1.125 + // Test Exception 1.126 + static class C extends B {} 1.127 + 1.128 + // Not a descendant of Exception 1.129 + static class D extends Error {} 1.130 + 1.131 + // Test Exception 1.132 + static class E extends C {} 1.133 + 1.134 +} 1.135 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/multicatch/Pos12.java Tue May 14 18:02:48 2013 -0700 2.3 @@ -0,0 +1,76 @@ 2.4 +/* 2.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 8013163 2.30 + * @author sogoel 2.31 + * @summary Child exception can be caught in a parents catch block but not sibling exceptions. 2.32 + * @run main Pos12 2.33 + */ 2.34 + 2.35 +/* 2.36 + * For this test: 2.37 + * RuntimeException 2.38 + * | 2.39 + * A 2.40 + * / \ 2.41 + * Ab Ac 2.42 + * This test throws an Ab and catches it as an A(parent). 2.43 + * The exception, although catch as an A, is rethrown and eventually 2.44 + * caught as an Ab. Before that it is NOT caught as an Ac. 2.45 + */ 2.46 + 2.47 +public class Pos12 { 2.48 + 2.49 + public static void main(String... args) { 2.50 + try { 2.51 + new Pos12().test(); 2.52 + } catch (A exception) { 2.53 + try { 2.54 + try { 2.55 + throw exception; // used to throw A, now throws Ab 2.56 + } catch (Ac cException) { // This should NOT catch sibling exception Ab 2.57 + throw new RuntimeException("FAIL: Should not be caught in catch Ac"); 2.58 + } 2.59 + } catch (Ab | Ac bcException) { 2.60 + if (bcException instanceof Ac) { 2.61 + throw new RuntimeException("FAIL: Sibling exception Ab not caught as expected"); 2.62 + } else if (bcException instanceof Ab) { 2.63 + System.out.println("PASS"); 2.64 + } 2.65 + } 2.66 + } 2.67 + } 2.68 + 2.69 + public void test() { throw new Ab(); } 2.70 + 2.71 + static class A extends RuntimeException {} 2.72 + 2.73 + // Test class 2.74 + static class Ab extends A {} 2.75 + 2.76 + // Test class 2.77 + static class Ac extends A {} 2.78 +} 2.79 +