JDK-6758881 : (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
  • Type: Bug
  • Component: tools
  • Sub-Component: launcher
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-10-13
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b38Fixed
Related Reports
Relates :  
Description
The changes for Java Launcher 6742159, throws JavaRuntimeException,
there are several tests which depend on NoClassDefFoundError. This
must be thrown.

Comments
SUGGESTED FIX Fix provided by ###@###.###: # HG changeset patch # User ksrini # Date 1224014550 25200 # Node ID cd84ce70f4825d9cf83442385461c786be8c3612 # Parent 214ebdcf7252d4862449fe0ae295e6c60a127315 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 diff --git a/src/share/classes/sun/launcher/LauncherHelper.java b/src/share/classes/sun/launcher/LauncherHelper.java --- a/src/share/classes/sun/launcher/LauncherHelper.java +++ b/src/share/classes/sun/launcher/LauncherHelper.java @@ -176,10 +176,10 @@ public enum LauncherHelper { * @param isJar * @param name * @return - * @throws java.lang.Exception + * @throws java.io.IOException */ public static Object checkAndLoadMain(boolean printToStderr, - boolean isJar, String name) throws Exception { + boolean isJar, String name) throws IOException { // get the class name String classname = (isJar) ? getMainClassFromJar(name) : name; classname = classname.replace('/', '.'); @@ -190,7 +190,9 @@ public enum LauncherHelper { clazz = loader.loadClass(classname); } catch (ClassNotFoundException cnfe) { 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); return clazz; diff --git a/test/tools/launcher/Arrrghs.java b/test/tools/launcher/Arrrghs.java --- a/test/tools/launcher/Arrrghs.java +++ b/test/tools/launcher/Arrrghs.java @@ -23,10 +23,10 @@ /** * @test - * @compile -XDignore.symbol.file Arrrghs.java TestHelper.java - * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 + * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 + * @summary Argument parsing validation. + * @compile Arrrghs.java TestHelper.java * @run main Arrrghs - * @summary Argument parsing validation. */ import java.io.BufferedReader; @@ -235,11 +235,13 @@ public class Arrrghs { TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"), (String[])null); 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); // use classpath to check tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA"); tr.contains("Error: Could not find main class MIA"); + tr.contains("java.lang.NoClassDefFoundError: MIA"); System.out.println(tr); // incorrect method access @@ -316,14 +318,14 @@ public class Arrrghs { */ public static void main(String[] args) throws FileNotFoundException { if (TestHelper.debug) System.out.println("Starting Arrrghs tests"); - quoteParsingTests(); - runBasicErrorMessageTests(); - runMainMethodTests(); - if (TestHelper.testExitValue > 0) { - System.out.println("Total of " + TestHelper.testExitValue + " failed"); - System.exit(1); - } else { - System.out.println("All tests pass"); + quoteParsingTests(); + runBasicErrorMessageTests(); + runMainMethodTests(); + if (TestHelper.testExitValue > 0) { + System.out.println("Total of " + TestHelper.testExitValue + " failed"); + System.exit(1); + } else { + System.out.println("All tests pass"); + } } } -}
17-10-2008

EVALUATION yes,we need to maintain compatibility.
13-10-2008