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

generics specification breaks exception checking

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0, 6
    • specification
    • generic
    • generic, solaris_8

      Currently, the language provides no way to throw a checked excption without
      either catching it or declaring it to be thrown in the current method.
      (Notwithstanding a deprecated methon in Thread) The generics prototype
      introduces a way to throw a checked exception with only a warning, which
      is suppressed by default.

      I believe this is a serious regression in the language. We should not
      introduce such loopholes in type checking.

      class Main {
          static void hiddenThrow(Throwable t) {
              class ExceptionHider<E extends Throwable> {
                  void hiddenThrow(Throwable e) throws E {
                      throw (E) e;
                  }
              }
              new ExceptionHider<RuntimeException>().hiddenThrow(t);
          }
          public static void main(String[] args) // no exception in method declaration
          {
              hiddenThrow(new java.io.IOException()); // throws IOException, hidden
          }
      }

            abuckley Alex Buckley
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: