ProtectedInaccessibleMethodRefTest.java revision 3648:31c022a17639
1/*
2 * Copyright (c) 2016, 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 8138667
27 * @summary Verify that javac emits suitable accessors when a method reference mentions a protected method that would need an accessor
28 * @run main ProtectedInaccessibleMethodRefTest
29 */
30
31
32import pack.SuperClass;
33
34import java.util.concurrent.Callable;
35
36public final class ProtectedInaccessibleMethodRefTest extends SuperClass {
37
38    static String message = "NOT OK";
39
40    public void doTest() throws Exception {
41        new Callable<Void>() {
42            @Override
43            public Void call() throws Exception {
44                final Runnable r = ProtectedInaccessibleMethodRefTest.this::myDo;
45                r.run();
46                return null;
47            }
48        }.call();
49
50        new Callable<Void>() {
51            @Override
52            public Void call() throws Exception {
53                final Runnable r = ProtectedInaccessibleMethodRefTest::myStaticDo;
54                r.run();
55                return null;
56            }
57        }.call();
58    }
59
60    public void message(String s) {
61        message = s;
62    }
63
64    public static void main(String[] args) throws Exception {
65        new ProtectedInaccessibleMethodRefTest().doTest();
66        if (!message.equals("OK!"))
67            throw new AssertionError("Unexpected output");
68        if (!sMessage.equals("OK!"))
69            throw new AssertionError("Unexpected output");
70    }
71}
72