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
@ -1326,7 +1326,9 @@ ParseArguments(int *pargc, char ***pargv,
|
||||
JLI_StrCmp(arg, "-cp") == 0) {
|
||||
REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
|
||||
SetClassPath(value);
|
||||
mode = LM_CLASS;
|
||||
if (mode != LM_SOURCE) {
|
||||
mode = LM_CLASS;
|
||||
}
|
||||
} else if (JLI_StrCmp(arg, "--list-modules") == 0) {
|
||||
listModules = JNI_TRUE;
|
||||
} else if (JLI_StrCmp(arg, "--show-resolved-modules") == 0) {
|
||||
|
@ -82,21 +82,21 @@ launcher.error=\
|
||||
error:\u0020
|
||||
|
||||
launcher.err.no.args=\
|
||||
no filename
|
||||
no path for source file
|
||||
|
||||
# 0: string
|
||||
launcher.err.invalid.filename=\
|
||||
invalid filename: {0}
|
||||
invalid path for source file: {0}
|
||||
|
||||
# 0: path
|
||||
launcher.err.file.not.found=\
|
||||
file not found: {0}
|
||||
source file not found: {0}
|
||||
|
||||
launcher.err.compilation.failed=\
|
||||
compilation failed
|
||||
|
||||
launcher.err.no.class=\
|
||||
no class declared in file
|
||||
no class declared in source file
|
||||
|
||||
launcher.err.main.not.public.static=\
|
||||
''main'' method is not declared ''public static''
|
||||
@ -122,7 +122,7 @@ launcher.err.cant.access.main.method=\
|
||||
|
||||
# 0: path, 1: object
|
||||
launcher.err.cant.read.file=\
|
||||
error reading file {0}: {1}
|
||||
error reading source file {0}: {1}
|
||||
|
||||
# 0: string
|
||||
launcher.err.no.value.for.option=\
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8192920 8204588
|
||||
* @bug 8192920 8204588 8210275
|
||||
* @summary Test source mode
|
||||
* @modules jdk.compiler jdk.jlink
|
||||
* @run main SourceMode
|
||||
@ -251,6 +251,31 @@ public class SourceMode extends TestHelper {
|
||||
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
|
||||
@Test
|
||||
void testSourceNoArg() throws IOException {
|
||||
|
@ -229,7 +229,7 @@ public class SourceLauncherTest extends TestRunner {
|
||||
Files.createDirectories(base);
|
||||
Path file = base.resolve("NoClass.java");
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user