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 */ 8 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 } 19 20 private static interface HasFoo { 21 void foo(); 22 } 23 24 static void thrower(int i) throws SonException, DaughterException { 25 if (i == 0) 26 throw new SonException(); 27 else 28 throw new DaughterException(); 29 } 30 31 private static class ParentException extends RuntimeException {} 32 33 private static class SonException 34 extends ParentException 35 implements HasFoo { 36 37 public void foo() { 38 System.out.println("SonException.foo"); 39 } 40 } 41 42 private static class DaughterException 43 extends ParentException 44 implements HasFoo { 45 46 public void foo() { 47 System.out.println("DaughterException.foo"); 48 } 49 } 50 }