Mon, 19 Jun 2017 14:51:25 -0700
Added tag jdk8u151-b02 for changeset 732e1bab2660
rfield@2590 | 1 | /* |
rfield@2590 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
rfield@2590 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
rfield@2590 | 4 | * |
rfield@2590 | 5 | * This code is free software; you can redistribute it and/or modify it |
rfield@2590 | 6 | * under the terms of the GNU General Public License version 2 only, as |
rfield@2590 | 7 | * published by the Free Software Foundation. |
rfield@2590 | 8 | * |
rfield@2590 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
rfield@2590 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
rfield@2590 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
rfield@2590 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
rfield@2590 | 13 | * accompanied this code). |
rfield@2590 | 14 | * |
rfield@2590 | 15 | * You should have received a copy of the GNU General Public License version |
rfield@2590 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
rfield@2590 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
rfield@2590 | 18 | * |
rfield@2590 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
rfield@2590 | 20 | * or visit www.oracle.com if you need additional information or have any |
rfield@2590 | 21 | * questions. |
rfield@2590 | 22 | */ |
rfield@2590 | 23 | |
rfield@2590 | 24 | /* |
rfield@2590 | 25 | * @test |
rfield@2590 | 26 | * @bug 8056051 |
rfield@2590 | 27 | * @summary int[]::clone causes "java.lang.NoClassDefFoundError: Array" |
rfield@2590 | 28 | * @run main MethodReferenceArrayClone |
rfield@2590 | 29 | */ |
rfield@2590 | 30 | |
rfield@2590 | 31 | import java.util.Arrays; |
rfield@2590 | 32 | import java.util.function.Function; |
rfield@2590 | 33 | import java.util.function.Supplier; |
rfield@2590 | 34 | |
rfield@2590 | 35 | public class MethodReferenceArrayClone { |
rfield@2590 | 36 | public static void main(String[] args) { |
rfield@2590 | 37 | int[] intArgs = new int[] {1, 2, 3, 4, 5}; |
rfield@2590 | 38 | checkInt("int[]::clone", int[]::clone, intArgs); |
rfield@2590 | 39 | checkInt("a -> a.clone()", a -> a.clone(), intArgs); |
rfield@2590 | 40 | checkInt("intArgs::clone", intArgs::clone, intArgs); |
rfield@2590 | 41 | |
rfield@2590 | 42 | String[] stringArgs = new String[] {"hi", "de", "ho"}; |
rfield@2590 | 43 | checkString("String[]::clone", String[]::clone, stringArgs); |
rfield@2590 | 44 | checkString("a -> a.clone()", a -> a.clone(), stringArgs); |
rfield@2590 | 45 | checkString("args::clone", stringArgs::clone, stringArgs); |
rfield@2590 | 46 | } |
rfield@2590 | 47 | |
rfield@2590 | 48 | private static void checkInt(String label, Supplier<int[]> s, int[] expected) { |
rfield@2590 | 49 | if (!Arrays.equals(s.get(), expected)) { |
rfield@2590 | 50 | throw new RuntimeException("Unexpected value " + label + ": " + Arrays.toString(s.get())); |
rfield@2590 | 51 | } |
rfield@2590 | 52 | } |
rfield@2590 | 53 | |
rfield@2590 | 54 | private static void checkInt(String label, Function<int[], int[]> f, int[] a) { |
rfield@2590 | 55 | checkInt(label, () -> f.apply(a), a); |
rfield@2590 | 56 | } |
rfield@2590 | 57 | |
rfield@2590 | 58 | private static void checkString(String label, Supplier<String[]> s, String[] expected) { |
rfield@2590 | 59 | if (!Arrays.equals(s.get(), expected)) { |
rfield@2590 | 60 | throw new RuntimeException("Unexpected value " + label + ": " + Arrays.toString(s.get())); |
rfield@2590 | 61 | } |
rfield@2590 | 62 | } |
rfield@2590 | 63 | |
rfield@2590 | 64 | private static void checkString(String label, Function<String[], String[]> f, String[] a) { |
rfield@2590 | 65 | checkString(label, () -> f.apply(a), a); |
rfield@2590 | 66 | } |
rfield@2590 | 67 | } |