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

Unchecked conversion is allowed by method type argument bound checking

    XMLWordPrintable

    Details

      Description

      The following compiles without error:

      <T extends Iterable<String>> void m(T arg) {}

      public void test(Iterable rawIterable) {
        this.<Iterable>m(rawIterable); // expected: error; actual: allowed
      }

      The same occurs if no explicit type argument is provided, because inference concludes T=Iterable:

      <T extends Iterable<String>> void m(T arg) {}

      public void test(Iterable rawIterable) {
        m(rawIterable); // expected: error; actual: allowed
      }

      Per JLS 15.12.2.2 and 15.12.2.3, this is incorrect: a raw type is _convertible to_ a parameterization of that type, but is not a _subtype of_ a parameterization of that type. The specification is clear that subtyping, not some more general conversion, is used to check method invocation bounds. So the method should not be considered applicable.

      Notably, there is an error if such a type argument is provided to a generic class:

      class C<T extends Iterable<String>> {}
      C<Iterable> c1 = null; // expected: error; actual: error

      The bug is present in all version of javac on my system, including 8 b104. (It is also present in Eclipse.)

        Attachments

          Activity

            People

            Assignee:
            dlsmith Dan Smith
            Reporter:
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: