-
Bug
-
Resolution: Unresolved
-
P4
-
6u16, 6u65, 7u51, 8
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Compiler fails to infer the correct type of a wildcard capture. Given a class A<T extends A<T>> with a method T get(), the compiler should be able to infer that the return type when calling get() on an instance of A<?> is <T extends A<T>>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successfully compiles.
ACTUAL -
Compile fails with error:
Test.java:10: <T>f1(T) in Test cannot be applied to (Test.A<capture#282 of ?>)
f1(obj.get()); // Fails to compile
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
class A<T extends A<T>> {
T get() {return null;}
}
<T extends A<T>> void f1(T t) {}
<T extends A<?>> void f2(T t) {}
void main(A<?> obj) {
f1(obj.get()); // Fails to compile
f2(obj.get()); // Works
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use method f2 instead of f1.
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
Compiler fails to infer the correct type of a wildcard capture. Given a class A<T extends A<T>> with a method T get(), the compiler should be able to infer that the return type when calling get() on an instance of A<?> is <T extends A<T>>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
javac Test.java
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successfully compiles.
ACTUAL -
Compile fails with error:
Test.java:10: <T>f1(T) in Test cannot be applied to (Test.A<capture#282 of ?>)
f1(obj.get()); // Fails to compile
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class Test {
class A<T extends A<T>> {
T get() {return null;}
}
<T extends A<T>> void f1(T t) {}
<T extends A<?>> void f2(T t) {}
void main(A<?> obj) {
f1(obj.get()); // Fails to compile
f2(obj.get()); // Works
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Use method f2 instead of f1.
- duplicates
-
JDK-8172222 javac does not verify generics usage correctly when wrapped in an additional type
-
- Closed
-
- relates to
-
JDK-6391995 REGRESSION: removal of "rvalue conversion" causes problems
-
- Closed
-
-
JDK-8039214 Inference should not map capture variables to their upper bounds
-
- Closed
-
-
JDK-7190296 unsoundness in type-containment implementation
-
- Closed
-