test/langtools/tools/javac/lambda/methodReference/ProtectedInaccessibleMethodRefTest2.java
changeset 59265 d9a3bddcffcc
equal deleted inserted replaced
59264:981a55672786 59265:d9a3bddcffcc
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8234729
       
    27  * @summary Javac should eagerly change code generation for method references to avert IllegalAccessError in future.
       
    28  * @run main ProtectedInaccessibleMethodRefTest2
       
    29  */
       
    30 
       
    31 import pack.I;
       
    32 import pack.J;
       
    33 
       
    34 import java.nio.file.Path;
       
    35 import java.nio.file.Paths;
       
    36 import java.util.function.Function;
       
    37 import java.lang.reflect.Method;
       
    38 import java.util.concurrent.Callable;
       
    39 
       
    40 public final class ProtectedInaccessibleMethodRefTest2 extends I {
       
    41 
       
    42     public static void main(String... args) {
       
    43         ProtectedInaccessibleMethodRefTest2 m = new ProtectedInaccessibleMethodRefTest2();
       
    44         m.test(Paths.get("test"));
       
    45         // Verify that the method reference has been folded into a lambda.
       
    46         boolean lambdaFound = false;
       
    47         for (Method meth : ProtectedInaccessibleMethodRefTest2.class.getDeclaredMethods()) {
       
    48             if (meth.getName().equals("lambda$test$0")) {
       
    49                 lambdaFound = true;
       
    50                 break;
       
    51             }
       
    52         }
       
    53         if (!lambdaFound) {
       
    54             throw new AssertionError("Did not find evidence of new code generation");
       
    55         }
       
    56     }
       
    57 
       
    58     void test(Path outputDir) {
       
    59         Sub c = new Sub(this::readFile);
       
    60         c.check(outputDir);
       
    61     }
       
    62     public class Sub extends J {
       
    63         Sub(Function<Path,String> fileReader) {
       
    64             super(fileReader);
       
    65         }
       
    66     }
       
    67 }