Bug 90437 - [1.5][compiler] Casting with Erasure generates warning in Eclipse but ERROR with JDK
Summary: [1.5][compiler] Casting with Erasure generates warning in Eclipse but ERROR w...
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.4 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-04-06 08:20 EDT by Volker Renneberg CLA
Modified: 2007-10-29 06:10 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 Volker Renneberg CLA 2005-04-06 08:20:55 EDT
Hi!

The following code compiles in eclipse with a warning, but under JDK 1.5 
(Update 2) it fails with an error:
public class TypeConversion {

    public interface SuperInterface<A> {
    }

    public interface SubInterface extends SuperInterface<String> {
        public String getString();
    }

    private SuperInterface< ? extends SuperInterface> x = null;

    public void f() {
        ((SubInterface) this.x).getString();
    }
}

The problem is line "((SubInterface) this.x).getString();"
****
Eclipse 3.1M6 says (warning)
Type safety: The cast from TypeConversion.SuperInterface<? extends 
TypeConversion.
 SuperInterface> to TypeConversion.SubInterface is actually checking against 
the erased type 
 TypeConversion.SubInterface

****
JDK 1.5 javac says:
imconvertible types found: 
TypeConversion.SuperInterface<capture of ? extends 
TypeConversion.SuperInterface>
required: TypeConversion.SubInterface
****

ciao
Volker
Comment 1 Philipe Mulet CLA 2005-04-15 11:09:35 EDT
I believe we are right. Casting to a raw type should always be fine.
Comment 2 Tim Hanson CLA 2005-06-08 13:06:59 EDT
This is a javac bug. See Bug Parade 6282460. 

Philippe, do you want to close this?
Comment 3 Philipe Mulet CLA 2005-06-08 17:52:11 EDT
Thanks for confirming Tim.

Added GenericTypeTest#test730.
Closing as invalid.
Comment 4 Philipe Mulet CLA 2007-09-27 09:24:49 EDT
The casting rules are being discussed to become more strict near provable distinctness of types.
Hence, the original scenario would need to be rejected, since the bounds would be considered and thus:

SuperInterface< ? extends SuperInterface>
could be proven distinct from
SuperInterface<String>

Reopening for further consideration
Comment 5 Philipe Mulet CLA 2007-10-09 16:37:08 EDT
Fixed along with changes released with bug 158870.
Released for 3.4M3.
Fixed
Comment 6 Maxime Daniel CLA 2007-10-29 06:10:25 EDT
Verified for 3.4 M3 using build I20071029-0010.