Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6758881

(launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b38
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      The changes for Java Launcher 6742159, throws JavaRuntimeException,
      there are several tests which depend on NoClassDefFoundError. This
      must be thrown.

        Issue Links

          Activity

          Hide
          ksrini Kumar Srinivasan added a comment -
          BT2:EVALUATION

          yes,we need to maintain compatibility.
          Show
          ksrini Kumar Srinivasan added a comment - BT2:EVALUATION yes,we need to maintain compatibility.
          Hide
          tbell Tim Bell added a comment -
          BT2: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");
          + }
                   }
               }
          -}
          Show
          tbell Tim Bell added a comment - BT2: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"); + }          }      } -}

            People

            • Assignee:
              ksrini Kumar Srinivasan
              Reporter:
              ksrini Kumar Srinivasan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: