author | dholmes |
Sat, 23 Jun 2018 01:32:41 -0400 | |
changeset 50735 | 2f2af62dfac7 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
1 |
/* |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
4 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
8 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
13 |
* accompanied this code). |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
14 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
18 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
21 |
* questions. |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
22 |
*/ |
40059 | 23 |
|
24 |
/** |
|
25 |
* @test |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
26 |
* @bug 8025260 8016839 8046171 |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
27 |
* @summary Ensure that correct exceptions are thrown, not NullPointerException |
40059 | 28 |
* @modules java.base/jdk.internal.org.objectweb.asm |
29 |
* @library / . |
|
30 |
* |
|
31 |
* @build p.* |
|
32 |
* @run main/othervm compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
|
33 |
* @run main/othervm -Xint compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
|
34 |
* @run main/othervm -Xcomp compiler.jsr292.methodHandleExceptions.TestAMEnotNPE |
|
35 |
*/ |
|
36 |
||
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
37 |
// Since this test was written the specification for interface method selection has been |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
38 |
// revised (JEP 181 - Nestmates) so that private methods are never selected, as they never |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
39 |
// override any inherited method. So where a private method was previously selected |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
40 |
// and then resulted in IllegalAccessError, the private method is skipped and the invocation |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
41 |
// will either succeed or fail based on what other implementations are found in the inheritance |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
42 |
// hierarchy. This is explained for each test below. |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
43 |
|
40059 | 44 |
package compiler.jsr292.methodHandleExceptions; |
45 |
||
46 |
import p.Dok; |
|
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
47 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
48 |
import jdk.internal.org.objectweb.asm.Handle; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
49 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
50 |
import jdk.internal.org.objectweb.asm.Opcodes; |
40059 | 51 |
|
52 |
import java.lang.reflect.InvocationTargetException; |
|
53 |
import java.lang.reflect.Method; |
|
54 |
import java.util.ArrayList; |
|
55 |
import java.util.List; |
|
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
56 |
|
40059 | 57 |
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE; |
58 |
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC; |
|
59 |
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC; |
|
60 |
import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER; |
|
61 |
import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD; |
|
62 |
import static jdk.internal.org.objectweb.asm.Opcodes.ILOAD; |
|
63 |
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKESPECIAL; |
|
64 |
import static jdk.internal.org.objectweb.asm.Opcodes.INVOKEVIRTUAL; |
|
65 |
import static jdk.internal.org.objectweb.asm.Opcodes.IRETURN; |
|
66 |
import static jdk.internal.org.objectweb.asm.Opcodes.LLOAD; |
|
67 |
import static jdk.internal.org.objectweb.asm.Opcodes.RETURN; |
|
68 |
import static jdk.internal.org.objectweb.asm.Opcodes.V1_8; |
|
69 |
||
70 |
public class TestAMEnotNPE { |
|
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
71 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
72 |
static boolean writeJarFiles = false; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
73 |
static boolean readJarFiles = false; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
74 |
|
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
75 |
/** |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
76 |
* Optional command line parameter (any case-insensitive prefix of) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
77 |
* "writejarfiles" or "readjarfiles". |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
78 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
79 |
* "Writejarfiles" creates a jar file for each different set of tested classes. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
80 |
* "Readjarfiles" causes the classloader to use the copies of the classes |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
81 |
* found in the corresponding jar files. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
82 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
83 |
* Jarfilenames look something like pD_ext_pF (p.D extends p.F) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
84 |
* and qD_m_pp_imp_pI (q.D with package-private m implements p.I) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
85 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
86 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
87 |
public static void main(String args[]) throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
88 |
ArrayList<Throwable> lt = new ArrayList<Throwable>(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
89 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
90 |
if (args.length > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
91 |
String a0 = args[0].toLowerCase(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
92 |
if (a0.length() > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
93 |
writeJarFiles = ("writejarfiles").startsWith(a0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
94 |
readJarFiles = ("readjarfiles").startsWith(a0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
95 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
96 |
if (!(writeJarFiles || readJarFiles)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
97 |
throw new Error("Command line parameter (if any) should be prefix of writeJarFiles or readJarFiles"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
98 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
99 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
100 |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
101 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL"); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
102 |
System.out.println(" - should invoke p.F.m as private p.D.m is skipped for selection"); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
103 |
tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
104 |
"p.D extends p.F (p.F implements p.I, FINAL public m), private m", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
105 |
null /* should succeed */, "pD_ext_pF"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
106 |
System.out.println(); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
107 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
108 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E"); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
109 |
System.out.println(" - should invoke p.E.m as private p.D.m is skipped for selection"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
110 |
tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"), |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
111 |
"p.D extends p.E (p.E implements p.I, public m), private m", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
112 |
null /* should succeed */, "pD_ext_pE"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
113 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
114 |
System.out.println("TRYING p.D.m ABSTRACT interface-invoked as p.I.m"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
115 |
tryAndCheckThrown(lt, bytesForD(), |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
116 |
"D extends abstract C, no m", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
117 |
AbstractMethodError.class, "pD_ext_pC"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
118 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
119 |
System.out.println("TRYING q.D.m PACKAGE interface-invoked as p.I.m"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
120 |
tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0), |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
121 |
"q.D implements p.I, protected m", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
122 |
IllegalAccessError.class, "qD_m_pp_imp_pI"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
123 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
124 |
// Note jar file name is used in the plural-arg case. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
125 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m"); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
126 |
System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
127 |
tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
128 |
"p.D implements p.I, private m", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
129 |
null /* should succeed */, "pD_m_pri_imp_pI"); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
130 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
131 |
// Plural-arg test. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
132 |
System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m"); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
133 |
System.out.println(" - should invoke p.I.m as private p.D.m is skipped for selection"); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
134 |
tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
47216
diff
changeset
|
135 |
"p.D implements p.I, private m", null /* should succeed */); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
136 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
137 |
if (lt.size() > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
138 |
System.out.flush(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
139 |
Thread.sleep(250); // This de-interleaves output and error in Netbeans, sigh. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
140 |
for (Throwable th : lt) |
40059 | 141 |
System.err.println(th); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
142 |
throw new Error("Test failed, there were " + lt.size() + " failures listed above"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
143 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
144 |
System.out.println("ALL PASS, HOORAY!"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
145 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
146 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
147 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
148 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
149 |
* The bytes for D, a NOT abstract class extending abstract class C without |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
150 |
* supplying an implementation for abstract method m. There is a default |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
151 |
* method in the interface I, but it should lose to the abstract class. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
152 |
* |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
153 |
* @return |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
154 |
* @throws Exception |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
155 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
156 |
public static byte[] bytesForD() throws Exception { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
157 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
158 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
159 |
| ClassWriter.COMPUTE_MAXS); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
160 |
MethodVisitor mv; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
161 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
162 |
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/D", null, "p/C", null); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
163 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
164 |
{ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
165 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
166 |
mv.visitCode(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
167 |
mv.visitVarInsn(ALOAD, 0); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
168 |
mv.visitMethodInsn(INVOKESPECIAL, "p/C", "<init>", "()V"); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
169 |
mv.visitInsn(RETURN); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
170 |
mv.visitMaxs(0, 0); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
171 |
mv.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
172 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
173 |
cw.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
174 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
175 |
return cw.toByteArray(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
176 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
177 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
178 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
179 |
* The bytes for D, implements I, does not extend C, declares m()I with |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
180 |
* access method_acc. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
181 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
182 |
* @param d_name Name of class defined |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
183 |
* @param method_acc Accessibility of that class's method m. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
184 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
185 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
186 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
187 |
public static byte[] bytesForDsomeAccess(String d_name, int method_acc) throws Exception { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
188 |
return bytesForSomeDsubSomethingSomeAccess(d_name, "java/lang/Object", method_acc); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
189 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
190 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
191 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
192 |
* The bytes for D implements I, extends some class, declares m()I as |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
193 |
* private. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
194 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
195 |
* Invokeinterface of I.m applied to this D should throw IllegalAccessError |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
196 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
197 |
* @param sub_what The name of the class that D will extend. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
198 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
199 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
200 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
201 |
public static byte[] bytesForDprivateSubWhat(String sub_what) throws Exception { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
202 |
return bytesForSomeDsubSomethingSomeAccess("p/D", sub_what, ACC_PRIVATE); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
203 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
204 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
205 |
/** |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
206 |
* Returns the bytes for a class with name d_name (presumably "D" in some |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
207 |
* package), extending some class with name sub_what, implementing p.I, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
208 |
* and defining two methods m() and m(11args) with access method_acc. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
209 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
210 |
* @param d_name Name of class that is defined |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
211 |
* @param sub_what Name of class that it extends |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
212 |
* @param method_acc Accessibility of method(s) m in defined class. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
213 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
214 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
215 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
216 |
public static byte[] bytesForSomeDsubSomethingSomeAccess |
40059 | 217 |
(String d_name, String sub_what, int method_acc) |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
218 |
throws Exception { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
219 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
220 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
221 |
| ClassWriter.COMPUTE_MAXS); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
222 |
MethodVisitor mv; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
223 |
String[] interfaces = {"p/I"}; |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
224 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
225 |
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, d_name, null, sub_what, interfaces); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
226 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
227 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
228 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
229 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
230 |
mv.visitMethodInsn(INVOKESPECIAL, sub_what, "<init>", "()V"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
231 |
mv.visitInsn(RETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
232 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
233 |
mv.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
234 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
235 |
// int m() {return 3;} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
236 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
237 |
mv = cw.visitMethod(method_acc, "m", "()I", null, null); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
238 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
239 |
mv.visitLdcInsn(new Integer(3)); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
240 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
241 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
242 |
mv.visitEnd(); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
243 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
244 |
// int m(11args) {return 3;} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
245 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
246 |
mv = cw.visitMethod(method_acc, "m", "(BCSIJ" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
247 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
248 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
249 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
250 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
251 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
252 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
253 |
+ ")I", null, null); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
254 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
255 |
mv.visitLdcInsn(new Integer(3)); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
256 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
257 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
258 |
mv.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
259 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
260 |
cw.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
261 |
return cw.toByteArray(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
262 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
263 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
264 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
265 |
* The bytecodes for a class p/T defining a methods test() and test(11args) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
266 |
* that contain an invokeExact of a particular methodHandle, I.m. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
267 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
268 |
* Test will be passed values that may imperfectly implement I, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
269 |
* and thus may in turn throw exceptions. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
270 |
* |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
271 |
* @return |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
272 |
* @throws Exception |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
273 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
274 |
public static byte[] bytesForT() throws Exception { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
275 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
276 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
277 |
| ClassWriter.COMPUTE_MAXS); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
278 |
MethodVisitor mv; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
279 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
280 |
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "p/T", null, "java/lang/Object", null); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
281 |
{ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
282 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
283 |
mv.visitCode(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
284 |
mv.visitVarInsn(ALOAD, 0); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
285 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
286 |
mv.visitInsn(RETURN); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
287 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
288 |
mv.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
289 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
290 |
// static int test(I) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
291 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
292 |
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;)I", null, null); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
293 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
294 |
mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "()I")); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
295 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
296 |
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
297 |
"invokeExact", "(Lp/I;)I"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
298 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
299 |
mv.visitMaxs(0, 0); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
300 |
mv.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
301 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
302 |
// static int test(I,11args) |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
303 |
{ |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
304 |
mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I", null, null); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
305 |
mv.visitCode(); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
306 |
mv.visitLdcInsn(new Handle(Opcodes.H_INVOKEINTERFACE, "p/I", "m", "(BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I")); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
307 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
308 |
mv.visitVarInsn(ILOAD, 1); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
309 |
mv.visitVarInsn(ILOAD, 2); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
310 |
mv.visitVarInsn(ILOAD, 3); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
311 |
mv.visitVarInsn(ILOAD, 4); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
312 |
mv.visitVarInsn(LLOAD, 5); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
313 |
mv.visitVarInsn(ALOAD, 7); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
314 |
mv.visitVarInsn(ALOAD, 8); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
315 |
mv.visitVarInsn(ALOAD, 9); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
316 |
mv.visitVarInsn(ALOAD, 10); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
317 |
mv.visitVarInsn(ALOAD, 11); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
318 |
mv.visitVarInsn(ALOAD, 12); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
319 |
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
320 |
"invokeExact", "(Lp/I;BCSIJLjava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)I"); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
321 |
mv.visitInsn(IRETURN); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
322 |
mv.visitMaxs(0, 0); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
323 |
mv.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
324 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
325 |
cw.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
326 |
return cw.toByteArray(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
327 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
328 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
329 |
private static void tryAndCheckThrown( |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
330 |
List<Throwable> lt, byte[] dBytes, String what, Class<?> expected, String jar_name) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
331 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
332 |
tryAndCheckThrown(lt, "p.D", dBytes, what, expected, jar_name); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
333 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
334 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
335 |
private static void tryAndCheckThrown(List<Throwable> lt, String d_name, byte[] dBytes, String what, Class<?> expected, String jar_name) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
336 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
337 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
338 |
System.out.println("Methodhandle invokeExact I.m() for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
339 |
ByteClassLoader bcl1 = new ByteClassLoader(jar_name, readJarFiles, writeJarFiles); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
340 |
try { |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
341 |
Class<?> d1 = bcl1.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
342 |
Class<?> t1 = bcl1.loadBytes("p.T", bytesForT()); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
343 |
invokeTest(t1, d1, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
344 |
} finally { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
345 |
// Not necessary for others -- all class files are written in this call. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
346 |
// (unless the VM crashes first). |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
347 |
bcl1.close(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
348 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
349 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
350 |
System.out.println("Reflection invoke I.m() for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
351 |
ByteClassLoader bcl3 = new ByteClassLoader(jar_name, readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
352 |
Class<?> d3 = bcl3.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
353 |
Class<?> t3 = bcl3.loadClass("p.Treflect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
354 |
invokeTest(t3, d3, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
355 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
356 |
System.out.println("Bytecode invokeInterface I.m() for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
357 |
ByteClassLoader bcl2 = new ByteClassLoader(jar_name, readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
358 |
Class<?> d2 = bcl2.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
359 |
Class<?> t2 = bcl2.loadClass("p.Tdirect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
360 |
badGoodBadGood(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
361 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
362 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
363 |
private static void invokeTest(Class<?> t, Class<?> d, Class<?> expected, List<Throwable> lt) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
364 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
365 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
366 |
Method m = t.getMethod("test", p.I.class); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
367 |
Object o = d.newInstance(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
368 |
Object result = m.invoke(null, o); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
369 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
370 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
371 |
+ " wrapped in InvocationTargetException, but nothing was thrown"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
372 |
lt.add(new Error("Exception " + expected.getName() + " was not thrown")); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
373 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
374 |
System.out.println("PASS, saw expected return."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
375 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
376 |
} catch (InvocationTargetException e) { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
377 |
Throwable th = e.getCause(); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
378 |
th.printStackTrace(System.out); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
379 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
380 |
if (expected.isInstance(th)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
381 |
System.out.println("PASS, saw expected exception (" + expected.getName() + ")."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
382 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
383 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
384 |
+ " wrapped in InvocationTargetException, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
385 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
386 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
387 |
} else { |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
388 |
System.out.println("FAIL, expected no exception, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
389 |
lt.add(th); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
390 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
391 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
392 |
System.out.println(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
393 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
394 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
395 |
/* Many-arg versions of above */ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
396 |
private static void tryAndCheckThrownMany(List<Throwable> lt, byte[] dBytes, String what, Class<?> expected) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
397 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
398 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
399 |
System.out.println("Methodhandle invokeExact I.m(11params) for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
400 |
ByteClassLoader bcl1 = new ByteClassLoader("p.D", readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
401 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
402 |
Class<?> d1 = bcl1.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
403 |
Class<?> t1 = bcl1.loadBytes("p.T", bytesForT()); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
404 |
invokeTestMany(t1, d1, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
405 |
} finally { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
406 |
bcl1.close(); // Not necessary for others -- all class files are written in this call. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
407 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
408 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
409 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
410 |
System.out.println("Bytecode invokeInterface I.m(11params) for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
411 |
ByteClassLoader bcl2 = new ByteClassLoader("pD_m_pri_imp_pI", readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
412 |
Class<?> d2 = bcl2.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
413 |
Class<?> t2 = bcl2.loadClass("p.Tdirect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
414 |
badGoodBadGoodMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
415 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
416 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
417 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
418 |
System.out.println("Reflection invokeInterface I.m(11params) for instance of " + what); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
419 |
ByteClassLoader bcl2 = new ByteClassLoader("pD_m_pri_imp_pI", readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
420 |
Class<?> d2 = bcl2.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
421 |
Class<?> t2 = bcl2.loadClass("p.Treflect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
422 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
423 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
424 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
425 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
426 |
private static void invokeTestMany(Class<?> t, Class<?> d, Class<?> expected, List<Throwable> lt) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
427 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
428 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
429 |
Method m = t.getMethod("test", p.I.class, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
430 |
Byte.TYPE, Character.TYPE, Short.TYPE, Integer.TYPE, Long.TYPE, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
431 |
Object.class, Object.class, Object.class, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
432 |
Object.class, Object.class, Object.class); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
433 |
Object o = d.newInstance(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
434 |
Byte b = 1; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
435 |
Character c = 2; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
436 |
Short s = 3; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
437 |
Integer i = 4; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
438 |
Long j = 5L; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
439 |
Object o1 = b; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
440 |
Object o2 = c; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
441 |
Object o3 = s; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
442 |
Object o4 = i; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
443 |
Object o5 = j; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
444 |
Object o6 = "6"; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
445 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
446 |
Object result = m.invoke(null, o, b, c, s, i, j, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
447 |
o1, o2, o3, o4, o5, o6); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
448 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
449 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
450 |
+ " wrapped in InvocationTargetException, but nothing was thrown"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
451 |
lt.add(new Error("Exception " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
452 |
+ " was not thrown")); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
453 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
454 |
System.out.println("PASS, saw expected return."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
455 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
456 |
} catch (InvocationTargetException e) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
457 |
Throwable th = e.getCause(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
458 |
th.printStackTrace(System.out); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
459 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
460 |
if (expected.isInstance(th)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
461 |
System.out.println("PASS, saw expected exception (" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
462 |
+ expected.getName() + ")."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
463 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
464 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
465 |
+ " wrapped in InvocationTargetException, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
466 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
467 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
468 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
469 |
System.out.println("FAIL, expected no exception, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
470 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
471 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
472 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
473 |
System.out.println(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
474 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
475 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
476 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
477 |
* This tests a peculiar idiom for tickling the bug on older VMs that lack |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
478 |
* methodhandles. The bug (if not fixed) acts in the following way: |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
479 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
480 |
* When a broken receiver is passed to the first execution of an invokeinterface |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
481 |
* bytecode, the illegal access is detected before the effects of resolution are |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
482 |
* cached for later use, and so repeated calls with a broken receiver will always |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
483 |
* throw the correct error. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
484 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
485 |
* If, however, a good receiver is passed to the invokeinterface, the effects of |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
486 |
* resolution will be successfully cached. A subsequent execution with a broken |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
487 |
* receiver will reuse the cached information, skip the detailed resolution work, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
488 |
* and instead encounter a null pointer. By convention, that is the encoding for a |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
489 |
* missing abstract method, and an AbstractMethodError is thrown -- not the expected |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
490 |
* IllegalAccessError. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
491 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
492 |
* @param t2 Test invocation class |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
493 |
* @param d2 Test receiver class |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
494 |
* @param expected expected exception type |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
495 |
* @param lt list of unexpected throwables seen |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
496 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
497 |
private static void badGoodBadGood(Class<?> t2, Class<?> d2, Class<?> expected, List<Throwable> lt) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
498 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
499 |
System.out.println(" Error input 1st time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
500 |
invokeTest(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
501 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
502 |
invokeTest(t2, Dok.class, null, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
503 |
System.out.println(" Error input 2nd time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
504 |
invokeTest(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
505 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
506 |
invokeTest(t2, Dok.class, null, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
507 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
508 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
509 |
private static void badGoodBadGoodMany(Class<?> t2, Class<?> d2, Class<?> expected, List<Throwable> lt) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
510 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
511 |
System.out.println(" Error input 1st time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
512 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
513 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
514 |
invokeTestMany(t2, Dok.class, null, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
515 |
System.out.println(" Error input 2nd time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
516 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
517 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
518 |
invokeTestMany(t2, Dok.class, null, lt); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
519 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
520 |
} |