Path: blob/master/test/jdk/java/lang/invoke/8147078/Test8147078.java
41153 views
/*1* Copyright (c) 2016, 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. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/* @test26* @bug 814707827* @run testng/othervm -ea -esa Test814707828*/2930import org.testng.annotations.Test;3132import java.lang.invoke.MethodHandle;33import java.lang.invoke.MethodHandles;3435import static java.lang.invoke.MethodType.methodType;3637import static org.testng.AssertJUnit.*;3839public class Test8147078 {4041static int target(int x) {42throw new RuntimeException("ieps");43}4445static int handler(String s, int x) {46return 4*x;47}4849static final MethodHandle MH_target;50static final MethodHandle MH_handler;51static final MethodHandle MH_catchException;5253static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();5455static {56try {57Class<Test8147078> C = Test8147078.class;58MH_target = LOOKUP.findStatic(C, "target", methodType(int.class, int.class));59MH_handler = LOOKUP.findStatic(C, "handler", methodType(int.class, String.class, int.class));60MH_catchException = LOOKUP.findStatic(MethodHandles.class, "catchException",61methodType(MethodHandle.class, MethodHandle.class, Class.class, MethodHandle.class));62} catch (Exception e) {63throw new ExceptionInInitializerError(e);64}65}6667@Test68public void testNoExceptionType() {69boolean caught = false;70try {71MethodHandle eek = (MethodHandle) MH_catchException.invoke(MH_target, String.class, MH_handler);72} catch (ClassCastException cce) {73assertEquals("java.lang.String", cce.getMessage());74caught = true;75} catch (Throwable t) {76fail("unexpected exception caught: " + t);77}78assertTrue(caught);79}8081}8283