Bug 131935 - [1.5][compiler] Illegal generic conversion allowed.
Summary: [1.5][compiler] Illegal generic conversion allowed.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M6   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-03-15 09:50 EST by Brian Miller CLA
Modified: 2006-03-29 06:00 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Miller CLA 2006-03-15 09:50:07 EST
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;
                }
        }
    };
}
Comment 1 Markus Keller CLA 2006-03-15 11:06:25 EST
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;
    }
}
Comment 2 Olivier Thomann CLA 2006-03-15 11:13:22 EST
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?
Comment 3 Philipe Mulet CLA 2006-03-28 18:45:30 EST
Tuned the code to not report unchecked cast warning.
Added GenericTypeTest#test0958
Comment 4 Philipe Mulet CLA 2006-03-28 18:46:16 EST
Note: no error is expected here, and no warning either.
Fixed
Comment 5 Frederic Fusier CLA 2006-03-29 06:00:41 EST
Verified for 3.2 M6 using build I20060329-0010.