Community
Participate
Working Groups
3.2M5 gives no compile error. Javac does: [javac] C:\workspace33\intellisuite\gui\src\Bug.java:22: inconvertible types [javac] found : java.lang.ref.Reference<capture of ? extends java.lang.String> [javac] required: Bug.Soft [javac] cache.remove(((Soft)trash.remove()).key); [javac] ^ --------------------------- Bug.java --------------- import java.lang.ref.ReferenceQueue; import java.lang.ref.SoftReference; import java.util.Hashtable; class Bug { private static final Hashtable<Integer,Soft>cache=new Hashtable<Integer,Soft>(); private static final ReferenceQueue<String>trash=new ReferenceQueue<String>(); private static final class Soft extends SoftReference<String>{ int key; Soft(){ super(null); } } final Thread clean=new Thread("BigTableModel cleaner"){ @Override public void run(){ for(;;) try { cache.remove(((Soft)trash.remove()).key); } catch (final InterruptedException e) { return; } } }; }
Simpler example: import java.lang.ref.*; class Soft extends SoftReference<String> { Soft() { super(null); } } class Bug { void m(Reference<? extends String> remove) { Soft soft= (Soft) remove; } }
On the first example, javac 1.6 (b71) doesn't complain. We emit a type safety warning, but javac doesn't. ---------- 1. WARNING in d:\tests_sources\X.java (at line 24) cache.remove(((Soft)trash.remove()).key); ^^^^^^^^^^^^^^^^^^^^^^ Type safety: The cast from Reference<capture-of ? extends String> to X.Soft is actually checking against the erased type X.Soft ---------- For the second example, Eclipse and javac 1.6 reports an error. Could this be a bug in javac that has been fixed in 1.6 branch?
Tuned the code to not report unchecked cast warning. Added GenericTypeTest#test0958
Note: no error is expected here, and no warning either. Fixed
Verified for 3.2 M6 using build I20060329-0010.