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

compile-time error for inherited abstract methods with throws conflict

    XMLWordPrintable

Details

    • sparc
    • solaris_2.5

    Description



      Name: apC46001 Date: 12/19/96


      JLS says [p. 167, 8.4.6.4 Inheriting Methods with the Same Signature]:

      "It is possible for a class to inherit more than one method with the same signature.
      Such a situation does not in itself cause a compile-time error.
      There are then two possible cases:
         ...
      If none of the inherited methods is not abstract, then the class is necessarily an
      abstract class and is considered to inherit all the abstract methods.
      A compile-time error occurs if, for any two such inherited methods, either they
      have different return types or one has a return type and the other is void.
      (The throws clauses do not cause errors in this case.)"
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      JDK 1.1 compiler produces unexpected error message for the correct java program.

      > javac -d . clss17901.java

      tests/lang/CLSS/clss179/clss17901/clss17901.java:14: Invalid exception class javasoft.sqe.tests.lang.clss179.clss17901.Ex2 in throws clause. The exception must be a subclass of an exception thrown by int m1() from interface javasoft.sqe.tests.lang.clss179.clss17901.clss17901_a.
      int m1() throws Ex2;
      ^
      tests/lang/CLSS/clss179/clss17901/clss17901.java:19: Invalid exception class javasoft.sqe.tests.lang.clss179.clss17901.Ex1 in throws clause. The exception must be a subclass of an exception thrown by int m1() from class javasoft.sqe.tests.lang.clss179.clss17901.clss17901_c.
      public int m1() throws Ex1 {
      ^
      tests/lang/CLSS/clss179/clss17901/clss17901.java:19: Invalid exception class javasoft.sqe.tests.lang.clss179.clss17901.Ex1 in throws clause. The exception must be a subclass of an exception thrown by int m1() from interface javasoft.sqe.tests.lang.clss179.clss17901.clss17901_b.
      public int m1() throws Ex1 {
      ^
      3 errors

      --------------------------clss17901.java------------------------------
      package javasoft.sqe.tests.lang.clss179.clss17901;


      import java.io.PrintStream;

      class Ex1 extends Exception {}
      class Ex2 extends Exception {}
      interface clss17901_a {
      int m1() throws Ex1;
      }
      interface clss17901_b {
      int m1() throws Ex2;
      }
      abstract class clss17901_c implements clss17901_b, clss17901_a {
      }
      class clss17901_d extends clss17901_c {
      public int m1() throws Ex1 {
      throw (new Ex1());
      }
      }

      public class clss17901 {
        public static void main(String argv[])
        {
           System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
        }
        public static int run(String argv[],PrintStream out) {
      clss17901_d x = new clss17901_d();
      try {
      x.m1();
      }
      catch (Exception Ex1) {
      return 0;
      }
      return 2;
        }
      }


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

      Attachments

        Issue Links

          Activity

            People

              tturnidgsunw Todd Turnidge (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: