1/* 2 * @test /nodynamiccopyright/ 3 * @bug 7015430 4 * 5 * @summary Incorrect thrown type determined for unchecked invocations 6 * @author Daniel Smith 7 * @compile/fail/ref=T7015430_1.out -source 7 -Xlint:-options,unchecked -XDrawDiagnostics T7015430.java 8 * @compile/fail/ref=T7015430_2.out -Xlint:unchecked -XDrawDiagnostics T7015430.java 9 * 10 */ 11 12class T7015430 { 13 static <E extends Exception> Iterable<E> empty(Iterable<E> arg) throws E { 14 return null; 15 } 16 17 <E extends Exception> T7015430(Iterable<E> arg) throws E { } 18 19 static <E extends Exception> Iterable<E> empty2(Iterable x) throws E { 20 return null; 21 } 22 23 static class Foo<X extends Exception> { 24 Foo() throws X {} 25 } 26 27 /** 28 * Method invocation, no unchecked 29 * inferred: RuntimeException - should pass 30 */ 31 void m1() { 32 Iterable<RuntimeException> i = java.util.Collections.emptyList(); 33 empty(i); 34 } 35 36 /** 37 * Method invocation, unchecked, inferred arguments 38 * inferred: Exception - should fail 39 */ 40 void m2() { 41 Iterable i = java.util.Collections.EMPTY_LIST; 42 empty(i); 43 } 44 45 /** 46 * Method invocation, unchecked, explicit arguments 47 * inferred: RuntimeException - should pass 48 */ 49 void m3() { 50 Iterable i = java.util.Collections.EMPTY_LIST; 51 T7015430.<RuntimeException>empty(i); 52 } 53 54 /** 55 * Constructor invocation, no unchecked 56 * inferred: RuntimeException - should pass 57 */ 58 void m4() { 59 Iterable<RuntimeException> i = java.util.Collections.emptyList(); 60 new T7015430(i); 61 } 62 63 /** 64 * Constructor invocation, unchecked, inferred arguments 65 * inferred: Exception - should fail 66 */ 67 void m5() { 68 Iterable i = java.util.Collections.EMPTY_LIST; 69 new T7015430(i); 70 } 71 72 /** 73 * Constructor invocation, unchecked, explicit arguments 74 * inferred: RuntimeException - should pass 75 */ 76 void m6() { 77 Iterable i = java.util.Collections.EMPTY_LIST; 78 new <RuntimeException>T7015430(i); 79 } 80 81 /** 82 * Method invocation, no unchecked, inferred arguments 83 * inferred: RuntimeException - should pass 84 */ 85 void m7() { 86 Iterable i = java.util.Collections.EMPTY_LIST; 87 Iterable<RuntimeException> e = empty2(i); 88 } 89 90 /** 91 * Method invocation, no unchecked, inferred arguments 92 * inferred: Exception - should fail 93 */ 94 void m8() { 95 Iterable i = java.util.Collections.EMPTY_LIST; 96 empty2(i); 97 } 98 99 /** 100 * Constructor invocation, unchecked, explicit arguments 101 * inferred: RuntimeException - should pass 102 */ 103 void m9() { 104 Iterable i = java.util.Collections.EMPTY_LIST; 105 new <RuntimeException> T7015430(i); 106 } 107 108 /** 109 * Constructor invocation, unchecked, inferred arguments 110 * inferred: Exception - should fail 111 */ 112 void m10() { 113 Iterable i = java.util.Collections.EMPTY_LIST; 114 new T7015430(i); 115 } 116 117 /** 118 * Constructor invocation, no unchecked, inferred arguments (diamond) 119 * inferred: RuntimeException - should pass 120 */ 121 void m11() { 122 Foo<RuntimeException> o = new Foo<>(); 123 } 124 125 /** 126 * Constructor invocation, no unchecked, inferred arguments (diamond) 127 * inferred: Exception - should fail 128 */ 129 void m12() { 130 new Foo<>(); 131 } 132} 133