6684582: Launcher needs improved error reporting
authorksrini
Thu, 10 Apr 2008 09:02:22 -0700
changeset 399 bcc2354430ff
parent 301 6490d6bac748
child 400 9f3afee24320
child 401 ef01e0dccd63
6684582: Launcher needs improved error reporting Summary: indicate the missing main class in the error message Reviewed-by: darcy, kbr
jdk/src/share/bin/emessages.h
jdk/src/share/bin/java.c
jdk/test/tools/launcher/Arrrghs.java
jdk/test/tools/launcher/Arrrghs.sh
--- a/jdk/src/share/bin/emessages.h	Mon Apr 07 14:19:23 2008 -0700
+++ b/jdk/src/share/bin/emessages.h	Thu Apr 10 09:02:22 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2005-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -50,7 +50,7 @@
 #define JAR_ERROR2      "Error: Unable to access jarfile %s"
 #define JAR_ERROR3      "Error: Invalid or corrupt jarfile %s"
 
-#define CLS_ERROR1      "Error: Could not find the main class.\n" JNI_ERROR
+#define CLS_ERROR1      "Error: Could not find the main class %s.\n" JNI_ERROR
 #define CLS_ERROR2      "Error: Failed to load Main Class: %s\n%s"
 #define CLS_ERROR3      "Error: No main method found in specified class.\n" GEN_ERROR
 #define CLS_ERROR4      "Error: Main method not public\n" GEN_ERROR
--- a/jdk/src/share/bin/java.c	Mon Apr 07 14:19:23 2008 -0700
+++ b/jdk/src/share/bin/java.c	Thu Apr 10 09:02:22 2008 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright 1995-2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 1995-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -414,7 +414,7 @@
         mainClass = LoadClass(env, classname);
         if(mainClass == NULL) { /* exception occured */
             ReportExceptionDescription(env);
-            ReportErrorMessage(CLS_ERROR1);
+            ReportErrorMessage(CLS_ERROR1, classname);
             goto leave;
         }
         (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
@@ -433,7 +433,7 @@
       mainClass = LoadClass(env, classname);
       if(mainClass == NULL) { /* exception occured */
         ReportExceptionDescription(env);
-        ReportErrorMessage(CLS_ERROR1);
+        ReportErrorMessage(CLS_ERROR1, classname);
         goto leave;
       }
       (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
--- a/jdk/test/tools/launcher/Arrrghs.java	Mon Apr 07 14:19:23 2008 -0700
+++ b/jdk/test/tools/launcher/Arrrghs.java	Thu Apr 10 09:02:22 2008 -0700
@@ -1,17 +1,5 @@
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
+ * Copyright 2007-2008 Sun Microsystems, Inc.  All Rights Reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -33,8 +21,19 @@
  * have any questions.
  */
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
 
-public class Arrrghs{
+public class Arrrghs {
 
     /**
      * A group of tests to ensure that arguments are passed correctly to
@@ -113,12 +112,10 @@
         return retval;
     }
 
-
-
     private static boolean doExec0(ProcessBuilder pb, String expectedArguments) {
         boolean retval = false;
         try {
-            pb.redirectErrorStream(_debug);
+            pb.redirectErrorStream(true);
             Process p = pb.start();
             retval = detectCookie(p.getInputStream(), expectedArguments);
             p.waitFor();
@@ -167,7 +164,6 @@
             }
         }
 
-
         if (_debug) System.out.println("Starting Arrrghs tests");
         // Basic test
         if (!doExec("-a -b -c -d")) exitValue++;
--- a/jdk/test/tools/launcher/Arrrghs.sh	Mon Apr 07 14:19:23 2008 -0700
+++ b/jdk/test/tools/launcher/Arrrghs.sh	Thu Apr 10 09:02:22 2008 -0700
@@ -1,13 +1,13 @@
 #!/bin/sh
 # @test Arrrghs.sh
-# @bug 5030233 6214916 6356475 6571029
+# @bug 5030233 6214916 6356475 6571029 6684582
 # @build Arrrghs
 # @run shell Arrrghs.sh
 # @summary Argument parsing validation.
 # @author Joseph E. Kowalski
 
 #
-# Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
+# Copyright 2004-2008 Sun Microsystems, Inc.  All Rights Reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -104,6 +104,44 @@
 }
 
 #
+# Test to ensure that a missing main class is indicated in the error message
+#
+TestMissingMainClass() {
+	# First create a small jar file with no main
+        printf "public class Foo {}\n" > Foo.java
+	$TESTJAVA/bin/javac Foo.java
+	if [ $? -ne 0 ]; then
+		printf "Error: compilation of Foo.java failed\n" 
+ 		exit 1
+	fi
+	printf "Main-Class: Bar\n" > manifest
+	$TESTJAVA/bin/jar -cvfm some.jar manifest Foo.class
+	if [ ! -f some.jar ]; then
+		printf "Error: did not find some.jar\n" 
+ 		exit 1
+	fi
+
+	# test a non-existence main-class using -jar 
+	mess="`$TESTJAVA/bin/java -jar some.jar 2>&1 1>/dev/null`"
+	echo $mess | grep 'Bar' 2>&1 > /dev/null
+	if [ $? -ne 0 ]; then
+		printf "Error: did not find main class missing message\n"
+		exit 1
+	fi
+
+	# test a non-existent main-class using classpath
+	mess="`$TESTJAVA/bin/java -cp some.jar Bar 2>&1 1>/dev/null`"
+	echo $mess | grep 'Bar' 2>&1 > /dev/null
+	if [ $? -ne 0 ]; then
+		printf "Error: did not find main class missing message\n"
+		exit 1
+	fi
+
+	# cleanup
+	rm -f some.jar Foo.* manifest
+}
+
+#
 # Main processing:
 #
 
@@ -117,6 +155,7 @@
 TestCP javac -classpath
 TestXUsage
 TestHelp
+TestMissingMainClass
 
 #
 # Tests for 6214916