author | dcubed |
Tue, 05 Jul 2016 14:00:21 -0700 | |
changeset 39696 | 80c9894e18f9 |
parent 29678 | dd2f3932c21e |
child 40059 | c2304140ed64 |
permissions | -rw-r--r-- |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
1 |
/* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
21770
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, 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 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
23 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
24 |
import java.lang.reflect.InvocationTargetException; |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
25 |
import java.lang.reflect.Method; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
26 |
import java.util.ArrayList; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
27 |
import java.util.List; |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
28 |
import jdk.internal.org.objectweb.asm.ClassWriter; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
29 |
import jdk.internal.org.objectweb.asm.Handle; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
30 |
import jdk.internal.org.objectweb.asm.MethodVisitor; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
31 |
import jdk.internal.org.objectweb.asm.Opcodes; |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
32 |
import p.Dok; |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
33 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
34 |
/** |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
35 |
* @test @bug 8025260 8016839 |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
36 |
* @summary Ensure that AbstractMethodError and IllegalAccessError are thrown appropriately, not NullPointerException |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
37 |
* |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
21770
diff
changeset
|
38 |
* @modules java.base/jdk.internal.org.objectweb.asm |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
39 |
* @compile -XDignore.symbol.file TestAMEnotNPE.java ByteClassLoader.java p/C.java p/Dok.java p/E.java p/F.java p/I.java p/Tdirect.java p/Treflect.java |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
40 |
* |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
41 |
* @run main/othervm TestAMEnotNPE |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
42 |
* @run main/othervm -Xint TestAMEnotNPE |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
43 |
* @run main/othervm -Xcomp TestAMEnotNPE |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
44 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
45 |
public class TestAMEnotNPE implements Opcodes { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
46 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
47 |
static boolean writeJarFiles = false; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
48 |
static boolean readJarFiles = false; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
49 |
|
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
50 |
/** |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
51 |
* 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
|
52 |
* "writejarfiles" or "readjarfiles". |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
53 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
54 |
* "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
|
55 |
* "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
|
56 |
* found in the corresponding jar files. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
57 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
58 |
* 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
|
59 |
* 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
|
60 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
61 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
62 |
public static void main(String args[]) throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
63 |
ArrayList<Throwable> lt = new ArrayList<Throwable>(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
64 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
65 |
if (args.length > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
66 |
String a0 = args[0].toLowerCase(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
67 |
if (a0.length() > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
68 |
writeJarFiles = ("writejarfiles").startsWith(a0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
69 |
readJarFiles = ("readjarfiles").startsWith(a0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
70 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
71 |
if (!(writeJarFiles || readJarFiles)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
72 |
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
|
73 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
74 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
75 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
76 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
77 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.F, p.F.m FINAL"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
78 |
tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/F"), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
79 |
"p.D extends p.F (p.F implements p.I, FINAL public m), private m", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
80 |
IllegalAccessError.class, "pD_ext_pF"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
81 |
// We'll take either a VerifyError (pre 2013-11-30) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
82 |
// or an IllegalAccessError (post 2013-11-22) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
83 |
} catch (VerifyError ve) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
84 |
System.out.println("Saw expected VerifyError " + ve); |
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 |
System.out.println(); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
87 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
88 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m, p.D extends p.E"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
89 |
tryAndCheckThrown(lt, bytesForDprivateSubWhat("p/E"), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
90 |
"p.D extends p.E (p.E implements p.I, public m), private m", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
91 |
IllegalAccessError.class, "pD_ext_pE"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
92 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
93 |
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
|
94 |
tryAndCheckThrown(lt, bytesForD(), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
95 |
"D extends abstract C, no m", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
96 |
AbstractMethodError.class, "pD_ext_pC"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
97 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
98 |
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
|
99 |
tryAndCheckThrown(lt, "q.D", bytesForDsomeAccess("q/D", 0), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
100 |
"q.D implements p.I, protected m", IllegalAccessError.class, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
101 |
"qD_m_pp_imp_pI"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
102 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
103 |
// 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
|
104 |
System.out.println("TRYING p.D.m PRIVATE interface-invoked as p.I.m"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
105 |
tryAndCheckThrown(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
106 |
"p.D implements p.I, private m", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
107 |
IllegalAccessError.class, "pD_m_pri_imp_pI"); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
108 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
109 |
// Plural-arg test. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
110 |
System.out.println("TRYING p.D.m PRIVATE MANY ARG interface-invoked as p.I.m"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
111 |
tryAndCheckThrownMany(lt, bytesForDsomeAccess("p/D", ACC_PRIVATE), |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
112 |
"p.D implements p.I, private m", IllegalAccessError.class); |
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 |
if (lt.size() > 0) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
115 |
System.out.flush(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
116 |
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
|
117 |
for (Throwable th : lt) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
118 |
System.err.println(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
119 |
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
|
120 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
121 |
System.out.println("ALL PASS, HOORAY!"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
122 |
} |
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 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
125 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
126 |
* 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
|
127 |
* 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
|
128 |
* 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
|
129 |
* |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
130 |
* @return |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
131 |
* @throws Exception |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
132 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
133 |
public static byte[] bytesForD() throws Exception { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
134 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
135 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
136 |
| ClassWriter.COMPUTE_MAXS); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
137 |
MethodVisitor mv; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
138 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
139 |
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
|
140 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
141 |
{ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
142 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
143 |
mv.visitCode(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
144 |
mv.visitVarInsn(ALOAD, 0); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
145 |
mv.visitMethodInsn(INVOKESPECIAL, "p/C", "<init>", "()V"); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
146 |
mv.visitInsn(RETURN); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
147 |
mv.visitMaxs(0, 0); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
148 |
mv.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
149 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
150 |
cw.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
151 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
152 |
return cw.toByteArray(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
153 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
154 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
155 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
156 |
* 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
|
157 |
* access method_acc. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
158 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
159 |
* @param d_name Name of class defined |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
160 |
* @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
|
161 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
162 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
163 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
167 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
168 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
169 |
* 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
|
170 |
* private. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
171 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
172 |
* 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
|
173 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
174 |
* @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
|
175 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
176 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
177 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
178 |
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
|
179 |
return bytesForSomeDsubSomethingSomeAccess("p/D", sub_what, ACC_PRIVATE); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
180 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
181 |
|
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
182 |
/** |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
183 |
* 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
|
184 |
* 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
|
185 |
* 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
|
186 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
187 |
* @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
|
188 |
* @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
|
189 |
* @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
|
190 |
* @return |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
191 |
* @throws Exception |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
192 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
193 |
public static byte[] bytesForSomeDsubSomethingSomeAccess |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
194 |
(String d_name, String sub_what, int method_acc) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
195 |
throws Exception { |
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 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
198 |
| ClassWriter.COMPUTE_MAXS); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
199 |
MethodVisitor mv; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
200 |
String[] interfaces = {"p/I"}; |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
201 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
202 |
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
|
203 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
204 |
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
|
205 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
206 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
207 |
mv.visitMethodInsn(INVOKESPECIAL, sub_what, "<init>", "()V"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
208 |
mv.visitInsn(RETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
209 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
210 |
mv.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
211 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
212 |
// int m() {return 3;} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
213 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
214 |
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
|
215 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
216 |
mv.visitLdcInsn(new Integer(3)); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
217 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
218 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
219 |
mv.visitEnd(); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
220 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
221 |
// int m(11args) {return 3;} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
222 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
223 |
mv = cw.visitMethod(method_acc, "m", "(BCSIJ" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
224 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
225 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
226 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
227 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
228 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
229 |
+ "Ljava/lang/Object;" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
230 |
+ ")I", null, null); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
231 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
232 |
mv.visitLdcInsn(new Integer(3)); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
233 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
234 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
235 |
mv.visitEnd(); |
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 |
cw.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
238 |
return cw.toByteArray(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
239 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
240 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
241 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
242 |
* 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
|
243 |
* 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
|
244 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
245 |
* 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
|
246 |
* and thus may in turn throw exceptions. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
247 |
* |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
248 |
* @return |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
249 |
* @throws Exception |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
250 |
*/ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
251 |
public static byte[] bytesForT() throws Exception { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
252 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
253 |
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
254 |
| ClassWriter.COMPUTE_MAXS); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
255 |
MethodVisitor mv; |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
256 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
257 |
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
|
258 |
{ |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
259 |
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
260 |
mv.visitCode(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
261 |
mv.visitVarInsn(ALOAD, 0); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
262 |
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
263 |
mv.visitInsn(RETURN); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
264 |
mv.visitMaxs(0, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
265 |
mv.visitEnd(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
266 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
267 |
// static int test(I) |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
268 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
269 |
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
|
270 |
mv.visitCode(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
271 |
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
|
272 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
273 |
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/invoke/MethodHandle", |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
274 |
"invokeExact", "(Lp/I;)I"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
275 |
mv.visitInsn(IRETURN); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
276 |
mv.visitMaxs(0, 0); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
277 |
mv.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
278 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
279 |
// static int test(I,11args) |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
280 |
{ |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
281 |
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
|
282 |
mv.visitCode(); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
283 |
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
|
284 |
mv.visitVarInsn(ALOAD, 0); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
285 |
mv.visitVarInsn(ILOAD, 1); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
286 |
mv.visitVarInsn(ILOAD, 2); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
287 |
mv.visitVarInsn(ILOAD, 3); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
288 |
mv.visitVarInsn(ILOAD, 4); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
289 |
mv.visitVarInsn(LLOAD, 5); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
290 |
mv.visitVarInsn(ALOAD, 7); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
291 |
mv.visitVarInsn(ALOAD, 8); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
292 |
mv.visitVarInsn(ALOAD, 9); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
293 |
mv.visitVarInsn(ALOAD, 10); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
294 |
mv.visitVarInsn(ALOAD, 11); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
295 |
mv.visitVarInsn(ALOAD, 12); |
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;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
|
298 |
mv.visitInsn(IRETURN); |
21770
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 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
302 |
cw.visitEnd(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
303 |
return cw.toByteArray(); |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
304 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
305 |
|
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
306 |
private static void tryAndCheckThrown( |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
307 |
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
|
308 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
309 |
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
|
310 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
311 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
312 |
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
|
313 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
314 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
315 |
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
|
316 |
ByteClassLoader bcl1 = new ByteClassLoader(jar_name, readJarFiles, writeJarFiles); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
317 |
try { |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
318 |
Class<?> d1 = bcl1.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
319 |
Class<?> t1 = bcl1.loadBytes("p.T", bytesForT()); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
320 |
invokeTest(t1, d1, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
321 |
} finally { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
322 |
// 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
|
323 |
// (unless the VM crashes first). |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
324 |
bcl1.close(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
325 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
326 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
327 |
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
|
328 |
ByteClassLoader bcl3 = new ByteClassLoader(jar_name, readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
329 |
Class<?> d3 = bcl3.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
330 |
Class<?> t3 = bcl3.loadClass("p.Treflect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
331 |
invokeTest(t3, d3, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
332 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
333 |
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
|
334 |
ByteClassLoader bcl2 = new ByteClassLoader(jar_name, readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
335 |
Class<?> d2 = bcl2.loadBytes(d_name, dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
336 |
Class<?> t2 = bcl2.loadClass("p.Tdirect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
337 |
badGoodBadGood(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
338 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
339 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
340 |
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
|
341 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
342 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
343 |
Method m = t.getMethod("test", p.I.class); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
344 |
Object o = d.newInstance(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
345 |
Object result = m.invoke(null, o); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
346 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
347 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
348 |
+ " wrapped in InvocationTargetException, but nothing was thrown"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
349 |
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
|
350 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
351 |
System.out.println("PASS, saw expected return."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
352 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
353 |
} catch (InvocationTargetException e) { |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
354 |
Throwable th = e.getCause(); |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
355 |
th.printStackTrace(System.out); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
356 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
357 |
if (expected.isInstance(th)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
358 |
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
|
359 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
360 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
361 |
+ " wrapped in InvocationTargetException, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
362 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
363 |
} |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
364 |
} else { |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
365 |
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
|
366 |
lt.add(th); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
367 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
368 |
} |
21770
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
369 |
System.out.println(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
370 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
371 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
372 |
/* Many-arg versions of above */ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
373 |
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
|
374 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
375 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
376 |
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
|
377 |
ByteClassLoader bcl1 = new ByteClassLoader("p.D", readJarFiles, false); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
378 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
379 |
Class<?> d1 = bcl1.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
380 |
Class<?> t1 = bcl1.loadBytes("p.T", bytesForT()); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
381 |
invokeTestMany(t1, d1, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
382 |
} finally { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
383 |
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
|
384 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
385 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
386 |
{ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
387 |
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
|
388 |
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
|
389 |
Class<?> d2 = bcl2.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
390 |
Class<?> t2 = bcl2.loadClass("p.Tdirect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
391 |
badGoodBadGoodMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
392 |
|
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 |
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
|
396 |
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
|
397 |
Class<?> d2 = bcl2.loadBytes("p.D", dBytes); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
398 |
Class<?> t2 = bcl2.loadClass("p.Treflect"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
399 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
400 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
401 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
402 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
403 |
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
|
404 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
405 |
try { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
406 |
Method m = t.getMethod("test", p.I.class, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
407 |
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
|
408 |
Object.class, Object.class, Object.class, |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
409 |
Object.class, Object.class, Object.class); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
410 |
Object o = d.newInstance(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
411 |
Byte b = 1; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
412 |
Character c = 2; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
413 |
Short s = 3; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
414 |
Integer i = 4; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
415 |
Long j = 5L; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
416 |
Object o1 = b; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
417 |
Object o2 = c; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
418 |
Object o3 = s; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
419 |
Object o4 = i; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
420 |
Object o5 = j; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
421 |
Object o6 = "6"; |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
422 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
423 |
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
|
424 |
o1, o2, o3, o4, o5, o6); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
425 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
426 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
427 |
+ " wrapped in InvocationTargetException, but nothing was thrown"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
428 |
lt.add(new Error("Exception " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
429 |
+ " was not thrown")); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
430 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
431 |
System.out.println("PASS, saw expected return."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
432 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
433 |
} catch (InvocationTargetException e) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
434 |
Throwable th = e.getCause(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
435 |
th.printStackTrace(System.out); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
436 |
if (expected != null) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
437 |
if (expected.isInstance(th)) { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
438 |
System.out.println("PASS, saw expected exception (" |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
439 |
+ expected.getName() + ")."); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
440 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
441 |
System.out.println("FAIL, Expected " + expected.getName() |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
442 |
+ " wrapped in InvocationTargetException, saw " + th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
443 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
444 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
445 |
} else { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
446 |
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
|
447 |
lt.add(th); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
448 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
449 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
450 |
System.out.println(); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
451 |
} |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
452 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
453 |
/** |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
454 |
* 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
|
455 |
* 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
|
456 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
457 |
* 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
|
458 |
* 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
|
459 |
* 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
|
460 |
* throw the correct error. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
461 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
462 |
* 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
|
463 |
* 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
|
464 |
* 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
|
465 |
* 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
|
466 |
* 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
|
467 |
* IllegalAccessError. |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
468 |
* |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
469 |
* @param t2 Test invocation class |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
470 |
* @param d2 Test receiver class |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
471 |
* @param expected expected exception type |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
472 |
* @param lt list of unexpected throwables seen |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
473 |
*/ |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
474 |
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
|
475 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
476 |
System.out.println(" Error input 1st time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
477 |
invokeTest(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
478 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
479 |
invokeTest(t2, Dok.class, null, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
480 |
System.out.println(" Error input 2nd time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
481 |
invokeTest(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
482 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
483 |
invokeTest(t2, Dok.class, null, lt); |
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 |
|
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
486 |
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
|
487 |
throws Throwable { |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
488 |
System.out.println(" Error input 1st time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
489 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
490 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
491 |
invokeTestMany(t2, Dok.class, null, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
492 |
System.out.println(" Error input 2nd time"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
493 |
invokeTestMany(t2, d2, expected, lt); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
494 |
System.out.println(" Good input (instance of Dok)"); |
e8932d2fda2c
8016839: JSR292: AME instead of IAE when calling a method
drchase
parents:
20298
diff
changeset
|
495 |
invokeTestMany(t2, Dok.class, null, lt); |
20298
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
496 |
} |
861da81238ee
8025260: Methodhandles/JSR292: NullPointerException (NPE) thrown instead of AbstractMethodError (AME)
drchase
parents:
diff
changeset
|
497 |
} |