Bug 97693 - [1.5][compiler] Unchecked generic cast gives false compiler error.
Summary: [1.5][compiler] Unchecked generic cast gives false compiler error.
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-31 15:53 EDT by Brian Miller CLA
Modified: 2006-06-09 07:05 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Miller CLA 2005-05-31 15:53:37 EDT
Eclipse3.1 M7 flagged this as a warning.  Sun's javac warns "Bug.java uses 
unchecked or unsafe operations."  But Eclipse3.1 RC1 falsely gives a compile 
error that says "Cannot cast from Bug.Implements to Comparable<Row>", even 
though all my J2SE 5.0 options are set to 'warning' in my Eclipse preferences.

Remove the seemingly insignificant 'final' keyword below, and the false 
compiler error suddenly changes to a warning.

--------------------------- Bug.java ----------------------
class Bug<Row> {
    static interface Interface extends Comparable<String>{}
    static final class Implements implements Interface{
        public int compareTo(String o) {return 0;}
    }
    void method (){
     ((Comparable<Row>)new Implements()).toString(); //COMPILER FALSE ERROR.
    }
}
Comment 1 Philipe Mulet CLA 2006-02-03 06:15:15 EST
Reproduced. Indeed our check is too strict.
Added GenericTypeTest#test899.

Problem comes from the class being final, which triggered an extra check, over constraining. 
Fixed in 3.2 stream.
Comment 2 Philipe Mulet CLA 2006-02-05 11:37:27 EST
Fixed
Comment 3 Philipe Mulet CLA 2006-02-05 11:46:48 EST
Actually, GenericTypeTest added is: test900.
Also tuned test661 corresponding to bug 95066.
Comment 4 Jerome Lanneluc CLA 2006-02-15 09:16:02 EST
Verified for 3.2 M5 using build I20060215-0010
Comment 5 Frederic Fusier CLA 2006-06-09 07:00:55 EDT
Verified that it has been backported to R3_2_maintenance stream.
Comment 6 Frederic Fusier CLA 2006-06-09 07:05:32 EDT
Sorry, in previous comment, you should obviously read 'R3_1_maintenance' instead...