Path: blob/master/test/jdk/java/lang/invoke/FinalVirtualCallFromInterface.java
41149 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 8200167 801031926* @summary Regression test for a bug introduced in 8200167 and fixed in 801031927* @run main FinalVirtualCallFromInterface28*/2930import java.lang.invoke.*;3132/*33* Test that a MethodHandle for a final method, called from an interface, works correctly.34* With only 8200167 applied this fails with:35* Exception in thread "main" java.lang.InternalError: Should only be invoked on a subclass36* at37* java.base/java.lang.invoke.DirectMethodHandle.checkReceiver(DirectMethodHandle.java:441)38*39* The nestmate update under 8010319 fixes that bug.40*/41public class FinalVirtualCallFromInterface {4243static class Final {44public final void fm() {}45}4647static interface FinalUser {48static void test() throws Throwable {49MethodType mt = MethodType.methodType(void.class);50MethodHandle mh = MethodHandles.lookup().findVirtual(Final.class, "fm", mt);51Final f = new Final();52mh.invokeExact(f);53mh.invoke(f);54}55}5657public static void main(String[] args) throws Throwable {58FinalUser.test();59}60}616263