Bug 74178 - [1.5] wrong errors when using type bounds
Summary: [1.5] wrong errors when using type bounds
Status: RESOLVED DUPLICATE of bug 74119
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.1 M4   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-09-17 10:20 EDT by Tom Hofmann CLA
Modified: 2004-11-10 11:35 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 Tom Hofmann CLA 2004-09-17 10:20:44 EDT
I20040914-gtk

(may be a dup of bug 74119, but not sure)

A super-bound type variable produces wrong errors, I believe:

public void write(List<? super Number> list) {
	
	list.add(new Integer(3));    // XXX should work
	list.add(new Double(3.4));   // XXX should work
	Number num= new Double(3.4);
	list.add(num);               // works
	list.add(new Object());      // XXX should fail
}


This code produces a ClassCastException:

void fail() {
	List<Number> numbers= new ArrayList<Number>();
	
	test.write(numbers);
		
	for(Number n: numbers) { // CCE when an Object comes back
		n.toString();
	}
}
Comment 1 Markus Keller CLA 2004-10-01 10:06:30 EDT
Looks like the subtype relationship check between the wildcard lower bound and
the argument's type should just go the other way 'round.
Comment 2 Frederic Fusier CLA 2004-10-27 13:05:05 EDT
With following test case:
import java.util.List;

public class Test {

public void write(List<? super Exception> list) {
	
  list.add(new RuntimeException());             // JDT fails, Javac works
  list.add(new IllegalMonitorStateException()); // JDT fails, Javac works
  Exception exc = new Exception();
  list.add(exc);                                // both works
  list.add(new Object());                       // JDT works, Javac fails
  list.add(new Throwable());                    // JDT works, Javac fails
  list.add(new Exception());                    // both works
}
}

javac reports following errors:

Test.java:11: cannot find symbol
symbol  : method add(java.lang.Object)
location: interface java.util.List<capture of ? super java.lang.Exception>
  list.add(new Object());                       // JDT works, Javac fails
      ^
Test.java:12: cannot find symbol
symbol  : method add(java.lang.Throwable)
location: interface java.util.List<capture of ? super java.lang.Exception>
  list.add(new Throwable());                    // JDT works, Javac fails
      ^
2 errors
Comment 3 Philipe Mulet CLA 2004-11-10 11:35:34 EST
We now accept all scenarii with recent tuning in wildcard compatibilities.
Added regression test: GenericTypeTest#test410

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