Bug 95066 - [1.5][compiler] Wrong Cast Allowed
Summary: [1.5][compiler] Wrong Cast Allowed
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 critical (vote)
Target Milestone: 3.1 RC1   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-12 19:53 EDT by Carlos Aydos CLA
Modified: 2006-02-05 11:49 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 Carlos Aydos CLA 2005-05-12 19:53:14 EDT
The code underneath compiles when it should fail.
I tried it with M5 and M6.

public class TestCasting<S extends Comparable<S>> {
   public TestCasting() {
       S a = (S)(Integer)3; // this should fail
   }
}
Comment 1 Olivier Thomann CLA 2005-05-13 10:13:56 EDT
Still failing using M7 candidate.
Comment 2 Philipe Mulet CLA 2005-05-13 12:07:42 EDT
Added GenericTypeTest#test661-665.

Part of the issue was that when recursing on variable upper bound, it was
actually using the upper bound erasure, and the check for final type was not
strict enough.

Fixed
Comment 3 Frederic Fusier CLA 2005-05-27 10:09:10 EDT
Verified for 3.1 RC1 with build I20050527-0010.
Comment 4 Philipe Mulet CLA 2006-02-03 06:39:28 EST
Humm... actually I now think this code should be accepted, with unchecked warnings. Comparable<S> is not provably distinct from Comparable<Integer>.
Interestingly, removing the bounds on S declaration make javac accept this code.
Comment 5 Philipe Mulet CLA 2006-02-05 11:49:00 EST
Also see javac bugs in cast conversions:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6270087