Bug 84091 - [1.5] Eclipse compiler fails to catch type error with lower-bounded wildcard type argument
Summary: [1.5] Eclipse compiler fails to catch type error with lower-bounded wildcard ...
Status: RESOLVED DUPLICATE of bug 83398
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-01-31 16:24 EST by Trevor Robinson CLA
Modified: 2005-01-31 18:04 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Trevor Robinson CLA 2005-01-31 16:24:08 EST
Sample code:
----
import java.util.LinkedList;
import java.util.List;

public class SuperTest
{
    private static class C1
    {
    }

    public static void main(String[] args)
    {
        List<C1> l = new LinkedList<C1>();
        addObject(l);
        for (C1 c : l)
        {
            System.out.println(c);
        }
    }

    private static void addObject(List< ? super C1> l)
    {
        l.add(new Object());
    }
}
----
Eclipse 3.1M4 compiles this code without complaint, but javac correctly gives
the following error:

SuperTest.java:22: cannot find symbol
symbol  : method add(java.lang.Object)
location: interface java.util.List<capture of ? super SuperTest.C1>
        l.add(new Object());
         ^

Executing the Eclipse-compiled class shows the problem at runtime:

Exception in thread "main" java.lang.ClassCastException: java.lang.Object
	at SuperTest.main(SuperTest.java:14)

Eclipse will report an error if the lower bound (super C1) is removed:

Bound mismatch: The method add(?) of type List<?> is not applicable for the
arguments (Object). The wildcard parameter ? has no lower bound, and may
actually be more restrictive than argument Object
Comment 1 Philipe Mulet CLA 2005-01-31 18:04:40 EST

*** This bug has been marked as a duplicate of 83398 ***