21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /** |
24 /** |
25 * @test |
25 * @test |
26 * @bug 8025260 8016839 |
26 * @bug 8025260 8016839 8046171 |
27 * @summary Ensure that AbstractMethodError and IllegalAccessError are thrown appropriately, not NullPointerException |
27 * @summary Ensure that correct exceptions are thrown, not NullPointerException |
28 * @modules java.base/jdk.internal.org.objectweb.asm |
28 * @modules java.base/jdk.internal.org.objectweb.asm |
29 * @library / . |
29 * @library / . |
30 * |
30 * |
31 * @build p.* |
31 * @build p.* |
32 * @run main/othervm compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
32 * @run main/othervm compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
33 * @run main/othervm -Xint compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
33 * @run main/othervm -Xint compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
34 * @run main/othervm -Xcomp compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
34 * @run main/othervm -Xcomp compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
35 */ |
35 */ |
|
36 |
|
37 // Since this test was written the specification for interface method selection has been |
|
38 // revised (JEP 181 - Nestmates) so that private methods are never selected, as they never |
|
39 // override any inherited method. So where a private method was previously selected |
|
40 // and then resulted in IllegalAccessError, the private method is skipped and the invocation |
|
41 // will either succeed or fail based on what other implementations are found in the inheritance |
|
42 // hierarchy. This is explained for each test below. |
36 |
43 |
37 package compiler.jsr292.methodHandleExceptions; |
44 package compiler.jsr292.methodHandleExceptions; |
38 |
45 |
39 import p.Dok; |
46 import p.Dok; |
40 import jdk.internal.org.objectweb.asm.ClassWriter; |
47 import jdk.internal.org.objectweb.asm.ClassWriter; |
89 if (!(writeJarFiles || readJarFiles)) { |
96 if (!(writeJarFiles || readJarFiles)) { |
90 throw new Error("Command line parameter (if any) should be prefix of writeJarFiles or readJarFiles"); |
97 throw new Error("Command line parameter (if any) should be prefix of writeJarFiles or readJarFiles"); |
91 } |
98 } |
92 } |
99 } |
93 |
100 |
94 try { |
101 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL"); |
95 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL"); |
102 System.out.println(" - should invoke p.F.m as private p.D.m is skipped for selection"); |
96 tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"), |
103 tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"), |
97 "p.D extends p.F (p.F implements p.I, FINAL public m), private m", |
104 "p.D extends p.F (p.F implements p.I, FINAL public m), private m", |
98 IllegalAccessError.class, "pD_ext_pF"); |
105 null /* should succeed */, "pD_ext_pF"); |
99 // We'll take either a VerifyError (pre 2013-11-30) |
|
100 // or an IllegalAccessError (post 2013-11-22) |
|
101 } catch (VerifyError ve) { |
|
102 System.out.println("Saw expected VerifyError " + ve); |
|
103 } |
|
104 System.out.println(); |
106 System.out.println(); |
105 |
107 |
106 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E"); |
108 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E"); |
|
109 System.out.println(" - should invoke p.E.m as private p.D.m is skipped for selection"); |
107 tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"), |
110 tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"), |
108 "p.D extends p.E (p.E implements p.I, public m), private m", |
111 "p.D extends p.E (p.E implements p.I, public m), private m", |
109 IllegalAccessError.class, "pD_ext_pE"); |
112 null /* should succeed */, "pD_ext_pE"); |
110 |
113 |
111 System.out.println("TRYING p.D.m ABSTRACT interface-invoked as p.I.m"); |
114 System.out.println("TRYING p.D.m ABSTRACT interface-invoked as p.I.m"); |
112 tryAndCheckThrown(lt, bytesForD(), |
115 tryAndCheckThrown(lt, bytesForD(), |
113 "D extends abstract C, no m", |
116 "D extends abstract C, no m", |
114 AbstractMethodError.class, "pD_ext_pC"); |
117 AbstractMethodError.class, "pD_ext_pC"); |
115 |
118 |
116 System.out.println("TRYING q.D.m PACKAGE interface-invoked as p.I.m"); |
119 System.out.println("TRYING q.D.m PACKAGE interface-invoked as p.I.m"); |
117 tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0), |
120 tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0), |
118 "q.D implements p.I, protected m", IllegalAccessError.class, |
121 "q.D implements p.I, protected m", |
119 "qD_m_pp_imp_pI"); |
122 IllegalAccessError.class, "qD_m_pp_imp_pI"); |
120 |
123 |
121 // Note jar file name is used in the plural-arg case. |
124 // Note jar file name is used in the plural-arg case. |
122 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m"); |
125 System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m"); |
|
126 System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection"); |
123 tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
127 tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
124 "p.D implements p.I, private m", |
128 "p.D implements p.I, private m", |
125 IllegalAccessError.class, "pD_m_pri_imp_pI"); |
129 null /* should succeed */, "pD_m_pri_imp_pI"); |
126 |
130 |
127 // Plural-arg test. |
131 // Plural-arg test. |
128 System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m"); |
132 System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m"); |
|
133 System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection"); |
129 tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
134 tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
130 "p.D implements p.I, private m", IllegalAccessError.class); |
135 "p.D implements p.I, private m", null /* should succeed */); |
131 |
136 |
132 if (lt.size() > 0) { |
137 if (lt.size() > 0) { |
133 System.out.flush(); |
138 System.out.flush(); |
134 Thread.sleep(250); // This de-interleaves output and error in Netbeans, sigh. |
139 Thread.sleep(250); // This de-interleaves output and error in Netbeans, sigh. |
135 for (Throwable th : lt) |
140 for (Throwable th : lt) |