8172215: java launcher no longer accepts -cp "" empty string

Reviewed-by: alanb, dholmes, psandoz
This commit is contained in:
Mandy Chung 2017-01-04 09:50:21 -08:00
parent 083c7c4176
commit 5a7ecc5b78
5 changed files with 36 additions and 18 deletions

View File

@ -1248,6 +1248,7 @@ ParseArguments(int *pargc, char ***pargv,
char *value = NULL;
int kind = GetOpt(&argc, &argv, &option, &value);
jboolean has_arg = value != NULL && JLI_StrLen(value) > 0;
jboolean has_arg_any_len = value != NULL;
/*
* Option to set main entry point
@ -1269,7 +1270,7 @@ ParseArguments(int *pargc, char ***pargv,
JLI_StrCCmp(arg, "--class-path=") == 0 ||
JLI_StrCmp(arg, "-classpath") == 0 ||
JLI_StrCmp(arg, "-cp") == 0) {
REPORT_ERROR (has_arg, ARG_ERROR1, arg);
REPORT_ERROR (has_arg_any_len, ARG_ERROR1, arg);
SetClassPath(value);
mode = LM_CLASS;
} else if (JLI_StrCmp(arg, "--list-modules") == 0 ||

View File

@ -35,7 +35,7 @@ import static org.testng.Assert.assertTrue;
/**
* Utility class for creating test modules.
*/
public class ModuleSourceBuilder {
public class ModuleInfoMaker {
private static String MODULE_INFO_JAVA = "module-info.java";
private static Pattern MODULE_PATTERN =
Pattern.compile("module\\s+((?:\\w+\\.)*)");
@ -45,7 +45,7 @@ public class ModuleSourceBuilder {
Pattern.compile("(?:public\\s+)?(?:class|enum|interface)\\s+(\\w+)");
private final Path dir;
public ModuleSourceBuilder(Path dir) {
public ModuleInfoMaker(Path dir) {
this.dir = dir;
}

View File

@ -27,7 +27,7 @@
* @summary Basic argument validation for --add-exports
* @library /lib/testlibrary
* @modules jdk.compiler
* @build AddExportsTestWarningError CompilerUtils ModuleSourceBuilder
* @build AddExportsTestWarningError CompilerUtils ModuleInfoMaker
* @build jdk.testlibrary.*
* @run testng AddExportsTestWarningError
*/
@ -59,7 +59,7 @@ public class AddExportsTestWarningError {
@BeforeTest
public void setup() throws Exception {
ModuleSourceBuilder builder = new ModuleSourceBuilder(SRC_DIR);
ModuleInfoMaker builder = new ModuleInfoMaker(SRC_DIR);
builder.writeJavaFiles("m1",
"module m1 { }",
"package p1; public class C1 { " +

View File

@ -27,7 +27,7 @@
* @summary Basic argument validation for --add-reads
* @library /lib/testlibrary
* @modules jdk.compiler
* @build AddReadsTestWarningError CompilerUtils ModuleSourceBuilder
* @build AddReadsTestWarningError CompilerUtils ModuleInfoMaker
* @build jdk.testlibrary.*
* @run testng AddReadsTestWarningError
*/
@ -59,7 +59,7 @@ public class AddReadsTestWarningError {
@BeforeTest
public void setup() throws Exception {
ModuleSourceBuilder builder = new ModuleSourceBuilder(SRC_DIR);
ModuleInfoMaker builder = new ModuleInfoMaker(SRC_DIR);
builder.writeJavaFiles("m1",
"module m1 { requires m4; }",
"package p1; public class C1 { " +

View File

@ -95,19 +95,20 @@ public class JavaClassPathTest {
public Object[][] classpath() {
return new Object[][]{
// true indicates that class path default to current working directory
{ "", "." },
{ "-Djava.class.path", "." },
{ "-Djava.class.path=", "" },
{ "-Djava.class.path=.", "." },
{ List.of(), "." },
{ List.of("-cp", ""), "" },
{ List.of("-cp", "."), "." },
{ List.of("-Djava.class.path"), "." },
{ List.of("-Djava.class.path="), "" },
{ List.of("-Djava.class.path=."), "." },
};
}
@Test(dataProvider = "classpath")
public void testUnnamedModule(String option, String expected) throws Throwable {
List<String> args = new ArrayList<>();
if (!option.isEmpty()) {
args.add(option);
}
public void testUnnamedModule(List<String> options, String expected)
throws Throwable
{
List<String> args = new ArrayList<>(options);
args.add(TEST_MAIN);
args.add(Boolean.toString(true));
args.add(expected);
@ -195,8 +196,12 @@ public class JavaClassPathTest {
}
private OutputAnalyzer execute(List<String> options) throws Throwable {
ProcessBuilder pb =
createJavaProcessBuilder(options.toArray(new String[0]));
ProcessBuilder pb = createJavaProcessBuilder(
options.stream()
.map(this::autoQuote)
.toArray(String[]::new)
);
Map<String,String> env = pb.environment();
// remove CLASSPATH environment variable
String value = env.remove("CLASSPATH");
@ -205,4 +210,16 @@ public class JavaClassPathTest {
.errorTo(System.out);
}
private static final boolean IS_WINDOWS
= System.getProperty("os.name").startsWith("Windows");
/*
* Autoquote empty string argument on Windows
*/
private String autoQuote(String arg) {
if (IS_WINDOWS && arg.isEmpty()) {
return "\"\"";
}
return arg;
}
}