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