changeset 5327:f68c854fa584

7151434: java -jar -XX crashes java launcher Reviewed-by: mchung, darcy
author ksrini
date Tue, 24 Apr 2012 10:37:01 -0700
parents 2c35304e885a
children fcdbd1f34309
files src/share/bin/java.c test/tools/launcher/Arrrghs.java test/tools/launcher/TestHelper.java
diffstat 3 files changed, 48 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/bin/java.c	Tue Apr 24 21:06:16 2012 +0800
+++ b/src/share/bin/java.c	Tue Apr 24 10:37:01 2012 -0700
@@ -695,6 +695,13 @@
     char *def;
     const char *orig = s;
     static const char format[] = "-Djava.class.path=%s";
+    /*
+     * usually we should not get a null pointer, but there are cases where
+     * we might just get one, in which case we simply ignore it, and let the
+     * caller deal with it
+     */
+    if (s == NULL)
+        return;
     s = JLI_WildcardExpandClasspath(s);
     def = JLI_MemAlloc(sizeof(format)
                        - 2 /* strlen("%s") */
--- a/test/tools/launcher/Arrrghs.java	Tue Apr 24 21:06:16 2012 +0800
+++ b/test/tools/launcher/Arrrghs.java	Tue Apr 24 10:37:01 2012 -0700
@@ -24,7 +24,7 @@
 /**
  * @test
  * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
- *      6894719 6968053
+ *      6894719 6968053 7151314
  * @summary Argument parsing validation.
  * @compile -XDignore.symbol.file Arrrghs.java
  * @run main Arrrghs
@@ -237,6 +237,13 @@
         tr.checkNegative();
         tr.isNotZeroOutput();
         System.out.println(tr);
+
+        // 7151314, test for non-negative exit value for an incorrectly formed
+        // command line, '% java -jar -W', note the bogus -W
+        tr = doExec(javaCmd, "-jar", "-W");
+        tr.checkNegative();
+        tr.contains("Unrecognized option: -W");
+        System.out.println(tr);
     }
 
     /*
--- a/test/tools/launcher/TestHelper.java	Tue Apr 24 21:06:16 2012 +0800
+++ b/test/tools/launcher/TestHelper.java	Tue Apr 24 10:37:01 2012 -0700
@@ -21,6 +21,8 @@
  * questions.
  */
 
+import java.io.StringWriter;
+import java.io.PrintWriter;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileFilter;
@@ -87,6 +89,7 @@
     static final String EXE_FILE_EXT   = ".exe";
     static final String JLDEBUG_KEY     = "_JAVA_LAUNCHER_DEBUG";
     static final String EXPECTED_MARKER = "TRACER_MARKER:About to EXEC";
+    static final String TEST_PREFIX     = "###TestError###: ";
 
     static int testExitValue = 0;
 
@@ -376,7 +379,8 @@
      * of use methods to check the test results.
      */
     static class TestResult {
-        StringBuilder status;
+        PrintWriter status;
+        StringWriter sw;
         int exitValue;
         List<String> testOutput;
         Map<String, String> env;
@@ -384,27 +388,33 @@
 
         public TestResult(String str, int rv, List<String> oList,
                 Map<String, String> env, Throwable t) {
-            status = new StringBuilder("Executed command: " + str + "\n");
+            sw = new StringWriter();
+            status = new PrintWriter(sw);
+            status.println("Executed command: " + str + "\n");
             exitValue = rv;
             testOutput = oList;
             this.env = env;
             this.t = t;
         }
 
-        void appendStatus(String x) {
-            status = status.append("  " + x + "\n");
+        void appendError(String x) {
+            status.println(TEST_PREFIX + x);
+        }
+
+        void indentStatus(String x) {
+            status.println("  " + x);
         }
 
         void checkNegative() {
             if (exitValue == 0) {
-                appendStatus("Error: test must not return 0 exit value");
+                appendError("test must not return 0 exit value");
                 testExitValue++;
             }
         }
 
         void checkPositive() {
             if (exitValue != 0) {
-                appendStatus("Error: test did not return 0 exit value");
+                appendError("test did not return 0 exit value");
                 testExitValue++;
             }
         }
@@ -415,7 +425,7 @@
 
         boolean isZeroOutput() {
             if (!testOutput.isEmpty()) {
-                appendStatus("Error: No message from cmd please");
+                appendError("No message from cmd please");
                 testExitValue++;
                 return false;
             }
@@ -424,7 +434,7 @@
 
         boolean isNotZeroOutput() {
             if (testOutput.isEmpty()) {
-                appendStatus("Error: Missing message");
+                appendError("Missing message");
                 testExitValue++;
                 return false;
             }
@@ -433,22 +443,25 @@
 
         @Override
         public String toString() {
-            status.append("++++Begin Test Info++++\n");
-            status.append("++++Test Environment++++\n");
+            status.println("++++Begin Test Info++++");
+            status.println("++++Test Environment++++");
             for (String x : env.keySet()) {
-                status.append(x).append("=").append(env.get(x)).append("\n");
+                indentStatus(x + "=" + env.get(x));
             }
-            status.append("++++Test Output++++\n");
+            status.println("++++Test Output++++");
             for (String x : testOutput) {
-                appendStatus(x);
+                indentStatus(x);
             }
-            status.append("++++Test Stack Trace++++\n");
-            status.append(t.toString());
+            status.println("++++Test Stack Trace++++");
+            status.println(t.toString());
             for (StackTraceElement e : t.getStackTrace()) {
-                status.append(e.toString());
+                indentStatus(e.toString());
             }
-            status.append("++++End of Test Info++++\n");
-            return status.toString();
+            status.println("++++End of Test Info++++");
+            status.flush();
+            String out = sw.toString();
+            status.close();
+            return out;
         }
 
         boolean contains(String str) {
@@ -457,7 +470,7 @@
                     return true;
                 }
             }
-            appendStatus("Error: string <" + str + "> not found");
+            appendError("string <" + str + "> not found");
             testExitValue++;
             return false;
         }
@@ -468,7 +481,7 @@
                     return true;
                 }
             }
-            appendStatus("Error: string <" + stringToMatch + "> not found");
+            appendError("string <" + stringToMatch + "> not found");
             testExitValue++;
             return false;
         }