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

The compiler needs to be aligned with clarified specification of throws

XMLWordPrintable

    • b136
    • generic
    • generic
    • Verified

      The compiler fails to reject this program:

      import java.io.*;

      class T6412514 {
          void f() {
              try {
                  throw new FileNotFoundException();
              } catch (FileNotFoundException x) {
              } catch (IOException x) { // ERROR
                  /*
                    It is a compile-time error if a catch clause catches checked
                    exception type E1 but there exists no checked exception type
                    E2 such that all of the following hold:
                    * E2 <: E1
                    * The try block corresponding to the catch clause can throw E2
                    * No preceding catch block of the immediately enclosing try
                    statement catches E2 or a supertype of E2.
                  */
              }
          }
      }

      It is actually correct according to the specification. However, the specification
      requires this version to be rejected:

      void f() {
          try {
              throw new IOException();
          } catch (IOException ex) {
          }
      }

      The specification issue is tracked in 6412514.

            mcimadamore Maurizio Cimadamore
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: