--- /dev/null 2013-09-06 19:25:58.000000000 -0400 +++ new/test/java/lang/invoke/8022701/MHIllegalAccess.java 2013-09-06 19:25:58.000000000 -0400 @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/** + * @test + * @bug 8022701 + * @summary Illegal access exceptions via methodhandle invocations threw wrong error. + * + * @compile BogoLoader.java InvokeSeveralWays.java MHIllegalAccess.java MethodSupplier.java + * @run main/othervm MHIllegalAccess + */ + + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.HashSet; + +public class MHIllegalAccess { + /* + * See MethodSupplier.java to see how to produce these bytes. + * They encode that class, except that method m is private, not public. + */ + static byte[] bogusMethodSupplier = { + -54, -2, -70, -66, 0, 0, 0, 52, 0, 28, 10, 0, 6, 0, 14, 9, + 0, 15, 0, 16, 8, 0, 17, 10, 0, 18, 0, 19, 7, 0, 20, 7, + 0, 21, 1, 0, 6, 60, 105, 110, 105, 116, 62, 1, 0, 3, 40, 41, + 86, 1, 0, 4, 67, 111, 100, 101, 1, 0, 15, 76, 105, 110, 101, 78, + 117, 109, 98, 101, 114, 84, 97, 98, 108, 101, 1, 0, 1, 109, 1, 0, + 10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1, 0, 19, 77, 101, + 116, 104, 111, 100, 83, 117, 112, 112, 108, 105, 101, 114, 46, 106, 97, 118, + 97, 12, 0, 7, 0, 8, 7, 0, 22, 12, 0, 23, 0, 24, 1, 0, + 4, 103, 111, 111, 100, 7, 0, 25, 12, 0, 26, 0, 27, 1, 0, 14, + 77, 101, 116, 104, 111, 100, 83, 117, 112, 112, 108, 105, 101, 114, 1, 0, + 16, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 79, 98, 106, 101, 99, + 116, 1, 0, 16, 106, 97, 118, 97, 47, 108, 97, 110, 103, 47, 83, 121, + 115, 116, 101, 109, 1, 0, 3, 111, 117, 116, 1, 0, 21, 76, 106, 97, + 118, 97, 47, 105, 111, 47, 80, 114, 105, 110, 116, 83, 116, 114, 101, 97, + 109, 59, 1, 0, 19, 106, 97, 118, 97, 47, 105, 111, 47, 80, 114, 105, + 110, 116, 83, 116, 114, 101, 97, 109, 1, 0, 7, 112, 114, 105, 110, 116, + 108, 110, 1, 0, 21, 40, 76, 106, 97, 118, 97, 47, 108, 97, 110, 103, + 47, 83, 116, 114, 105, 110, 103, 59, 41, 86, 0, 33, 0, 5, 0, 6, + 0, 0, 0, 0, 0, 2, 0, 1, 0, 7, 0, 8, 0, 1, 0, 9, + 0, 0, 0, 29, 0, 1, 0, 1, 0, 0, 0, 5, 42, -73, 0, 1, + -79, 0, 0, 0, 1, 0, 10, 0, 0, 0, 6, 0, 1, 0, 0, 0, + 1, 0, 2, 0, 11, 0, 8, 0, 1, 0, 9, 0, 0, 0, 37, 0, + 2, 0, 1, 0, 0, 0, 9, -78, 0, 2, 18, 3, -74, 0, 4, -79, + 0, 0, 0, 1, 0, 10, 0, 0, 0, 10, 0, 2, 0, 0, 0, 3, + 0, 8, 0, 4, 0, 1, 0, 12, 0, 0, 0, 2, 0, 13,}; + + public static void main(String args[]) throws Throwable { + HashMap replace = new HashMap(); + replace.put("MethodSupplier", bogusMethodSupplier); + HashSet in_bogus = new HashSet(); + in_bogus.add("InvokeSeveralWays"); + in_bogus.add("MyFunctionalInterface"); + in_bogus.add("MethodInvoker"); + BogoLoader bl = new BogoLoader(in_bogus, replace); + Class isw = bl.loadClass("InvokeSeveralWays"); + Object[] arg_for_args = new Object[1]; + arg_for_args[0] = args; + try { + isw.getMethod("main", String[].class).invoke(null, arg_for_args); + } catch (InvocationTargetException e) { + Throwable th = e.getCause(); + throw th == null ? e : th; + } + } +}