Tue, 29 Mar 2016 10:48:49 +0000
8143647: Javac compiles method reference that allows results in an IllegalAccessError
Summary: Lambda implementation method synthesized by javac should not mention inaccessible types.
Reviewed-by: mcimadamore
rfield@2614 | 1 | /* |
rfield@2614 | 2 | * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
rfield@2614 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
rfield@2614 | 4 | * |
rfield@2614 | 5 | * This code is free software; you can redistribute it and/or modify it |
rfield@2614 | 6 | * under the terms of the GNU General Public License version 2 only, as |
rfield@2614 | 7 | * published by the Free Software Foundation. Oracle designates this |
rfield@2614 | 8 | * particular file as subject to the "Classpath" exception as provided |
rfield@2614 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
rfield@2614 | 10 | * |
rfield@2614 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
rfield@2614 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
rfield@2614 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
rfield@2614 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
rfield@2614 | 15 | * accompanied this code). |
rfield@2614 | 16 | * |
rfield@2614 | 17 | * You should have received a copy of the GNU General Public License version |
rfield@2614 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
rfield@2614 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
rfield@2614 | 20 | * |
rfield@2614 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
rfield@2614 | 22 | * or visit www.oracle.com if you need additional information or have any |
rfield@2614 | 23 | * questions. |
rfield@2614 | 24 | */ |
rfield@2614 | 25 | |
rfield@2614 | 26 | /** |
rfield@2614 | 27 | * @test |
rfield@2614 | 28 | * @bug 8058112 |
rfield@2614 | 29 | * @summary Invalid BootstrapMethod for constructor/method reference |
rfield@2614 | 30 | */ |
rfield@2614 | 31 | |
rfield@2614 | 32 | import java.util.function.Function; |
rfield@2614 | 33 | |
rfield@2614 | 34 | public class MethodReferenceIntersection2 { |
rfield@2614 | 35 | |
rfield@2614 | 36 | interface B { } |
rfield@2614 | 37 | |
rfield@2614 | 38 | interface A { } |
rfield@2614 | 39 | |
rfield@2614 | 40 | static class C implements A, B { } |
rfield@2614 | 41 | |
rfield@2614 | 42 | static class Info { |
rfield@2614 | 43 | <H extends A & B> Info(H h) { } |
rfield@2614 | 44 | |
rfield@2614 | 45 | static <H extends A & B> Info info(H h) { |
rfield@2614 | 46 | return new Info(h); |
rfield@2614 | 47 | } |
rfield@2614 | 48 | } |
rfield@2614 | 49 | |
rfield@2614 | 50 | public static void main(String[] args) { |
rfield@2614 | 51 | test(); |
rfield@2614 | 52 | } |
rfield@2614 | 53 | |
rfield@2614 | 54 | // Note the switch in order compared to that on Info |
rfield@2614 | 55 | static <H extends B & A> void test() { |
rfield@2614 | 56 | Function<H, Info> f1L = _h -> new Info(_h); |
rfield@2614 | 57 | Function<H, Info> f1 = Info::new; |
rfield@2614 | 58 | Function<H, Info> f2L = _h -> Info.info(_h); |
rfield@2614 | 59 | Function<H, Info> f2 = Info::info; |
rfield@2614 | 60 | H c = (H) new C(); |
rfield@2614 | 61 | if(f1.apply(c) instanceof Info && |
rfield@2614 | 62 | f2.apply(c) instanceof Info) { |
rfield@2614 | 63 | System.out.println("Passes."); |
rfield@2614 | 64 | } else { |
rfield@2614 | 65 | throw new AssertionError(); |
rfield@2614 | 66 | } |
rfield@2614 | 67 | } |
rfield@2614 | 68 | } |