1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 /* 25 * @test 26 * @bug 8186092 27 * @compile ../common/Foo.java 28 * ../common/J.java 29 * I.java 30 * ../common/C.jasm 31 * Task.java 32 * ../common/PreemptingClassLoader.java 33 * @run main/othervm Test 34 */ 35 36 import java.io.PrintStream; 37 import java.lang.reflect.*; 38 39 public class Test { 40 41 // Test that LinkageError exceptions are not thrown during vtable creation, 42 // for loader constraint errors, if the target method is an overpass method. 43 // 44 // In this test, during vtable creation for class Task, the target method 45 // "Task.m()LFoo;" is an overpass method (that throws an AME). So, even 46 // though it is inheriting the method from its super class C, and Task has 47 // a different class Foo than C, no LinkageError exception should be thrown 48 // because the loader constraint check that would cause the LinkageError 49 // should not be done. 50 public static void main(String args[]) throws Exception { 51 Class<?> c = Foo.class; // forces standard class loader to load Foo 52 ClassLoader l = new PreemptingClassLoader("Task", "Foo", "I", "J"); 53 l.loadClass("Foo"); 54 l.loadClass("Task").newInstance(); 55 Task t = new Task(); 56 try { 57 t.m(); // Should get AME 58 throw new RuntimeException("Missing AbstractMethodError exception"); 59 } catch (AbstractMethodError e) { 60 if (!e.getMessage().contains("Method Task.m()LFoo; is abstract")) { 61 throw new RuntimeException("Wrong AME exception thrown: " + e.getMessage()); 62 } 63 } 64 } 65 66 }