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 972d6a1075b..95f8f847923 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 @@ public class ClassFinder { * 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 @@ public class ClassFinder { 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 deleted file mode 100644 index 0a16305aaba..00000000000 --- a/test/langtools/tools/javac/options/system/SystemSunProprietary.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (c) 2024, Alphabet LLC. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/** - * @test - * @bug 8331081 - * @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 - * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner - * @run main SystemSunProprietary - */ -import toolbox.JavacTask; -import toolbox.Task; -import toolbox.Task.Expect; -import toolbox.TestRunner; -import toolbox.ToolBox; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Arrays; -import java.util.List; - -public class SystemSunProprietary extends TestRunner { - - private final ToolBox tb = new ToolBox(); - - public SystemSunProprietary() { - super(System.err); - } - - public static void main(String... args) throws Exception { - new SystemSunProprietary().runTests(); - } - - @Test - public void testUnsafe(Path base) throws IOException { - Path 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); - } - - // Create a valid argument to system that isn't the current java.home - Path originalSystem = Path.of(System.getProperty("java.home")); - Path system = base.resolve("system"); - for (String path : List.of("release", "lib/modules", "lib/jrt-fs.jar")) { - Path to = system.resolve(path); - Files.createDirectories(to.getParent()); - Files.copy(originalSystem.resolve(path), to); - } - - log = - new JavacTask(tb) - .options("-XDrawDiagnostics", "--system", system.toString()) - .outdir(classes) - .files(tb.findJavaFiles(src)) - .run(Expect.SUCCESS) - .writeAll() - .getOutputLines(Task.OutputKind.DIRECT); - - if (!expected.equals(log)) { - throw new AssertionError("Unexpected output: " + log); - } - } - - protected void runTests() throws Exception { - runTests(m -> new Object[] {Paths.get(m.getName())}); - } -}