mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
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
This commit is contained in:
parent
b9e177677c
commit
a51a8527e7
7 changed files with 267 additions and 3 deletions
|
@ -198,6 +198,10 @@ public abstract class BaseFileManager implements JavaFileManager {
|
||||||
return locations.isDefaultBootClassPath();
|
return locations.isDefaultBootClassPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultSystemModulesPath() {
|
||||||
|
return locations.isDefaultSystemModulesPath();
|
||||||
|
}
|
||||||
|
|
||||||
// <editor-fold defaultstate="collapsed" desc="Option handling">
|
// <editor-fold defaultstate="collapsed" desc="Option handling">
|
||||||
@Override @DefinedBy(Api.COMPILER)
|
@Override @DefinedBy(Api.COMPILER)
|
||||||
public boolean handleOption(String current, Iterator<String> remaining) {
|
public boolean handleOption(String current, Iterator<String> remaining) {
|
||||||
|
|
|
@ -94,6 +94,7 @@ import com.sun.tools.javac.util.Iterators;
|
||||||
import com.sun.tools.javac.util.Pair;
|
import com.sun.tools.javac.util.Pair;
|
||||||
import com.sun.tools.javac.util.StringUtils;
|
import com.sun.tools.javac.util.StringUtils;
|
||||||
|
|
||||||
|
import static javax.tools.StandardLocation.SYSTEM_MODULES;
|
||||||
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
|
import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH;
|
||||||
|
|
||||||
import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH;
|
import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH;
|
||||||
|
@ -185,6 +186,12 @@ public class Locations {
|
||||||
return h.isDefault();
|
return h.isDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isDefaultSystemModulesPath() {
|
||||||
|
SystemModulesLocationHandler h
|
||||||
|
= (SystemModulesLocationHandler) getHandler(SYSTEM_MODULES);
|
||||||
|
return !h.isExplicit();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split a search path into its elements. Empty path elements will be ignored.
|
* Split a search path into its elements. Empty path elements will be ignored.
|
||||||
*
|
*
|
||||||
|
|
|
@ -565,8 +565,13 @@ public class Arguments {
|
||||||
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
|
boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option);
|
||||||
if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) {
|
if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) {
|
||||||
if (fm instanceof BaseFileManager) {
|
if (fm instanceof BaseFileManager) {
|
||||||
|
if (source.compareTo(Source.JDK8) <= 0) {
|
||||||
if (((BaseFileManager) fm).isDefaultBootClassPath())
|
if (((BaseFileManager) fm).isDefaultBootClassPath())
|
||||||
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name));
|
log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name));
|
||||||
|
} else {
|
||||||
|
if (((BaseFileManager) fm).isDefaultSystemModulesPath())
|
||||||
|
log.warning(LintCategory.OPTIONS, Warnings.SourceNoSystemModulesPath(source.name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1865,6 +1865,10 @@ compiler.warn.static.not.qualified.by.type=\
|
||||||
compiler.warn.source.no.bootclasspath=\
|
compiler.warn.source.no.bootclasspath=\
|
||||||
bootstrap class path not set in conjunction with -source {0}
|
bootstrap class path not set in conjunction with -source {0}
|
||||||
|
|
||||||
|
# 0: string
|
||||||
|
compiler.warn.source.no.system.modules.path=\
|
||||||
|
system modules path not set in conjunction with -source {0}
|
||||||
|
|
||||||
# 0: string
|
# 0: string
|
||||||
compiler.warn.option.obsolete.source=\
|
compiler.warn.option.obsolete.source=\
|
||||||
source value {0} is obsolete and will be removed in a future release
|
source value {0} is obsolete and will be removed in a future release
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Oracle and/or its affiliates. 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// key: compiler.warn.source.no.system.modules.path
|
||||||
|
// options: -source 9
|
||||||
|
|
||||||
|
class SourceNoSystemModulesPath { }
|
217
test/langtools/tools/javac/options/BCPOrSystemNotSpecified.java
Normal file
217
test/langtools/tools/javac/options/BCPOrSystemNotSpecified.java
Normal file
|
@ -0,0 +1,217 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019, Oracle and/or its affiliates. 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 8228460
|
||||||
|
* @summary Verify --system is required rather than -bootclasspath for -source 9.
|
||||||
|
* @library /tools/lib
|
||||||
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||||
|
* jdk.compiler/com.sun.tools.javac.main
|
||||||
|
* @build toolbox.ToolBox toolbox.JavacTask toolbox.TestRunner
|
||||||
|
* @run main BCPOrSystemNotSpecified
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import javax.tools.JavaFileManager;
|
||||||
|
import javax.tools.JavaFileObject;
|
||||||
|
import javax.tools.StandardLocation;
|
||||||
|
import javax.tools.ToolProvider;
|
||||||
|
import toolbox.JavacTask;
|
||||||
|
import toolbox.Task;
|
||||||
|
import toolbox.Task.Expect;
|
||||||
|
import toolbox.TestRunner;
|
||||||
|
import toolbox.ToolBox;
|
||||||
|
|
||||||
|
public class BCPOrSystemNotSpecified extends TestRunner {
|
||||||
|
|
||||||
|
private final ToolBox tb = new ToolBox();
|
||||||
|
private final String fileSep = System.getProperty("file.separator");
|
||||||
|
|
||||||
|
public BCPOrSystemNotSpecified() {
|
||||||
|
super(System.err);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String... args) throws Exception {
|
||||||
|
new BCPOrSystemNotSpecified().runTests();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSource8(Path base) throws IOException {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
tb.writeJavaFiles(src,
|
||||||
|
"package test; public class Test { } ");
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
tb.createDirectories(classes);
|
||||||
|
|
||||||
|
List<String> log;
|
||||||
|
List<String> expected = Arrays.asList(
|
||||||
|
"- compiler.warn.source.no.bootclasspath: 8",
|
||||||
|
"1 warning"
|
||||||
|
);
|
||||||
|
|
||||||
|
log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics", "-source", "8")
|
||||||
|
.outdir(classes)
|
||||||
|
.files(tb.findJavaFiles(src))
|
||||||
|
.run(Expect.SUCCESS)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
if (!expected.equals(log)) {
|
||||||
|
throw new AssertionError("Unexpected output: " + log);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path bcp = base.resolve("bcp");
|
||||||
|
|
||||||
|
prepareBCP(bcp);
|
||||||
|
|
||||||
|
new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"-source", "8",
|
||||||
|
"-bootclasspath", bcp.toAbsolutePath().toString(),
|
||||||
|
"-Werror")
|
||||||
|
.outdir(classes)
|
||||||
|
.files(tb.findJavaFiles(src))
|
||||||
|
.run(Expect.SUCCESS)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
if (!expected.equals(log)) {
|
||||||
|
throw new AssertionError("Unexpected output: " + log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSource9(Path base) throws IOException {
|
||||||
|
Path src = base.resolve("src");
|
||||||
|
tb.writeJavaFiles(src,
|
||||||
|
"package test; public class Test { } ");
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
tb.createDirectories(classes);
|
||||||
|
|
||||||
|
List<String> log;
|
||||||
|
List<String> expected = Arrays.asList(
|
||||||
|
"- compiler.warn.source.no.system.modules.path: 9",
|
||||||
|
"1 warning"
|
||||||
|
);
|
||||||
|
|
||||||
|
log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"-source", "9")
|
||||||
|
.outdir(classes)
|
||||||
|
.files(tb.findJavaFiles(src))
|
||||||
|
.run(Expect.SUCCESS)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
if (!expected.equals(log)) {
|
||||||
|
throw new AssertionError("Unexpected output: " + log);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path bcp = base.resolve("bcp");
|
||||||
|
|
||||||
|
prepareBCP(bcp);
|
||||||
|
|
||||||
|
log = new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"-source", "9",
|
||||||
|
"-bootclasspath", bcp.toAbsolutePath().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);
|
||||||
|
}
|
||||||
|
|
||||||
|
new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"-source", "9",
|
||||||
|
"--system", "none",
|
||||||
|
"--module-path", bcp.toAbsolutePath().toString(),
|
||||||
|
"-Werror")
|
||||||
|
.outdir(classes)
|
||||||
|
.files(tb.findJavaFiles(src))
|
||||||
|
.run(Expect.SUCCESS)
|
||||||
|
.writeAll()
|
||||||
|
.getOutputLines(Task.OutputKind.DIRECT);
|
||||||
|
|
||||||
|
if (!expected.equals(log)) {
|
||||||
|
throw new AssertionError("Unexpected output: " + log);
|
||||||
|
}
|
||||||
|
|
||||||
|
new JavacTask(tb)
|
||||||
|
.options("-XDrawDiagnostics",
|
||||||
|
"-source", "9",
|
||||||
|
"--system", System.getProperty("java.home"),
|
||||||
|
"-Werror")
|
||||||
|
.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()).toAbsolutePath() });
|
||||||
|
}
|
||||||
|
|
||||||
|
private void prepareBCP(Path target) throws IOException {
|
||||||
|
try (JavaFileManager jfm = ToolProvider.getSystemJavaCompiler()
|
||||||
|
.getStandardFileManager(null, null, null)) {
|
||||||
|
for (String pack : new String[] {"", "java.lang", "java.lang.annotation"}) {
|
||||||
|
JavaFileManager.Location javaBase =
|
||||||
|
jfm.getLocationForModule(StandardLocation.SYSTEM_MODULES,
|
||||||
|
"java.base");
|
||||||
|
for (JavaFileObject file : jfm.list(javaBase,
|
||||||
|
pack,
|
||||||
|
EnumSet.of(JavaFileObject.Kind.CLASS),
|
||||||
|
false)) {
|
||||||
|
Path targetDir = target.resolve(pack.replace(".", fileSep));
|
||||||
|
Files.createDirectories(targetDir);
|
||||||
|
try (InputStream in = file.openInputStream()) {
|
||||||
|
String sourcePath = file.getName();
|
||||||
|
int sepPos = sourcePath.lastIndexOf(fileSep);
|
||||||
|
String fileName = sourcePath.substring(sepPos + 1);
|
||||||
|
Files.copy(in, targetDir.resolve(fileName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
- compiler.warn.source.no.bootclasspath: 10
|
- compiler.warn.source.no.system.modules.path: 10
|
||||||
VarInImplicitLambdaNegTest01.java:12:36: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.var.syntax.in.implicit.lambda), 10, 11
|
VarInImplicitLambdaNegTest01.java:12:36: compiler.err.feature.not.supported.in.source.plural: (compiler.misc.feature.var.syntax.in.implicit.lambda), 10, 11
|
||||||
VarInImplicitLambdaNegTest01.java:15:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.implicit.and.explicit.not.allowed)
|
VarInImplicitLambdaNegTest01.java:15:28: compiler.err.invalid.lambda.parameter.declaration: (compiler.misc.implicit.and.explicit.not.allowed)
|
||||||
VarInImplicitLambdaNegTest01.java:17:52: compiler.err.restricted.type.not.allowed.here: var
|
VarInImplicitLambdaNegTest01.java:17:52: compiler.err.restricted.type.not.allowed.here: var
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue