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

15.12.2.6: Excessive erasure of return/thrown types is specified

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • tbd
    • 5.0, 7, 8
    • specification
    • None
    • Fix Understood

    Description

      Reading from JLS 15.12.2.6:

      "The result type of the chosen method is determined as follows: [...]
                o Otherwise, if unchecked conversion was necessary for the method to be applicable then the result type is the erasure (§4.6) of the method's declared return type.[...]"

      Moreover

      "The exception types of the throws clause of the chosen method are determined as follows:[...]
          * If unchecked conversion was necessary for the method to be applicable then the throws clause is composed of the erasure (§4.6) of the types in the method's declared throws clause."

      which means that the following programs should *not* compile

      Example 1.

      class Test<X> {
      X m(Class<X> c) {return null;}
      X x = m((Class)String.class);
      }

      Example 2.

      class Test {
         <T extends Throwable> void foo(Class<T> c, T t) throws T {}
         void test(Exception e) {
            try {
               foo((Class)String.class, e);
            } catch (Exception t) {}
         }
      }

      Example 3.

      class Test<T extends Throwable> {
         void foo(Class<T> c, T t) throws T {}
         void test(Exception e) {
            try {
               new Test<Exception>().foo((Class)String.class, e);
            } catch (Exception t) {}
         }
      }

      Attachments

        Issue Links

          Activity

            People

              dlsmith Dan Smith
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: