Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8056051

int[]::clone causes "java.lang.NoClassDefFoundError: Array"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u40
    • Fix Version/s: 8u40
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b12
    • CPU:
      x86_64
    • OS:
      linux_ubuntu

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_20"
        Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)

        A DESCRIPTION OF THE PROBLEM :
        JLS §15.13 says that `int[]::clone` is a valid method reference expression. However, using it causes a "java.lang.NoClassDefFoundError: Array" error.

        THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

        THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run the code listed in "Source code for an executable test case".

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        I expect the `int[]::clone` and `String[]::clone` to behave the same as `a -> a.clone()`. Instead, they throw a `NoClassDefFoundError`.
        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.lang.NoClassDefFoundError: Array
        at ArrayCloneTest.lambda$MR$main$clone$8ed4b78b$1(ArrayCloneTest.java:8)
        at ArrayCloneTest$$Lambda$3/1555009629.apply(Unknown Source)
        at ArrayCloneTest.lambda$printInt$3(ArrayCloneTest.java:31)
        at ArrayCloneTest$$Lambda$4/149928006.get(Unknown Source)
        at ArrayCloneTest.lambda$printInt$2(ArrayCloneTest.java:27)
        at ArrayCloneTest$$Lambda$5/168423058.get(Unknown Source)
        at ArrayCloneTest.print(ArrayCloneTest.java:19)
        at ArrayCloneTest.printInt(ArrayCloneTest.java:27)
        at ArrayCloneTest.printInt(ArrayCloneTest.java:31)
        at ArrayCloneTest.main(ArrayCloneTest.java:8)
        Caused by: java.lang.ClassNotFoundException: Array
        at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 10 more

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.util.Arrays;
        import java.util.function.Function;
        import java.util.function.Supplier;

        public class ArrayCloneTest {
            public static void main(String[] args) {
                int[] intArgs = Arrays.stream(args).mapToInt(Integer::parseInt).toArray();
                printInt("int[]::clone", int[]::clone, intArgs);
                printInt("a -> a.clone()", a -> a.clone(), intArgs);
                printInt("intArgs::clone", intArgs::clone);

                printString("String[]::clone", String[]::clone, args);
                printString("a -> a.clone()", a -> a.clone(), args);
                printString("args::clone", args::clone);
            }

            private static void print(String label, Supplier<?> s) {
                try {
                    System.out.printf("%s => %s%n", label, s.get());
                } catch (Throwable t) {
                    System.err.printf("%s =!> %s%n", label, t);
                    t.printStackTrace();
                }
            }

            private static void printInt(String label, Supplier<int[]> s) {
                print(label, () -> Arrays.toString(s.get()));
            }

            private static void printInt(String label, Function<int[], int[]> f, int[] a) {
                printInt(label, () -> f.apply(a));
            }

            private static void printString(String label, Supplier<String[]> s) {
                print(label, () -> Arrays.toString(s.get()));
            }

            private static void printString(String label, Function<String[], String[]> f, String[] a) {
                printString(label, () -> f.apply(a));
            }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Instead of using `int[]::clone`, use `a -> a.clone()` instead.

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                rfield Robert Field
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: