8231863: Crash if classpath is read from @argument file and the main gets option argument
Reviewed-by: alanb, mchung
This commit is contained in:
parent
a4c01b3c46
commit
f390c87d8d
@ -337,7 +337,9 @@ static JLI_List readArgFile(FILE *file) {
|
||||
// remaining partial token
|
||||
if (ctx.state == IN_TOKEN || ctx.state == IN_QUOTE) {
|
||||
if (ctx.parts->size != 0) {
|
||||
JLI_List_add(rv, JLI_List_combine(ctx.parts));
|
||||
token = JLI_List_combine(ctx.parts);
|
||||
checkArg(token);
|
||||
JLI_List_add(rv, token);
|
||||
}
|
||||
}
|
||||
JLI_List_free(ctx.parts);
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8027634
|
||||
* @bug 8027634 8231863
|
||||
* @summary Argument parsing from file
|
||||
* @modules jdk.compiler
|
||||
* jdk.zipfs
|
||||
@ -61,13 +61,17 @@ public class ArgsFileTest extends TestHelper {
|
||||
env.put(JLDEBUG_KEY, "true");
|
||||
}
|
||||
|
||||
private File createArgFile(String fname, List<String> lines) throws IOException {
|
||||
private File createArgFile(String fname, List<String> lines, boolean endWithNewline) throws IOException {
|
||||
File argFile = new File(fname);
|
||||
argFile.delete();
|
||||
createAFile(argFile, lines);
|
||||
createAFile(argFile, lines, endWithNewline);
|
||||
return argFile;
|
||||
}
|
||||
|
||||
private File createArgFile(String fname, List<String> lines) throws IOException {
|
||||
return createArgFile(fname, lines, true);
|
||||
}
|
||||
|
||||
private void verifyOptions(List<String> args, TestResult tr) {
|
||||
if (args.isEmpty()) {
|
||||
return;
|
||||
@ -266,6 +270,23 @@ public class ArgsFileTest extends TestHelper {
|
||||
userArgs.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userApplicationWithoutEmptyLastLine() throws IOException {
|
||||
File cpOpt = createArgFile("cpOpt", Arrays.asList("-classpath ."), false);
|
||||
File vmArgs = createArgFile("vmArgs", Arrays.asList("-Xint"), false);
|
||||
|
||||
TestResult tr = doExec(env, javaCmd, "-cp", "test.jar", "@cpOpt", "Foo", "-test");
|
||||
verifyOptions(Arrays.asList("-cp", "test.jar", "-classpath", ".", "Foo", "-test"), tr);
|
||||
verifyUserArgs(Arrays.asList("-test"), tr, 6);
|
||||
|
||||
tr = doExec(env, javaCmd, "-cp", "test.jar", "@vmArgs", "Foo", "-test");
|
||||
verifyOptions(Arrays.asList("-cp", "test.jar", "-Xint", "Foo", "-test"), tr);
|
||||
verifyUserArgs(Arrays.asList("-test"), tr, 5);
|
||||
|
||||
cpOpt.delete();
|
||||
vmArgs.delete();
|
||||
}
|
||||
|
||||
// test with missing file
|
||||
@Test
|
||||
public void missingFileNegativeTest() throws IOException {
|
||||
|
@ -349,12 +349,23 @@ public class TestHelper {
|
||||
* occurs then back off for a moment and try again. When a number of
|
||||
* attempts fail, give up and throw an exception.
|
||||
*/
|
||||
void createAFile(File aFile, List<String> contents) throws IOException {
|
||||
void createAFile(File aFile, List<String> lines) throws IOException {
|
||||
createAFile(aFile, lines, true);
|
||||
}
|
||||
|
||||
void createAFile(File aFile, List<String> lines, boolean endWithNewline) throws IOException {
|
||||
IOException cause = null;
|
||||
for (int attempts = 0; attempts < 10; attempts++) {
|
||||
try {
|
||||
Files.write(aFile.getAbsoluteFile().toPath(), contents,
|
||||
Charset.defaultCharset(), CREATE, TRUNCATE_EXISTING, WRITE);
|
||||
if (endWithNewline) {
|
||||
Files.write(aFile.getAbsoluteFile().toPath(),
|
||||
lines, Charset.defaultCharset(),
|
||||
CREATE, TRUNCATE_EXISTING, WRITE);
|
||||
} else {
|
||||
Files.write(aFile.getAbsoluteFile().toPath(),
|
||||
String.join(System.lineSeparator(), lines).getBytes(Charset.defaultCharset()),
|
||||
CREATE, TRUNCATE_EXISTING, WRITE);
|
||||
}
|
||||
if (cause != null) {
|
||||
/*
|
||||
* report attempts and errors that were encountered
|
||||
|
Loading…
Reference in New Issue
Block a user