Skip to content

Commit 1ab1c1d

Browse files
committedFeb 6, 2025
8349058: 'internal proprietary API' warnings make javac warnings unusable
Reviewed-by: vromero
1 parent eb84702 commit 1ab1c1d

File tree

2 files changed

+66
-57
lines changed

2 files changed

+66
-57
lines changed
 

‎src/jdk.compiler/share/classes/com/sun/tools/javac/code/ClassFinder.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected ClassFinder(Context context) {
241241
* available from the module system.
242242
*/
243243
long getSupplementaryFlags(ClassSymbol c) {
244-
if (c.name == names.module_info) {
244+
if (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) {
245245
return 0;
246246
}
247247

@@ -257,22 +257,17 @@ long getSupplementaryFlags(ClassSymbol c) {
257257
try {
258258
ModuleSymbol owningModule = packge.modle;
259259
if (owningModule == syms.noModule) {
260-
if (jrtIndex != null && jrtIndex.isInJRT(c.classfile)) {
261-
JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName());
262-
Profile minProfile = Profile.DEFAULT;
263-
if (ctSym.proprietary)
264-
newFlags |= PROPRIETARY;
265-
if (ctSym.minProfile != null)
266-
minProfile = Profile.lookup(ctSym.minProfile);
267-
if (profile != Profile.DEFAULT && minProfile.value > profile.value) {
268-
newFlags |= NOT_IN_PROFILE;
269-
}
260+
JRTIndex.CtSym ctSym = jrtIndex.getCtSym(packge.flatName());
261+
Profile minProfile = Profile.DEFAULT;
262+
if (ctSym.proprietary)
263+
newFlags |= PROPRIETARY;
264+
if (ctSym.minProfile != null)
265+
minProfile = Profile.lookup(ctSym.minProfile);
266+
if (profile != Profile.DEFAULT && minProfile.value > profile.value) {
267+
newFlags |= NOT_IN_PROFILE;
270268
}
271269
} else if (owningModule.name == names.jdk_unsupported) {
272270
newFlags |= PROPRIETARY;
273-
} else {
274-
// don't accumulate user modules in supplementaryFlags
275-
return 0;
276271
}
277272
} catch (IOException ignore) {
278273
}

‎test/langtools/tools/javac/options/system/SystemSunProprietary.java

+57-43
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@
2323

2424
/**
2525
* @test
26-
* @bug 8331081
26+
* @bug 8331081 8349058
2727
* @summary Verify 'internal proprietary API' diagnostics if --system is configured
2828
* @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
29+
* @modules jdk.compiler/com.sun.tools.javac.api jdk.compiler/com.sun.tools.javac.file
30+
* jdk.compiler/com.sun.tools.javac.jvm jdk.compiler/com.sun.tools.javac.main
31+
* jdk.compiler/com.sun.tools.javac.util jdk.jdeps/com.sun.tools.javap
3132
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask toolbox.JavapTask toolbox.TestRunner
3233
* @run main SystemSunProprietary
3334
*/
35+
import com.sun.tools.javac.file.JavacFileManager;
36+
import com.sun.tools.javac.util.Context;
37+
3438
import toolbox.JavacTask;
3539
import toolbox.Task;
3640
import toolbox.Task.Expect;
@@ -41,13 +45,17 @@
4145
import java.nio.file.Files;
4246
import java.nio.file.Path;
4347
import java.nio.file.Paths;
44-
import java.util.Arrays;
48+
import java.util.ArrayList;
49+
import java.util.Collections;
4550
import java.util.List;
4651

4752
public class SystemSunProprietary extends TestRunner {
4853

4954
private final ToolBox tb = new ToolBox();
5055

56+
private Path src;
57+
private Path classes;
58+
5159
public SystemSunProprietary() {
5260
super(System.err);
5361
}
@@ -58,45 +66,14 @@ public static void main(String... args) throws Exception {
5866

5967
@Test
6068
public void testUnsafe(Path base) throws IOException {
61-
Path src = base.resolve("src");
69+
src = base.resolve("src");
6270
tb.writeJavaFiles(
6371
src,
6472
"module m { requires jdk.unsupported; }",
6573
"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");
7474

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-
}
75+
classes = base.resolve("classes");
76+
tb.createDirectories(classes);
10077

10178
// Create a valid argument to system that isn't the current java.home
10279
Path originalSystem = Path.of(System.getProperty("java.home"));
@@ -107,17 +84,54 @@ public void testUnsafe(Path base) throws IOException {
10784
Files.copy(originalSystem.resolve(path), to);
10885
}
10986

110-
log =
87+
expectSunapi(false);
88+
expectSunapi(false, "--system", System.getProperty("java.home"));
89+
expectSunapi(false, "--release", String.valueOf(Runtime.version().feature()));
90+
expectSunapi(false, "--release", String.valueOf(Runtime.version().feature() - 1));
91+
expectSunapi(true, "--release", String.valueOf(Runtime.version().feature()));
92+
expectSunapi(true, "--release", String.valueOf(Runtime.version().feature() - 1));
93+
94+
// non-default --system arguments disable sunapi, see JDK-8349058
95+
expectNoSunapi(false, "--system", system.toString());
96+
97+
// -XDignore.symbol.file disables sunapi diagnostics, see JDK-8349058
98+
expectNoSunapi(true);
99+
expectNoSunapi(true, "--system", System.getProperty("java.home"));
100+
expectNoSunapi(true, "--system", system.toString());
101+
}
102+
103+
private void expectSunapi(boolean ignoreSymbolFile, String... options) throws IOException {
104+
expectSunapi(true, ignoreSymbolFile, options);
105+
}
106+
107+
private void expectNoSunapi(boolean ignoreSymbolFile, String... options) throws IOException {
108+
expectSunapi(false, ignoreSymbolFile, options);
109+
}
110+
111+
private void expectSunapi(boolean expectDiagnostic, boolean ignoreSymbolFile, String... options)
112+
throws IOException {
113+
List<String> expected =
114+
expectDiagnostic
115+
? List.of(
116+
"Test.java:1:43: compiler.warn.sun.proprietary: sun.misc.Unsafe",
117+
"1 warning")
118+
: List.of("");
119+
List<String> allOptions = new ArrayList<>();
120+
allOptions.add("-XDrawDiagnostics");
121+
Collections.addAll(allOptions, options);
122+
JavacFileManager fm = new JavacFileManager(new Context(), false, null);
123+
fm.setSymbolFileEnabled(!ignoreSymbolFile);
124+
List<String> log =
111125
new JavacTask(tb)
112-
.options("-XDrawDiagnostics", "--system", system.toString())
126+
.fileManager(fm)
127+
.options(allOptions)
113128
.outdir(classes)
114129
.files(tb.findJavaFiles(src))
115130
.run(Expect.SUCCESS)
116131
.writeAll()
117132
.getOutputLines(Task.OutputKind.DIRECT);
118-
119-
if (!expected.equals(log)) {
120-
throw new AssertionError("Unexpected output: " + log);
133+
if (!log.equals(expected)) {
134+
throw new AssertionError("expected: " + expected + "\nactual: " + log + "\n");
121135
}
122136
}
123137

0 commit comments

Comments
 (0)
Please sign in to comment.