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

Extra throws are allowed in overriding methods.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.7, 1.2.0
    • tools
    • generic
    • generic


      allan.jacobs@Eng 1998-09-17

      algol% setenv JDK /net/mulder.eng/export/mulder3/jdk12x/sparc/jdk1.2FCS_J
      algol% ${JDK}/bin/java -fullversion
      java full version "JDK-1.2fcs-J"
      algol% uname -a
      SunOS algol 5.6 Generic sun4u sparc SUNW,Ultra-2
      algol% ${JDK}/bin/javac -d . X.java
      algol% ${JDK}/bin/java X
      java.lang.NullPointerException
      java.lang.IllegalArgumentException

      algol% cat X.java

      class A {
      void s(int i) throws NullPointerException {
              throw new NullPointerException();
      }
      }
      public class X extends A {
      public static void main( String[] argv ) {
              X ob = new X();
              try { ob.s(0); }
              catch (Exception e) { System.out.println(e); }
              try { ob.s(1); }
              catch (Exception e) { System.out.println(e); }
      }
      void s(int i) throws NullPointerException,IllegalArgumentException {
              if (i==0) throw new NullPointerException();
              else if (i==1) throw new IllegalArgumentException();
      }
      }


      The code X.java should generate a compile-time error. The relevant section in the
      JLS is 8.4.4.
      "A method that overrides or hides another method (s8.4.6), including methods that
      implement abstract methods defined in interfaces, may not be declared to throw more
      checked exceptions thatn the overriden or hidden method."

      The bug was discovered using Plum Hall test jvs/ch8neg/j844p51a_z.


      allan.jacobs@Eng 1998-09-17
      Also in JDK1.1.7J.

            tturnidgsunw Todd Turnidge (Inactive)
            ajacobssunw Allan Jacobs (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: