Skip to content

Commit 2170e99

Browse files
committedMay 22, 2024
8331081: 'internal proprietary API' diagnostics if --system is configured to an earlier JDK version
Reviewed-by: jlahoda
1 parent a0c5714 commit 2170e99

File tree

2 files changed

+141
-9
lines changed

2 files changed

+141
-9
lines changed
 

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

+14-9
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 (jrtIndex == null || !jrtIndex.isInJRT(c.classfile) || c.name == names.module_info) {
244+
if (c.name == names.module_info) {
245245
return 0;
246246
}
247247

@@ -257,17 +257,22 @@ long getSupplementaryFlags(ClassSymbol c) {
257257
try {
258258
ModuleSymbol owningModule = packge.modle;
259259
if (owningModule == syms.noModule) {
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;
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+
}
268270
}
269271
} else if (owningModule.name == names.jdk_unsupported) {
270272
newFlags |= PROPRIETARY;
273+
} else {
274+
// don't accumulate user modules in supplementaryFlags
275+
return 0;
271276
}
272277
} catch (IOException ignore) {
273278
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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

Comments
 (0)
Please sign in to comment.