Skip to content

Commit a51a852

Browse files
committed
8228460: bootstrap class path not set in conjunction with -source 11
Ensuring implicit system module path is checked for the no-bootclasspath warning for -source >= 9. Reviewed-by: vromero
1 parent b9e1776 commit a51a852

File tree

7 files changed

+267
-3
lines changed

7 files changed

+267
-3
lines changed

src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ public boolean isDefaultBootClassPath() {
198198
return locations.isDefaultBootClassPath();
199199
}
200200

201+
public boolean isDefaultSystemModulesPath() {
202+
return locations.isDefaultSystemModulesPath();
203+
}
204+
201205
// <editor-fold defaultstate="collapsed" desc="Option handling">
202206
@Override @DefinedBy(Api.COMPILER)
203207
public boolean handleOption(String current, Iterator<String> remaining) {

src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
import com.sun.tools.javac.util.Pair;
9595
import com.sun.tools.javac.util.StringUtils;
9696

97+
import static javax.tools.StandardLocation.SYSTEM_MODULES;
9798
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
9899

99100
import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH;
@@ -185,6 +186,12 @@ boolean isDefaultBootClassPath() {
185186
return h.isDefault();
186187
}
187188

189+
boolean isDefaultSystemModulesPath() {
190+
SystemModulesLocationHandler h
191+
= (SystemModulesLocationHandler) getHandler(SYSTEM_MODULES);
192+
return !h.isExplicit();
193+
}
194+
188195
/**
189196
* Split a search path into its elements. Empty path elements will be ignored.
190197
*

src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -565,8 +565,13 @@ public boolean validate() {
565565
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
566566
if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) {
567567
if (fm instanceof BaseFileManager) {
568-
if (((BaseFileManager) fm).isDefaultBootClassPath())
569-
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name));
568+
if (source.compareTo(Source.JDK8) <= 0) {
569+
if (((BaseFileManager) fm).isDefaultBootClassPath())
570+
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name));
571+
} else {
572+
if (((BaseFileManager) fm).isDefaultSystemModulesPath())
573+
log.warning(LintCategory.OPTIONS, Warnings.SourceNoSystemModulesPath(source.name));
574+
}
570575
}
571576
}
572577

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,6 +1865,10 @@ compiler.warn.static.not.qualified.by.type=\
18651865
compiler.warn.source.no.bootclasspath=\
18661866
bootstrap class path not set in conjunction with -source {0}
18671867

1868+
# 0: string
1869+
compiler.warn.source.no.system.modules.path=\
1870+
system modules path not set in conjunction with -source {0}
1871+
18681872
# 0: string
18691873
compiler.warn.option.obsolete.source=\
18701874
source value {0} is obsolete and will be removed in a future release
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. 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+
// key: compiler.warn.source.no.system.modules.path
25+
// options: -source 9
26+
27+
class SourceNoSystemModulesPath { }
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. 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 8228460
27+
* @summary Verify --system is required rather than -bootclasspath for -source 9.
28+
* @library /tools/lib
29+
* @modules jdk.compiler/com.sun.tools.javac.api
30+
* jdk.compiler/com.sun.tools.javac.main
31+
* @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
32+
* @run main BCPOrSystemNotSpecified
33+
*/
34+
35+
import java.io.IOException;
36+
import java.nio.file.Path;
37+
import java.nio.file.Paths;
38+
import java.util.Arrays;
39+
import java.util.List;
40+
41+
import java.io.InputStream;
42+
import java.nio.file.Files;
43+
import java.util.EnumSet;
44+
import javax.tools.JavaFileManager;
45+
import javax.tools.JavaFileObject;
46+
import javax.tools.StandardLocation;
47+
import javax.tools.ToolProvider;
48+
import toolbox.JavacTask;
49+
import toolbox.Task;
50+
import toolbox.Task.Expect;
51+
import toolbox.TestRunner;
52+
import toolbox.ToolBox;
53+
54+
public class BCPOrSystemNotSpecified extends TestRunner {
55+
56+
private final ToolBox tb = new ToolBox();
57+
private final String fileSep = System.getProperty("file.separator");
58+
59+
public BCPOrSystemNotSpecified() {
60+
super(System.err);
61+
}
62+
63+
public static void main(String... args) throws Exception {
64+
new BCPOrSystemNotSpecified().runTests();
65+
}
66+
67+
@Test
68+
public void testSource8(Path base) throws IOException {
69+
Path src = base.resolve("src");
70+
tb.writeJavaFiles(src,
71+
"package test; public class Test { } ");
72+
Path classes = base.resolve("classes");
73+
tb.createDirectories(classes);
74+
75+
List<String> log;
76+
List<String> expected = Arrays.asList(
77+
"- compiler.warn.source.no.bootclasspath: 8",
78+
"1 warning"
79+
);
80+
81+
log = new JavacTask(tb)
82+
.options("-XDrawDiagnostics", "-source", "8")
83+
.outdir(classes)
84+
.files(tb.findJavaFiles(src))
85+
.run(Expect.SUCCESS)
86+
.writeAll()
87+
.getOutputLines(Task.OutputKind.DIRECT);
88+
89+
if (!expected.equals(log)) {
90+
throw new AssertionError("Unexpected output: " + log);
91+
}
92+
93+
Path bcp = base.resolve("bcp");
94+
95+
prepareBCP(bcp);
96+
97+
new JavacTask(tb)
98+
.options("-XDrawDiagnostics",
99+
"-source", "8",
100+
"-bootclasspath", bcp.toAbsolutePath().toString(),
101+
"-Werror")
102+
.outdir(classes)
103+
.files(tb.findJavaFiles(src))
104+
.run(Expect.SUCCESS)
105+
.writeAll()
106+
.getOutputLines(Task.OutputKind.DIRECT);
107+
108+
if (!expected.equals(log)) {
109+
throw new AssertionError("Unexpected output: " + log);
110+
}
111+
}
112+
113+
@Test
114+
public void testSource9(Path base) throws IOException {
115+
Path src = base.resolve("src");
116+
tb.writeJavaFiles(src,
117+
"package test; public class Test { } ");
118+
Path classes = base.resolve("classes");
119+
tb.createDirectories(classes);
120+
121+
List<String> log;
122+
List<String> expected = Arrays.asList(
123+
"- compiler.warn.source.no.system.modules.path: 9",
124+
"1 warning"
125+
);
126+
127+
log = new JavacTask(tb)
128+
.options("-XDrawDiagnostics",
129+
"-source", "9")
130+
.outdir(classes)
131+
.files(tb.findJavaFiles(src))
132+
.run(Expect.SUCCESS)
133+
.writeAll()
134+
.getOutputLines(Task.OutputKind.DIRECT);
135+
136+
if (!expected.equals(log)) {
137+
throw new AssertionError("Unexpected output: " + log);
138+
}
139+
140+
Path bcp = base.resolve("bcp");
141+
142+
prepareBCP(bcp);
143+
144+
log = new JavacTask(tb)
145+
.options("-XDrawDiagnostics",
146+
"-source", "9",
147+
"-bootclasspath", bcp.toAbsolutePath().toString())
148+
.outdir(classes)
149+
.files(tb.findJavaFiles(src))
150+
.run(Expect.SUCCESS)
151+
.writeAll()
152+
.getOutputLines(Task.OutputKind.DIRECT);
153+
154+
if (!expected.equals(log)) {
155+
throw new AssertionError("Unexpected output: " + log);
156+
}
157+
158+
new JavacTask(tb)
159+
.options("-XDrawDiagnostics",
160+
"-source", "9",
161+
"--system", "none",
162+
"--module-path", bcp.toAbsolutePath().toString(),
163+
"-Werror")
164+
.outdir(classes)
165+
.files(tb.findJavaFiles(src))
166+
.run(Expect.SUCCESS)
167+
.writeAll()
168+
.getOutputLines(Task.OutputKind.DIRECT);
169+
170+
if (!expected.equals(log)) {
171+
throw new AssertionError("Unexpected output: " + log);
172+
}
173+
174+
new JavacTask(tb)
175+
.options("-XDrawDiagnostics",
176+
"-source", "9",
177+
"--system", System.getProperty("java.home"),
178+
"-Werror")
179+
.outdir(classes)
180+
.files(tb.findJavaFiles(src))
181+
.run(Expect.SUCCESS)
182+
.writeAll()
183+
.getOutputLines(Task.OutputKind.DIRECT);
184+
185+
if (!expected.equals(log)) {
186+
throw new AssertionError("Unexpected output: " + log);
187+
}
188+
}
189+
190+
protected void runTests() throws Exception {
191+
runTests(m -> new Object[] { Paths.get(m.getName()).toAbsolutePath() });
192+
}
193+
194+
private void prepareBCP(Path target) throws IOException {
195+
try (JavaFileManager jfm = ToolProvider.getSystemJavaCompiler()
196+
.getStandardFileManager(null, null, null)) {
197+
for (String pack : new String[] {"", "java.lang", "java.lang.annotation"}) {
198+
JavaFileManager.Location javaBase =
199+
jfm.getLocationForModule(StandardLocation.SYSTEM_MODULES,
200+
"java.base");
201+
for (JavaFileObject file : jfm.list(javaBase,
202+
pack,
203+
EnumSet.of(JavaFileObject.Kind.CLASS),
204+
false)) {
205+
Path targetDir = target.resolve(pack.replace(".", fileSep));
206+
Files.createDirectories(targetDir);
207+
try (InputStream in = file.openInputStream()) {
208+
String sourcePath = file.getName();
209+
int sepPos = sourcePath.lastIndexOf(fileSep);
210+
String fileName = sourcePath.substring(sepPos + 1);
211+
Files.copy(in, targetDir.resolve(fileName));
212+
}
213+
}
214+
}
215+
}
216+
}
217+
}

test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01_source10.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- compiler.warn.source.no.bootclasspath: 10
1+
- compiler.warn.source.no.system.modules.path: 10
22
VarInImplicitLambdaNegTest01.java:12:36: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.var.syntax.in.implicit.lambda), 10, 11
33
VarInImplicitLambdaNegTest01.java:15:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.implicit.and.explicit.not.allowed)
44
VarInImplicitLambdaNegTest01.java:17:52: compiler.err.restricted.type.not.allowed.here: var

0 commit comments

Comments
 (0)