提交 2cc0c30d 编写于 作者: K ksrini

6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException

Summary: The launcher will throw the Error vs. Exception, also fixed some minor issues with the tests.
Reviewed-by: darcy
上级 b17cc21a
...@@ -176,10 +176,10 @@ public enum LauncherHelper { ...@@ -176,10 +176,10 @@ public enum LauncherHelper {
* @param isJar * @param isJar
* @param name * @param name
* @return * @return
* @throws java.lang.Exception * @throws java.io.IOException
*/ */
public static Object checkAndLoadMain(boolean printToStderr, public static Object checkAndLoadMain(boolean printToStderr,
boolean isJar, String name) throws Exception { boolean isJar, String name) throws IOException {
// get the class name // get the class name
String classname = (isJar) ? getMainClassFromJar(name) : name; String classname = (isJar) ? getMainClassFromJar(name) : name;
classname = classname.replace('/', '.'); classname = classname.replace('/', '.');
...@@ -190,7 +190,9 @@ public enum LauncherHelper { ...@@ -190,7 +190,9 @@ public enum LauncherHelper {
clazz = loader.loadClass(classname); clazz = loader.loadClass(classname);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
ostream.println(getLocalizedMessage("java.launcher.cls.error1", classname)); ostream.println(getLocalizedMessage("java.launcher.cls.error1", classname));
throw new RuntimeException("Could not find the main class " + classname); NoClassDefFoundError ncdfe = new NoClassDefFoundError(classname);
ncdfe.initCause(cnfe);
throw ncdfe;
} }
signatureDiagnostic(ostream, clazz); signatureDiagnostic(ostream, clazz);
return clazz; return clazz;
......
...@@ -23,10 +23,10 @@ ...@@ -23,10 +23,10 @@
/** /**
* @test * @test
* @compile -XDignore.symbol.file Arrrghs.java TestHelper.java * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600
* @run main Arrrghs
* @summary Argument parsing validation. * @summary Argument parsing validation.
* @compile Arrrghs.java TestHelper.java
* @run main Arrrghs
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -235,11 +235,13 @@ public class Arrrghs { ...@@ -235,11 +235,13 @@ public class Arrrghs {
TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"), TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"),
(String[])null); (String[])null);
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar");
tr.contains("MIA"); tr.contains("Error: Could not find main class MIA");
tr.contains("java.lang.NoClassDefFoundError: MIA");
System.out.println(tr); System.out.println(tr);
// use classpath to check // use classpath to check
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA"); tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA");
tr.contains("Error: Could not find main class MIA"); tr.contains("Error: Could not find main class MIA");
tr.contains("java.lang.NoClassDefFoundError: MIA");
System.out.println(tr); System.out.println(tr);
// incorrect method access // incorrect method access
...@@ -316,14 +318,14 @@ public class Arrrghs { ...@@ -316,14 +318,14 @@ public class Arrrghs {
*/ */
public static void main(String[] args) throws FileNotFoundException { public static void main(String[] args) throws FileNotFoundException {
if (TestHelper.debug) System.out.println("Starting Arrrghs tests"); if (TestHelper.debug) System.out.println("Starting Arrrghs tests");
quoteParsingTests(); quoteParsingTests();
runBasicErrorMessageTests(); runBasicErrorMessageTests();
runMainMethodTests(); runMainMethodTests();
if (TestHelper.testExitValue > 0) { if (TestHelper.testExitValue > 0) {
System.out.println("Total of " + TestHelper.testExitValue + " failed"); System.out.println("Total of " + TestHelper.testExitValue + " failed");
System.exit(1); System.exit(1);
} else { } else {
System.out.println("All tests pass"); System.out.println("All tests pass");
}
} }
} }
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册