mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 11:04:34 +02:00
8210275: Source Launcher should fail if --source is used without a source file
Reviewed-by: mchung, alanb, mcimadamore
This commit is contained in:
parent
82ed2a5fc0
commit
8edf8e2b03
4 changed files with 35 additions and 8 deletions
|
@ -1326,7 +1326,9 @@ ParseArguments(int *pargc, char ***pargv,
|
||||||
JLI_StrCmp(arg, "-cp") == 0) {
|
JLI_StrCmp(arg, "-cp") == 0) {
|
||||||
REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
|
REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
|
||||||
SetClassPath(value);
|
SetClassPath(value);
|
||||||
mode = LM_CLASS;
|
if (mode != LM_SOURCE) {
|
||||||
|
mode = LM_CLASS;
|
||||||
|
}
|
||||||
} else if (JLI_StrCmp(arg, "--list-modules") == 0) {
|
} else if (JLI_StrCmp(arg, "--list-modules") == 0) {
|
||||||
listModules = JNI_TRUE;
|
listModules = JNI_TRUE;
|
||||||
} else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {
|
} else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {
|
||||||
|
|
|
@ -82,21 +82,21 @@ launcher.error=\
|
||||||
error:\u0020
|
error:\u0020
|
||||||
|
|
||||||
launcher.err.no.args=\
|
launcher.err.no.args=\
|
||||||
no filename
|
no path for source file
|
||||||
|
|
||||||
# 0: string
|
# 0: string
|
||||||
launcher.err.invalid.filename=\
|
launcher.err.invalid.filename=\
|
||||||
invalid filename: {0}
|
invalid path for source file: {0}
|
||||||
|
|
||||||
# 0: path
|
# 0: path
|
||||||
launcher.err.file.not.found=\
|
launcher.err.file.not.found=\
|
||||||
file not found: {0}
|
source file not found: {0}
|
||||||
|
|
||||||
launcher.err.compilation.failed=\
|
launcher.err.compilation.failed=\
|
||||||
compilation failed
|
compilation failed
|
||||||
|
|
||||||
launcher.err.no.class=\
|
launcher.err.no.class=\
|
||||||
no class declared in file
|
no class declared in source file
|
||||||
|
|
||||||
launcher.err.main.not.public.static=\
|
launcher.err.main.not.public.static=\
|
||||||
''main'' method is not declared ''public static''
|
''main'' method is not declared ''public static''
|
||||||
|
@ -122,7 +122,7 @@ launcher.err.cant.access.main.method=\
|
||||||
|
|
||||||
# 0: path, 1: object
|
# 0: path, 1: object
|
||||||
launcher.err.cant.read.file=\
|
launcher.err.cant.read.file=\
|
||||||
error reading file {0}: {1}
|
error reading source file {0}: {1}
|
||||||
|
|
||||||
# 0: string
|
# 0: string
|
||||||
launcher.err.no.value.for.option=\
|
launcher.err.no.value.for.option=\
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8192920 8204588
|
* @bug 8192920 8204588 8210275
|
||||||
* @summary Test source mode
|
* @summary Test source mode
|
||||||
* @modules jdk.compiler jdk.jlink
|
* @modules jdk.compiler jdk.jlink
|
||||||
* @run main SourceMode
|
* @run main SourceMode
|
||||||
|
@ -251,6 +251,31 @@ public class SourceMode extends TestHelper {
|
||||||
show(tr);
|
show(tr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// java --source N -cp ... HelloWorld
|
||||||
|
@Test
|
||||||
|
void testSourceClasspath() throws IOException {
|
||||||
|
starting("testSourceClasspath");
|
||||||
|
Path base = Files.createDirectories(Paths.get("testSourceClasspath"));
|
||||||
|
Path src = Files.createDirectories(base.resolve("src"));
|
||||||
|
Path srcfile = src.resolve("java.java");
|
||||||
|
createFile(srcfile, List.of(
|
||||||
|
"class HelloWorld {",
|
||||||
|
" public static void main(String... args) {",
|
||||||
|
" System.out.println(\"Hello World\");",
|
||||||
|
" }",
|
||||||
|
"}"
|
||||||
|
));
|
||||||
|
Path classes = base.resolve("classes");
|
||||||
|
compile("-d", classes.toString(), srcfile.toString());
|
||||||
|
TestResult tr =
|
||||||
|
doExec(javaCmd, "--source", thisVersion, "-cp", classes.toString(), "HelloWorld");
|
||||||
|
if (tr.isOK())
|
||||||
|
error(tr, "Command succeeded unexpectedly");
|
||||||
|
if (!tr.contains("file not found: HelloWorld"))
|
||||||
|
error(tr, "Expected output not found");
|
||||||
|
show(tr);
|
||||||
|
}
|
||||||
|
|
||||||
// java --source
|
// java --source
|
||||||
@Test
|
@Test
|
||||||
void testSourceNoArg() throws IOException {
|
void testSourceNoArg() throws IOException {
|
||||||
|
|
|
@ -229,7 +229,7 @@ public class SourceLauncherTest extends TestRunner {
|
||||||
Files.createDirectories(base);
|
Files.createDirectories(base);
|
||||||
Path file = base.resolve("NoClass.java");
|
Path file = base.resolve("NoClass.java");
|
||||||
Files.write(file, List.of("package p;"));
|
Files.write(file, List.of("package p;"));
|
||||||
testError(file, "", "error: no class declared in file");
|
testError(file, "", "error: no class declared in source file");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue