Bug 90879 - [1.5][compiler] Cannot sort a raw Comparable
Summary: [1.5][compiler] Cannot sort a raw Comparable
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.1 M7   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 84284 90430 94701 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-08 19:00 EDT by Tim Hanson CLA
Modified: 2005-05-11 11:49 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Hanson CLA 2005-04-08 19:00:28 EDT
The following example fails to compile producing the following diagnostic:

Severity	Description	Resource	In Folder	Location	Creation Time
2	Bound mismatch: The generic method sort(List<T>) of type Collections is not
applicable for the arguments (List<X>) since the type X is not a valid
substitute for the bounded parameter <T extends Comparable<? super T>>	X.java
Test/src	line 15	April 8, 2005 3:57:50 PM

javac compiles without a problem.

import java.util.*;

class X implements Comparable {

	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}
    
}

class Y {
	public static void main(String[] args) {
		List<X> lx = null;
		Collections.sort(lx);
	}
}
Comment 1 Tim Hanson CLA 2005-04-12 19:46:44 EDT
As I have investigated this further it's not clear to me that Eclipse has the
wrong behaviour. Since 15.12.2.2 requires that X <: Comparable<? super X>, which
it is not.

It's possible my JLS3 is out of date. The one I have is dated 8/16/04. I'll
investigate further.
Comment 2 Philipe Mulet CLA 2005-04-14 06:17:43 EDT
This is related to fix for bug 86838. I introduced a limitation in bound check
preventing raw type to be a good match to a non-raw bound.

Comment 3 Philipe Mulet CLA 2005-04-14 07:03:48 EDT
I suspect javac treats differently variable bound check for type or method:
import java.util.*;

public class X implements Comparable {
	public static void main(String[] args) {
		List<X> lx = null;
		sort1(lx);
		sort2(lx);
		sort3(lx);
		sort4(lx);
		sort5(lx);

		S1<X> s1;
		S2<X> s2;
		S3<X> s3;
		S4<X> s4;
		S5<X> s5;
	}
	public int compareTo(Object o) {
		return 0;
	}
	static <T extends Comparable<? super T>> void sort1(List<T> list) {}
	static <T extends Comparable<? extends T>> void sort2(List<T> list) {}
	static <T extends Comparable<?>> void sort3(List<T> list) {}
	static <T extends Comparable<T>> void sort4(List<T> list) {}
	static <T extends Comparable> void sort5(List<T> list) {}
}

class S1<T extends Comparable<? super T>> {}
class S2<T extends Comparable<? extends T>> {}
class S3<T extends Comparable<?>> {}
class S4<T extends Comparable<T>> {}
class S5<T extends Comparable> {}

==========
X.java:8: warning: [unchecked] unchecked method invocation:
<T>sort1(java.util.List<T>) in X is applied to (java.util.List<X>)
                sort1(lx);
                     ^
X.java:9: warning: [unchecked] unchecked method invocation:
<T>sort2(java.util.List<T>) in X is applied to (java.util.List<X>)
                sort2(lx);
                     ^
X.java:11: warning: [unchecked] unchecked method invocation:
<T>sort4(java.util.List<T>) in X is applied to (java.util.List<X>)
                sort4(lx);
                     ^
X.java:14: type parameter X is not within its bound
                S1<X> s1;
                   ^
X.java:15: type parameter X is not within its bound
                S2<X> s2;
                   ^
X.java:16: type parameter X is not within its bound
                S3<X> s3;
                   ^
X.java:17: type parameter X is not within its bound
                S4<X> s4;
                   ^
4 errors
3 warnings
Comment 4 Philipe Mulet CLA 2005-04-14 13:01:56 EDT
Added GenericTypeTest#test598-600.
I changed the TypeVariableBinding#boundCheck semantics to answer: OK, MISMATCH
or UNCHECKED in this scenario. Depending on who initiates the call, UNCHECKED is
either bad or tolerable; which is the case for method type argument inference;
but still will issue some unchecked method invocation warning.

Changes are to be released along with fix for bug 84496
Comment 5 Philipe Mulet CLA 2005-04-15 04:54:10 EDT
*** Bug 84284 has been marked as a duplicate of this bug. ***
Comment 6 Philipe Mulet CLA 2005-04-15 09:06:43 EDT
*** Bug 90430 has been marked as a duplicate of this bug. ***
Comment 7 Philipe Mulet CLA 2005-04-21 09:11:04 EDT
Released
Comment 8 Allistair Crossley CLA 2005-05-11 09:59:05 EDT
*** Bug 94701 has been marked as a duplicate of this bug. ***
Comment 9 Olivier Thomann CLA 2005-05-11 11:49:00 EDT
Verified in I20050510-0010