Bug 83398

Summary: [compiler][1.5] compiler allows adding Object to List<? super Number>
Product: [Eclipse Project] JDT Reporter: Tom Hofmann <eclipse>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: dirk_baeumer, markus.kell.r, trevor
Version: 3.1   
Target Milestone: 3.1 M5   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:

Description Tom Hofmann CLA 2005-01-21 09:42:43 EST
I20050118

The following class compiles, but should not (javac complains):

package test1;

import java.util.List;

public class SuperAssignment {
    void method(List<? super Number> list) {
        list.add(new Object());   // should fail
        list.add(new Integer(3)); // correct
    }
}
Comment 1 Dirk Baeumer CLA 2005-01-25 06:50:50 EST
Philippe,

I encounter the same problem when implementing assigment compatibility accross
contexts. I fixed it by distingusish between isAssignmentCompatible and
isTypeArgumentCompatible because both need different rules:

List<? extens Number>= List<Integer> 

  but

? extends Number != Integer

List<? super Number>= List<Object>

  but

? super Number != Object
Comment 2 Dirk Baeumer CLA 2005-01-25 10:27:43 EST
Another case:

public class A<T extends Number> {
	List<? super T> lhs;
	List<? extends Number> rhs;
	{
		lhs.add(rhs.get(0));
	}
}

Javac rejects this
Comment 3 Dirk Baeumer CLA 2005-01-25 10:34:34 EST
Another case:

public class A<U extends Number> {
	List<? super Number> lhs;
	List<? super U> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 4 Dirk Baeumer CLA 2005-01-25 10:51:48 EST
public class A<U extends Number> {
	List<? super Integer> lhs;
	List<? extends Number> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 5 Dirk Baeumer CLA 2005-01-25 10:55:38 EST
import java.util.List;

public class A<U extends Number> {
	List<? super Number> lhs;
	List<? super Integer> rhs;
	{
		lhs.add(rhs.get(0));
	}
}
Comment 6 Philipe Mulet CLA 2005-01-27 17:07:16 EST
Added GenericTypeTest#test475-481.
Problem comes from wrong wildcard SUPER bound check implementation.
Indeed the parameterized type compared ok.

Fixed, thanks for all test cases (all exposing the same one issue)
Comment 7 Philipe Mulet CLA 2005-01-31 18:04:41 EST
*** Bug 84091 has been marked as a duplicate of this bug. ***
Comment 8 Jerome Lanneluc CLA 2005-02-15 06:38:15 EST
Verified in I20050214