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

incorrect error message about unchecked exception in initializer

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      sparc
    • OS:
      solaris_2.5.1
    • Verification:
      Verified

      Description



      Name: dkC59003 Date: 01/08/98



      The section "11.2 Compile-Time Checking of Exceptions" of JLS says:
      "The unchecked exceptions classes are the class RuntimeException and its
      subclasses, and the class Error and its subclasses.
      ...
      Variable initializers for fields and static initializers must not result
      in a checked exception; if one does, a compile-time error occurs."

      The test below uses unchecked exceptions RuntimeException and Error that
      are thrown in variable initializers.
      While the case of RuntimeException is OK the case of Error causes compile-
      time error which does not conform with the specification.
      If "throws" clause in the method iniE is deleted the test compiles
      successfully but according to JLS an exception property "checked/unchecked"
      does not depend on whether it is included in any syntactic form or not.

      -----------------------------------------
      public class excp01304 {

      int i1 = iniR(2);
      int i2 = iniE(2);
        
      int iniR (int par) throws RuntimeException {
      if ( par == 2 )
      throw new RuntimeException();
      return 1;
      }
      int iniE (int par) throws Error {
      if ( par == 2 )
      throw new Error();
      return 1;
      }
      }
      -----------------------------------------

      JDK 1.0.2 through 1.2-beta3-A compiler outputs:

      excp01304.java:4: Exception java.lang.Error can't be thrown in initializer.
      int i2 = iniE(2);
      ^
      1 error
      -----------------------------------------

      Hook 5(hook5): test

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            tturnidgsunw Todd Turnidge (Inactive)
            Reporter:
            dkhukhrosunw Dmitry Khukhro (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: