Sat, 22 Dec 2018 13:10:38 -0800
Added tag jdk8u202-b25 for changeset 15d8c732039b
1 /*
2 * @test /nodynamiccopyright/
3 * @bug 7039822
4 * @summary Verify typing of lub of exception parameter w.r.t getClass
5 * @author Joseph D. Darcy
6 * @compile/fail/ref=Neg07.out -XDrawDiagnostics Neg07.java
7 */
9 public class Neg07 {
10 private static void test(int i) {
11 try {
12 thrower(i);
13 } catch (SonException | DaughterException e) {
14 Class<? extends HasFoo> clazz2 = e.getClass(); // Rejected!
15 HasFoo m = e;
16 e.foo();
17 }
18 }
20 private static interface HasFoo {
21 void foo();
22 }
24 static void thrower(int i) throws SonException, DaughterException {
25 if (i == 0)
26 throw new SonException();
27 else
28 throw new DaughterException();
29 }
31 private static class ParentException extends RuntimeException {}
33 private static class SonException
34 extends ParentException
35 implements HasFoo {
37 public void foo() {
38 System.out.println("SonException.foo");
39 }
40 }
42 private static class DaughterException
43 extends ParentException
44 implements HasFoo {
46 public void foo() {
47 System.out.println("DaughterException.foo");
48 }
49 }
50 }