diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java index 655f58bfee514..db8d98236c866 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java @@ -241,7 +241,7 @@ protected ClassFinder(Context context) { * available from the module system. */ long getSupplementaryFlags(ClassSymbol c) { - if (c.name == names.module_info) { + if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) { return 0; } @@ -257,22 +257,17 @@ long getSupplementaryFlags(ClassSymbol c) { try { ModuleSymbol owningModule = packge.modle; if (owningModule == syms.noModule) { - if (jrtIndex != null && jrtIndex.isInJRT(c.classfile)) { - JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName()); - Profile minProfile = Profile.DEFAULT; - if (ctSym.proprietary) - newFlags |= PROPRIETARY; - if (ctSym.minProfile != null) - minProfile = Profile.lookup(ctSym.minProfile); - if (profile != Profile.DEFAULT && minProfile.value > profile.value) { - newFlags |= NOT_IN_PROFILE; - } + JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName()); + Profile minProfile = Profile.DEFAULT; + if (ctSym.proprietary) + newFlags |= PROPRIETARY; + if (ctSym.minProfile != null) + minProfile = Profile.lookup(ctSym.minProfile); + if (profile != Profile.DEFAULT && minProfile.value > profile.value) { + newFlags |= NOT_IN_PROFILE; } } else if (owningModule.name == names.jdk_unsupported) { newFlags |= PROPRIETARY; - } else { - // don't accumulate user modules in supplementaryFlags - return 0; } } catch (IOException ignore) { } diff --git a/test/langtools/tools/javac/options/system/SystemSunProprietary.java b/test/langtools/tools/javac/options/system/SystemSunProprietary.java index 0a16305aaba7b..a057972d73d57 100644 --- a/test/langtools/tools/javac/options/system/SystemSunProprietary.java +++ b/test/langtools/tools/javac/options/system/SystemSunProprietary.java @@ -23,14 +23,18 @@ /** * @test - * @bug 8331081 + * @bug 8331081 8349058 * @summary Verify 'internal proprietary API' diagnostics if --system is configured * @library /tools/lib - * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.main - * jdk.compiler/com.sun.tools.javac.jvm jdk.jdeps/com.sun.tools.javap + * @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.file + * jdk.compiler/com.sun.tools.javac.jvm jdk.compiler/com.sun.tools.javac.main + * jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner * @run main SystemSunProprietary */ +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.util.Context; + import toolbox.JavacTask; import toolbox.Task; import toolbox.Task.Expect; @@ -41,13 +45,17 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class SystemSunProprietary extends TestRunner { private final ToolBox tb = new ToolBox(); + private Path src; + private Path classes; + public SystemSunProprietary() { super(System.err); } @@ -58,45 +66,14 @@ public static void main(String... args) throws Exception { @Test public void testUnsafe(Path base) throws IOException { - Path src = base.resolve("src"); + src = base.resolve("src"); tb.writeJavaFiles( src, "module m { requires jdk.unsupported; }", "package test; public class Test { sun.misc.Unsafe unsafe; } "); - Path classes = base.resolve("classes"); - tb.createDirectories(classes); - - List log; - List expected = - Arrays.asList( - "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", - "1 warning"); - log = - new JavacTask(tb) - .options("-XDrawDiagnostics") - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } - - log = - new JavacTask(tb) - .options("-XDrawDiagnostics", "--system", System.getProperty("java.home")) - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } + classes = base.resolve("classes"); + tb.createDirectories(classes); // Create a valid argument to system that isn't the current java.home Path originalSystem = Path.of(System.getProperty("java.home")); @@ -107,17 +84,54 @@ public void testUnsafe(Path base) throws IOException { Files.copy(originalSystem.resolve(path), to); } - log = + expectSunapi(false); + expectSunapi(false, "--system", System.getProperty("java.home")); + expectSunapi(false, "--release", String.valueOf(Runtime.version().feature())); + expectSunapi(false, "--release", String.valueOf(Runtime.version().feature() - 1)); + expectSunapi(true, "--release", String.valueOf(Runtime.version().feature())); + expectSunapi(true, "--release", String.valueOf(Runtime.version().feature() - 1)); + + // non-default --system arguments disable sunapi, see JDK-8349058 + expectNoSunapi(false, "--system", system.toString()); + + // -XDignore.symbol.file disables sunapi diagnostics, see JDK-8349058 + expectNoSunapi(true); + expectNoSunapi(true, "--system", System.getProperty("java.home")); + expectNoSunapi(true, "--system", system.toString()); + } + + private void expectSunapi(boolean ignoreSymbolFile, String... options) throws IOException { + expectSunapi(true, ignoreSymbolFile, options); + } + + private void expectNoSunapi(boolean ignoreSymbolFile, String... options) throws IOException { + expectSunapi(false, ignoreSymbolFile, options); + } + + private void expectSunapi(boolean expectDiagnostic, boolean ignoreSymbolFile, String... options) + throws IOException { + List expected = + expectDiagnostic + ? List.of( + "Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe", + "1 warning") + : List.of(""); + List allOptions = new ArrayList<>(); + allOptions.add("-XDrawDiagnostics"); + Collections.addAll(allOptions, options); + JavacFileManager fm = new JavacFileManager(new Context(), false, null); + fm.setSymbolFileEnabled(!ignoreSymbolFile); + List log = new JavacTask(tb) - .options("-XDrawDiagnostics", "--system", system.toString()) + .fileManager(fm) + .options(allOptions) .outdir(classes) .files(tb.findJavaFiles(src)) .run(Expect.SUCCESS) .writeAll() .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); + if (!log.equals(expected)) { + throw new AssertionError("expected: " + expected + "\nactual: " + log + "\n"); } }