Bug 135319 - [1.5][compiler] generic cast produces error instead of warning.
Summary: [1.5][compiler] generic cast produces error instead of warning.
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.3   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-06 12:39 EDT by Chris Longfield CLA
Modified: 2009-08-30 02:38 EDT (History)
0 users

See Also:


Attachments
Code example of the problem (1.47 KB, application/octet-stream)
2006-04-06 12:40 EDT, Chris Longfield CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Longfield CLA 2006-04-06 12:39:01 EDT
the attached code is flagged as an error, but it should just be a warning. 3.2(M6)
Comment 1 Chris Longfield CLA 2006-04-06 12:40:31 EDT
Created attachment 37907 [details]
Code example of the problem

the tgz is in the form of a project that has a single class that excercises the bug.
Comment 2 Philipe Mulet CLA 2006-04-20 09:52:18 EDT
The cast issue is working fine nowadays, but there is an issue with bound check.
import java.io.*;
import java.util.*;

public class X<T extends Closeable> implements Closeable {
    private T obj;
    public static <E> Collection<E> unwrap(Iterable<E> coll) {
        Collection<E> newColl = new ArrayList<E>();
        for (E element : coll)
            if (element instanceof X)
                newColl.add(((X<E>)element).obj);  // error, should be warning
            else
                newColl.add(element);
        return newColl;
    }
    public void close() throws IOException {
        obj.close();
    }
}
----------
1. WARNING in X.java
 (at line 10)
        newColl.add(((X<E>)element).obj);  // error, should be warning
                    ^^^^^^^^^^^^^^^
Type safety: The cast from E to X<E> is actually checking against the erased type X
----------
2. ERROR in X.java
 (at line 10)
        newColl.add(((X<E>)element).obj);  // error, should be warning
                        ^
Bound mismatch: The type E is not a valid substitute for the bounded parameter <T extends Closeable> of the type X<T>
----------
2 problems (1 error, 1 warning)
Comment 3 Philipe Mulet CLA 2006-04-20 10:35:27 EDT
Cast types do not seem to have their bound checked by javac. This is arguable, and this is an area where the spec is being reworked.

e.g. ((X<String>)element)  is not complained against.

Post 3.2 (since not a recent regression, and need to figure what the spec is going to say).
Comment 4 Philipe Mulet CLA 2006-04-20 10:36:44 EDT
defer
Comment 5 Eclipse Webmaster CLA 2009-08-30 02:38:11 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.