提交 c1e29c84 编写于 作者: K ksrini

6684582: Launcher needs improved error reporting

Summary: indicate the missing main class in the error message
Reviewed-by: darcy, kbr
上级 cf1b8f69
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
#define JAR_ERROR2 "Error: Unable to access jarfile %s" #define JAR_ERROR2 "Error: Unable to access jarfile %s"
#define JAR_ERROR3 "Error: Invalid or corrupt 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_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_ERROR3 "Error: No main method found in specified class.\n" GEN_ERROR
#define CLS_ERROR4 "Error: Main method not public\n" GEN_ERROR #define CLS_ERROR4 "Error: Main method not public\n" GEN_ERROR
......
/* /*
* 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -414,7 +414,7 @@ JavaMain(void * _args) ...@@ -414,7 +414,7 @@ JavaMain(void * _args)
mainClass = LoadClass(env, classname); mainClass = LoadClass(env, classname);
if(mainClass == NULL) { /* exception occured */ if(mainClass == NULL) { /* exception occured */
ReportExceptionDescription(env); ReportExceptionDescription(env);
ReportErrorMessage(CLS_ERROR1); ReportErrorMessage(CLS_ERROR1, classname);
goto leave; goto leave;
} }
(*env)->ReleaseStringUTFChars(env, mainClassName, classname); (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
...@@ -433,7 +433,7 @@ JavaMain(void * _args) ...@@ -433,7 +433,7 @@ JavaMain(void * _args)
mainClass = LoadClass(env, classname); mainClass = LoadClass(env, classname);
if(mainClass == NULL) { /* exception occured */ if(mainClass == NULL) { /* exception occured */
ReportExceptionDescription(env); ReportExceptionDescription(env);
ReportErrorMessage(CLS_ERROR1); ReportErrorMessage(CLS_ERROR1, classname);
goto leave; goto leave;
} }
(*env)->ReleaseStringUTFChars(env, mainClassName, classname); (*env)->ReleaseStringUTFChars(env, mainClassName, classname);
......
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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -33,8 +21,19 @@ import java.util.StringTokenizer; ...@@ -33,8 +21,19 @@ import java.util.StringTokenizer;
* have any questions. * 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 * A group of tests to ensure that arguments are passed correctly to
...@@ -113,12 +112,10 @@ public class Arrrghs{ ...@@ -113,12 +112,10 @@ public class Arrrghs{
return retval; return retval;
} }
private static boolean doExec0(ProcessBuilder pb, String expectedArguments) { private static boolean doExec0(ProcessBuilder pb, String expectedArguments) {
boolean retval = false; boolean retval = false;
try { try {
pb.redirectErrorStream(_debug); pb.redirectErrorStream(true);
Process p = pb.start(); Process p = pb.start();
retval = detectCookie(p.getInputStream(), expectedArguments); retval = detectCookie(p.getInputStream(), expectedArguments);
p.waitFor(); p.waitFor();
...@@ -167,7 +164,6 @@ public class Arrrghs{ ...@@ -167,7 +164,6 @@ public class Arrrghs{
} }
} }
if (_debug) System.out.println("Starting Arrrghs tests"); if (_debug) System.out.println("Starting Arrrghs tests");
// Basic test // Basic test
if (!doExec("-a -b -c -d")) exitValue++; if (!doExec("-a -b -c -d")) exitValue++;
......
#!/bin/sh #!/bin/sh
# @test Arrrghs.sh # @test Arrrghs.sh
# @bug 5030233 6214916 6356475 6571029 # @bug 5030233 6214916 6356475 6571029 6684582
# @build Arrrghs # @build Arrrghs
# @run shell Arrrghs.sh # @run shell Arrrghs.sh
# @summary Argument parsing validation. # @summary Argument parsing validation.
# @author Joseph E. Kowalski # @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. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -103,6 +103,44 @@ TestHelp() { ...@@ -103,6 +103,44 @@ TestHelp() {
fi fi
} }
#
# 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: # Main processing:
# #
...@@ -117,6 +155,7 @@ TestCP javac -cp ...@@ -117,6 +155,7 @@ TestCP javac -cp
TestCP javac -classpath TestCP javac -classpath
TestXUsage TestXUsage
TestHelp TestHelp
TestMissingMainClass
# #
# Tests for 6214916 # Tests for 6214916
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册