# HG changeset patch # User jlahoda # Date 1568796078 -7200 # Node ID dfd434203aa0cd839bb8f1fc61cacc624f1690a9 # Parent a45cce906207c77ac6e17730888e367e4d3eb11c 8228460: bootstrap class path not set in conjunction with -source 11 Summary: Ensuring implicit system module path is checked for the no-bootclasspath warning for -source >= 9. Reviewed-by: vromero diff -r a45cce906207 -r dfd434203aa0 src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java Tue Jul 23 16:52:38 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java Wed Sep 18 10:41:18 2019 +0200 @@ -198,6 +198,10 @@ return locations.isDefaultBootClassPath(); } + public boolean isDefaultSystemModulesPath() { + return locations.isDefaultSystemModulesPath(); + } + // @Override @DefinedBy(Api.COMPILER) public boolean handleOption(String current, Iterator remaining) { diff -r a45cce906207 -r dfd434203aa0 src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java Tue Jul 23 16:52:38 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/Locations.java Wed Sep 18 10:41:18 2019 +0200 @@ -94,6 +94,7 @@ import com.sun.tools.javac.util.Pair; import com.sun.tools.javac.util.StringUtils; +import static javax.tools.StandardLocation.SYSTEM_MODULES; import static javax.tools.StandardLocation.PLATFORM_CLASS_PATH; import static com.sun.tools.javac.main.Option.BOOT_CLASS_PATH; @@ -185,6 +186,12 @@ 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. * diff -r a45cce906207 -r dfd434203aa0 src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Tue Jul 23 16:52:38 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java Wed Sep 18 10:41:18 2019 +0200 @@ -565,8 +565,13 @@ boolean lintOptions = options.isUnset(Option.XLINT_CUSTOM, "-" + LintCategory.OPTIONS.option); if (lintOptions && source.compareTo(Source.DEFAULT) < 0 && !options.isSet(Option.RELEASE)) { if (fm instanceof BaseFileManager) { - if (((BaseFileManager) fm).isDefaultBootClassPath()) - log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name)); + if (source.compareTo(Source.JDK8) <= 0) { + if (((BaseFileManager) fm).isDefaultBootClassPath()) + log.warning(LintCategory.OPTIONS, Warnings.SourceNoBootclasspath(source.name)); + } else { + if (((BaseFileManager) fm).isDefaultSystemModulesPath()) + log.warning(LintCategory.OPTIONS, Warnings.SourceNoSystemModulesPath(source.name)); + } } } diff -r a45cce906207 -r dfd434203aa0 src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Tue Jul 23 16:52:38 2019 +0200 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Sep 18 10:41:18 2019 +0200 @@ -1866,6 +1866,10 @@ 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 compiler.warn.option.obsolete.source=\ source value {0} is obsolete and will be removed in a future release diff -r a45cce906207 -r dfd434203aa0 test/langtools/tools/javac/diags/examples/SourceNoSystemModulesPath.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/diags/examples/SourceNoSystemModulesPath.java Wed Sep 18 10:41:18 2019 +0200 @@ -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 { } diff -r a45cce906207 -r dfd434203aa0 test/langtools/tools/javac/options/BCPOrSystemNotSpecified.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/options/BCPOrSystemNotSpecified.java Wed Sep 18 10:41:18 2019 +0200 @@ -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 log; + List 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 log; + List 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)); + } + } + } + } + } +} diff -r a45cce906207 -r dfd434203aa0 test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01_source10.out --- a/test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01_source10.out Tue Jul 23 16:52:38 2019 +0200 +++ b/test/langtools/tools/javac/var_implicit_lambda/VarInImplicitLambdaNegTest01_source10.out Wed Sep 18 10:41:18 2019 +0200 @@ -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: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