21 * questions. |
21 * questions. |
22 */ |
22 */ |
23 |
23 |
24 /* |
24 /* |
25 * @test |
25 * @test |
26 * @bug 8169197 8172668 8173117 |
26 * @bug 8169197 8172668 8173117 8175007 |
27 * @summary Check convenient errors are produced for inaccessible classes. |
27 * @summary Check convenient errors are produced for inaccessible classes. |
28 * @library /tools/lib |
28 * @library /tools/lib |
29 * @modules jdk.compiler/com.sun.tools.javac.api |
29 * @modules jdk.compiler/com.sun.tools.javac.api |
30 * jdk.compiler/com.sun.tools.javac.main |
30 * jdk.compiler/com.sun.tools.javac.main |
31 * jdk.compiler/com.sun.tools.javac.util |
31 * jdk.compiler/com.sun.tools.javac.util |
702 |
702 |
703 if (!expected.equals(actual)) { |
703 if (!expected.equals(actual)) { |
704 throw new Exception("Expected names not generated: " + actual); |
704 throw new Exception("Expected names not generated: " + actual); |
705 } |
705 } |
706 } |
706 } |
|
707 |
|
708 @Test |
|
709 public void testInaccessibleInVisible(Path base) throws Exception { |
|
710 Path src = base.resolve("src"); |
|
711 Path src_ma = src.resolve("ma"); |
|
712 tb.writeJavaFiles(src_ma, |
|
713 "module ma { exports ma; }", |
|
714 "package ma; class NotApi { public static class Inner { } }"); |
|
715 Path classes = base.resolve("classes"); |
|
716 tb.createDirectories(classes); |
|
717 |
|
718 new JavacTask(tb) |
|
719 .outdir(classes) |
|
720 .files(findJavaFiles(src_ma)) |
|
721 .run() |
|
722 .writeAll(); |
|
723 |
|
724 Path src_mb = src.resolve("mb"); |
|
725 tb.writeJavaFiles(src_mb, |
|
726 "module mb { requires ma; }", |
|
727 "package mb.a; public class Test { ma.NotApi.Inner i1; mb.b.NotApi.Inner i2; }", |
|
728 "package mb.b; class NotApi { public static class Inner { } }"); |
|
729 |
|
730 List<String> log = new JavacTask(tb) |
|
731 .options("-XDrawDiagnostics", |
|
732 "--module-path", classes.toString()) |
|
733 .outdir(classes) |
|
734 .files(findJavaFiles(src_mb)) |
|
735 .run(Task.Expect.FAIL) |
|
736 .writeAll() |
|
737 .getOutputLines(Task.OutputKind.DIRECT); |
|
738 |
|
739 List<String> expected = Arrays.asList( |
|
740 "Test.java:1:44: compiler.err.not.def.access.class.intf.cant.access: ma.NotApi.Inner, ma.NotApi", |
|
741 "Test.java:1:66: compiler.err.not.def.access.class.intf.cant.access: mb.b.NotApi.Inner, mb.b.NotApi", |
|
742 "2 errors"); |
|
743 |
|
744 if (!expected.equals(log)) |
|
745 throw new Exception("expected output not found; actual: " + log); |
|
746 } |
707 } |
747 } |