|
| 1 | +/* |
| 2 | + * Copyright (c) 2024, Alphabet LLC. 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 8331081 |
| 27 | + * @summary Verify 'internal proprietary API' diagnostics if --system is configured |
| 28 | + * @library /tools/lib |
| 29 | + * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.main |
| 30 | + * jdk.compiler/com.sun.tools.javac.jvm jdk.jdeps/com.sun.tools.javap |
| 31 | + * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner |
| 32 | + * @run main SystemSunProprietary |
| 33 | + */ |
| 34 | +import toolbox.JavacTask; |
| 35 | +import toolbox.Task; |
| 36 | +import toolbox.Task.Expect; |
| 37 | +import toolbox.TestRunner; |
| 38 | +import toolbox.ToolBox; |
| 39 | + |
| 40 | +import java.io.IOException; |
| 41 | +import java.nio.file.Files; |
| 42 | +import java.nio.file.Path; |
| 43 | +import java.nio.file.Paths; |
| 44 | +import java.util.Arrays; |
| 45 | +import java.util.List; |
| 46 | + |
| 47 | +public class SystemSunProprietary extends TestRunner { |
| 48 | + |
| 49 | + private final ToolBox tb = new ToolBox(); |
| 50 | + |
| 51 | + public SystemSunProprietary() { |
| 52 | + super(System.err); |
| 53 | + } |
| 54 | + |
| 55 | + public static void main(String... args) throws Exception { |
| 56 | + new SystemSunProprietary().runTests(); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testUnsafe(Path base) throws IOException { |
| 61 | + Path src = base.resolve("src"); |
| 62 | + tb.writeJavaFiles( |
| 63 | + src, |
| 64 | + "module m { requires jdk.unsupported; }", |
| 65 | + "package test; public class Test { sun.misc.Unsafe unsafe; } "); |
| 66 | + Path classes = base.resolve("classes"); |
| 67 | + tb.createDirectories(classes); |
| 68 | + |
| 69 | + List<String> log; |
| 70 | + List<String> expected = |
| 71 | + Arrays.asList( |
| 72 | + "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", |
| 73 | + "1 warning"); |
| 74 | + |
| 75 | + log = |
| 76 | + new JavacTask(tb) |
| 77 | + .options("-XDrawDiagnostics") |
| 78 | + .outdir(classes) |
| 79 | + .files(tb.findJavaFiles(src)) |
| 80 | + .run(Expect.SUCCESS) |
| 81 | + .writeAll() |
| 82 | + .getOutputLines(Task.OutputKind.DIRECT); |
| 83 | + |
| 84 | + if (!expected.equals(log)) { |
| 85 | + throw new AssertionError("Unexpected output: " + log); |
| 86 | + } |
| 87 | + |
| 88 | + log = |
| 89 | + new JavacTask(tb) |
| 90 | + .options("-XDrawDiagnostics", "--system", System.getProperty("java.home")) |
| 91 | + .outdir(classes) |
| 92 | + .files(tb.findJavaFiles(src)) |
| 93 | + .run(Expect.SUCCESS) |
| 94 | + .writeAll() |
| 95 | + .getOutputLines(Task.OutputKind.DIRECT); |
| 96 | + |
| 97 | + if (!expected.equals(log)) { |
| 98 | + throw new AssertionError("Unexpected output: " + log); |
| 99 | + } |
| 100 | + |
| 101 | + // Create a valid argument to system that isn't the current java.home |
| 102 | + Path originalSystem = Path.of(System.getProperty("java.home")); |
| 103 | + Path system = base.resolve("system"); |
| 104 | + for (String path : List.of("release", "lib/modules", "lib/jrt-fs.jar")) { |
| 105 | + Path to = system.resolve(path); |
| 106 | + Files.createDirectories(to.getParent()); |
| 107 | + Files.copy(originalSystem.resolve(path), to); |
| 108 | + } |
| 109 | + |
| 110 | + log = |
| 111 | + new JavacTask(tb) |
| 112 | + .options("-XDrawDiagnostics", "--system", system.toString()) |
| 113 | + .outdir(classes) |
| 114 | + .files(tb.findJavaFiles(src)) |
| 115 | + .run(Expect.SUCCESS) |
| 116 | + .writeAll() |
| 117 | + .getOutputLines(Task.OutputKind.DIRECT); |
| 118 | + |
| 119 | + if (!expected.equals(log)) { |
| 120 | + throw new AssertionError("Unexpected output: " + log); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + protected void runTests() throws Exception { |
| 125 | + runTests(m -> new Object[] {Paths.get(m.getName())}); |
| 126 | + } |
| 127 | +} |
0 commit comments