-
Bug
-
Resolution: Unresolved
-
P4
-
6u51, 7u5, 8
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.)
<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.)