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

generics specification breaks exception checking

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.4.0, 6
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic, solaris_8

      Description

      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
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                abuckley Alex Buckley
                Reporter:
                gafter Neal Gafter
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: