Summary: | [1.5][compiler] Cannot sort a raw Comparable | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Tim Hanson <thanson> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED FIXED | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | akiezun, allistair.crossley, volker.renneberg.external |
Version: | 3.1 | ||
Target Milestone: | 3.1 M7 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
Tim Hanson
2005-04-08 19:00:28 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. 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. 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 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 *** Bug 84284 has been marked as a duplicate of this bug. *** *** Bug 90430 has been marked as a duplicate of this bug. *** Released *** Bug 94701 has been marked as a duplicate of this bug. *** Verified in I20050510-0010 |