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.Arrays; |
rfield@2614 | 33 | import java.util.Comparator; |
rfield@2614 | 34 | import java.util.List; |
rfield@2614 | 35 | |
rfield@2614 | 36 | import static java.util.stream.Collectors.toList; |
rfield@2614 | 37 | |
rfield@2614 | 38 | public class MethodReferenceIntersection1 { |
rfield@2614 | 39 | |
rfield@2614 | 40 | public static void main(String[] args) { |
rfield@2614 | 41 | MethodReferenceIntersection1 main = new MethodReferenceIntersection1(); |
rfield@2614 | 42 | List<Info_MRI1> list = main.toInfoListError(Arrays.asList(new Base_MRI1())); |
rfield@2614 | 43 | System.out.printf("result %d\n", list.size()); |
rfield@2614 | 44 | } |
rfield@2614 | 45 | |
rfield@2614 | 46 | public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListError(List<H> list) { |
rfield@2614 | 47 | Comparator<B_MRI1> byNameComparator = |
rfield@2614 | 48 | (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB()); |
rfield@2614 | 49 | return list.stream().sorted(byNameComparator).map(Info_MRI1::new).collect(toList()); |
rfield@2614 | 50 | } |
rfield@2614 | 51 | |
rfield@2614 | 52 | public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListWorks(List<H> list) { |
rfield@2614 | 53 | Comparator<B_MRI1> byNameComparator = |
rfield@2614 | 54 | (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB()); |
rfield@2614 | 55 | return list.stream().sorted(byNameComparator).map(s -> new Info_MRI1(s)).collect(toList()); |
rfield@2614 | 56 | } |
rfield@2614 | 57 | } |
rfield@2614 | 58 | |
rfield@2614 | 59 | interface B_MRI1 { |
rfield@2614 | 60 | public String getB(); |
rfield@2614 | 61 | } |
rfield@2614 | 62 | |
rfield@2614 | 63 | interface A_MRI1 { |
rfield@2614 | 64 | public long getA(); |
rfield@2614 | 65 | } |
rfield@2614 | 66 | |
rfield@2614 | 67 | class Info_MRI1 { |
rfield@2614 | 68 | private final long a; |
rfield@2614 | 69 | private final String b; |
rfield@2614 | 70 | |
rfield@2614 | 71 | <H extends A_MRI1 & B_MRI1> Info_MRI1(H h) { |
rfield@2614 | 72 | a = h.getA(); |
rfield@2614 | 73 | b = h.getB(); |
rfield@2614 | 74 | } |
rfield@2614 | 75 | } |
rfield@2614 | 76 | |
rfield@2614 | 77 | class Base_MRI1 implements A_MRI1, B_MRI1 { |
rfield@2614 | 78 | |
rfield@2614 | 79 | @Override |
rfield@2614 | 80 | public long getA() { |
rfield@2614 | 81 | return 7L; |
rfield@2614 | 82 | } |
rfield@2614 | 83 | |
rfield@2614 | 84 | @Override |
rfield@2614 | 85 | public String getB() { |
rfield@2614 | 86 | return "hello"; |
rfield@2614 | 87 | } |
rfield@2614 | 88 | } |