# HG changeset patch # User henryjen # Date 1495063583 25200 # Node ID 6541159682578f01bdf41b089921a0440a82ecd9 # Parent f7d47a5e1e993651836c7969f12cc7986a6a76a8 8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch Reviewed-by: alanb, mchung, ksrini diff -r f7d47a5e1e99 -r 654115968257 jdk/src/java.base/share/native/libjli/args.c --- a/jdk/src/java.base/share/native/libjli/args.c Wed May 17 14:29:26 2017 -0700 +++ b/jdk/src/java.base/share/native/libjli/args.c Wed May 17 16:26:23 2017 -0700 @@ -456,6 +456,11 @@ env++; } + // Trailing space + if (*env == '\0') { + break; + } + arg = p; while (*env != '\0' && !isspace(*env)) { if (*env == '"' || *env == '\'') { diff -r f7d47a5e1e99 -r 654115968257 jdk/src/java.base/share/native/libjli/emessages.h --- a/jdk/src/java.base/share/native/libjli/emessages.h Wed May 17 14:29:26 2017 -0700 +++ b/jdk/src/java.base/share/native/libjli/emessages.h Wed May 17 16:26:23 2017 -0700 @@ -36,7 +36,7 @@ #define JNI_ERROR "Error: A JNI error has occurred, please check your installation and try again" #define JNI_ERROR1 "Error: can't find JNI interfaces in: %s" -#define ARG_INFO_ENVVAR "NOTE: Picked up the following options via %s:\n %s" +#define ARG_INFO_ENVVAR "NOTE: Picked up %s: %s" #define ARG_WARN "Warning: %s option is no longer supported." #define ARG_ERROR1 "Error: %s requires class path specification" diff -r f7d47a5e1e99 -r 654115968257 jdk/test/tools/launcher/ArgsEnvVar.java --- a/jdk/test/tools/launcher/ArgsEnvVar.java Wed May 17 14:29:26 2017 -0700 +++ b/jdk/test/tools/launcher/ArgsEnvVar.java Wed May 17 16:26:23 2017 -0700 @@ -23,7 +23,7 @@ /** * @test - * @bug 8170832 + * @bug 8170832 8180447 * @summary Arguments passed in environment variable * @build TestHelper * @run main ArgsEnvVar @@ -224,6 +224,21 @@ verifyOptions(List.of("-p", "?", "-jar", "test.jar", "one", "two"), tr); } + @Test + public void testTrailingSpaces() { + env.put(JDK_JAVA_OPTIONS, "--add-exports java.base/jdk.internal.misc=ALL-UNNAMED "); + TestResult tr = doExec(env, javaCmd, "-jar", "test.jar"); + verifyOptions(List.of("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", "-jar", "test.jar"), tr); + + env.put(JDK_JAVA_OPTIONS, "--class-path ' '"); + tr = doExec(env, javaCmd, "-jar", "test.jar"); + verifyOptions(List.of("--class-path", " ", "-jar", "test.jar"), tr); + + env.put(JDK_JAVA_OPTIONS, " --add-exports java.base/jdk.internal.misc=ALL-UNNAMED "); + tr = doExec(env, javaCmd, "-jar", "test.jar"); + verifyOptions(List.of("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED", "-jar", "test.jar"), tr); + } + public static void main(String... args) throws Exception { init(); ArgsEnvVar a = new ArgsEnvVar(); @@ -236,4 +251,3 @@ } } } -