Path: blob/master/test/hotspot/jtreg/compiler/runtime/SpreadNullArg.java
41149 views
/*1* Copyright (c) 2011 SAP SE. 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* @test SpreadNullArg25* @bug 714163726* @summary verifies that the MethodHandle spread adapter can gracefully handle null arguments.27*28* @run main compiler.runtime.SpreadNullArg29* @author [email protected]30*/3132package compiler.runtime;3334import java.lang.invoke.MethodHandle;35import java.lang.invoke.MethodHandles;36import java.lang.invoke.MethodType;3738public class SpreadNullArg {3940public static void main(String args[]) {4142MethodType mt_ref_arg = MethodType.methodType(int.class, Integer.class);43MethodHandle mh_spreadInvoker = MethodHandles.spreadInvoker(mt_ref_arg, 0);44MethodHandle mh_spread_target;45int result = 42;4647try {48mh_spread_target =49MethodHandles.lookup().findStatic(SpreadNullArg.class, "target_spread_arg", mt_ref_arg);50result = (int) mh_spreadInvoker.invokeExact(mh_spread_target, (Object[]) null);51throw new Error("Expected NullPointerException was not thrown");52} catch (NullPointerException e) {53System.out.println("Expected exception : " + e);54} catch (Throwable e) {55throw new Error(e);56}5758if (result != 42) {59throw new Error("result [" + result60+ "] != 42 : Expected NullPointerException was not thrown?");61}62}6364public static int target_spread_arg(Integer i1) {65return i1.intValue();66}6768}697071