changeset 17149:13b7c6fdf864

8180447: Trailing space in JDK_JAVA_OPTIONS causes an application fail to launch Reviewed-by: alanb, mchung, ksrini
author henryjen
date Wed, 17 May 2017 16:26:23 -0700
parents 93b0c398e243
children 7efb352c6765
files src/java.base/share/native/libjli/args.c src/java.base/share/native/libjli/emessages.h test/tools/launcher/ArgsEnvVar.java
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/native/libjli/args.c	Wed May 17 14:29:26 2017 -0700
+++ b/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 == '\'') {
--- a/src/java.base/share/native/libjli/emessages.h	Wed May 17 14:29:26 2017 -0700
+++ b/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"
--- a/test/tools/launcher/ArgsEnvVar.java	Wed May 17 14:29:26 2017 -0700
+++ b/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 @@
         }
     }
 }
-