Community
Participate
Working Groups
the attached code is flagged as an error, but it should just be a warning. 3.2(M6)
Created attachment 37907 [details] Code example of the problem the tgz is in the form of a project that has a single class that excercises the bug.
The cast issue is working fine nowadays, but there is an issue with bound check. import java.io.*; import java.util.*; public class X<T extends Closeable> implements Closeable { private T obj; public static <E> Collection<E> unwrap(Iterable<E> coll) { Collection<E> newColl = new ArrayList<E>(); for (E element : coll) if (element instanceof X) newColl.add(((X<E>)element).obj); // error, should be warning else newColl.add(element); return newColl; } public void close() throws IOException { obj.close(); } } ---------- 1. WARNING in X.java (at line 10) newColl.add(((X<E>)element).obj); // error, should be warning ^^^^^^^^^^^^^^^ Type safety: The cast from E to X<E> is actually checking against the erased type X ---------- 2. ERROR in X.java (at line 10) newColl.add(((X<E>)element).obj); // error, should be warning ^ Bound mismatch: The type E is not a valid substitute for the bounded parameter <T extends Closeable> of the type X<T> ---------- 2 problems (1 error, 1 warning)
Cast types do not seem to have their bound checked by javac. This is arguable, and this is an area where the spec is being reworked. e.g. ((X<String>)element) is not complained against. Post 3.2 (since not a recent regression, and need to figure what the spec is going to say).
defer
As of now 'LATER' and 'REMIND' resolutions are no longer supported. Please reopen this bug if it is still valid for you.