-
Bug
-
Resolution: Unresolved
-
P4
-
6u65, 7u51, 8u60, 9
The below test exercises the clause in JLS 18.5.2 stating that, where unchecked conversion was necessary for the arguments, the return type of the invocation must be erased.
<T> T m(Class<T> arg1, Class<T> arg2) { return null; }
void test(Class c1, Class<Class<String>> c2) throws Exception {
m(c1, c2).newInstance(); // expected: error; actual: ok
m(c1, c2).newInstance().length(); // expected: error; actual: error
}
The erasure of the return type, T, is Object. However, javac seems to be producing raw Class instead. It appears that javac is inferring T=Class<String>, performing substitution on the return type, and *then* erasing to raw Class. This is inconsistent with the spec, going back to JLS 3 (15.12.2.6), which makes clear that substitution of inference results only occurs in the case in which unchecked conversion was not necessary.
<T> T m(Class<T> arg1, Class<T> arg2) { return null; }
void test(Class c1, Class<Class<String>> c2) throws Exception {
m(c1, c2).newInstance(); // expected: error; actual: ok
m(c1, c2).newInstance().length(); // expected: error; actual: error
}
The erasure of the return type, T, is Object. However, javac seems to be producing raw Class instead. It appears that javac is inferring T=Class<String>, performing substitution on the return type, and *then* erasing to raw Class. This is inconsistent with the spec, going back to JLS 3 (15.12.2.6), which makes clear that substitution of inference results only occurs in the case in which unchecked conversion was not necessary.
- relates to
-
JDK-6791481 15.12.2.6: Excessive erasure of return/thrown types is specified
- Open
-
JDK-8174249 Regression in generic method unchecked calls
- Closed