Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8047378 | OpenJDK6 | Ivan Krylov | P3 | Closed | Fixed |
The following demonstrates a bug in javac's handling of wildcard types that results in a hole in the type system. javac accepts this program without even a warning but it blows up with a class cast error at runtime. The Java compiler for Eclipse rejects this code.
import java.util.*;
class Comp {
static <T> Comparator<T> compound(final Iterable<? extends Comparator<? super T>> it) {
return new Comparator<T>() {
public int compare(T t1, T t2) {
for (Comparator<? super T> c : it) {
int r = c.compare(t1, t2);
if (r != 0) return r;
}
return 0;
}
};
}
public static void main(String[] args) {
List<Comparator<?>> x = new ArrayList<Comparator<?>>();
Comparator<Integer> c1 = new Comparator<Integer>() {
public int compare(Integer i1, Integer i2) {
return i1.compareTo(i2);
}
};
x.add(c1);
x.add(String.CASE_INSENSITIVE_ORDER);
Comparator<String> c3 = compound(x);
c3.compare("foo", "bar");
}
}
- backported by
-
JDK-8047378 Inference with wildcard types causes selection of inapplicable method
- Closed
- duplicates
-
JDK-6795689 javac can produce type-unsafe programs without any warning
- Closed
-
JDK-7010452 Unsafe generic assignment permitted by the compiler
- Closed
- relates to
-
JDK-6556624 Fails to accept program with Tj <: A constraint
- Closed
-
JDK-6650759 Inference of formal type parameter (unused in formal parameters) is not performed
- Closed
-
JDK-6862521 closed/javax/swing/JTable/sorting/UnitTest.java test fails with invalid inferred types.
- Closed
-
JDK-6785112 Umbrella: issues with generic method type-inference
- Closed
-
JDK-6863667 (ch) Several tests in java/nio/channels/* need to be updated after 6638712
- Closed
-
JDK-6707034 javac accepts method invocation with actuals that are not subtypes of the formal
- Closed
-
JDK-6730468 javac infers inapplicable method
- Closed
-
JDK-6452148 wrong type checking with lower bounded wildcard
- Closed
-
JDK-6640435 inference: propagate >> and == constraints to help uninferred type vars
- Closed