Community
Participate
Working Groups
Build 3.5M3 The following code should be rejected by the compiler: class Box<U extends Box<?, ?>, V extends U> { V value; Box<U, V> same; Box(V v) { value = v; } Box() { } } class A extends Box<A, A> {} class B extends Box<B, B> {} public class X { public static void main(String[] args) { Box<Box<A, A>, Box<A, A>> a = new Box<Box<A, A>, Box<A, A>>(new Box<A, A>(new A())); Box<?, ?> b = a; b.value.same = new Box<B, B>(new B()); A c = a.value.same.value; } } Also see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6450290
Created attachment 119528 [details] Work in progress This patch GenericTypeTest#test0925 and it should not. It complains about an ambiguous call. "----------\n" + "1. ERROR in X.java (at line 23)\n" + " l.addAll(getRelated(b));\n" + " ^^^^^^\n" + "The method addAll(Collection<? extends capture#2-of ? super A>) is ambiguous for the type L\n" + "----------\n" Before the patch, the method didn't get captured argument types; which wasn't good.
Created attachment 119531 [details] Proposed patch This addresses the previous concern. When iterating supertypes, need to hold onto the already captured receiver type.
Released for 3.5M4. Fixed
Added GenericTypeTest#test1418-1420
I believe we should consider fixing it for 3.4.2. There is no workaround, and the compiler is exposing uncaptured wildcards which can lead to accept illegal code by mistake. Fix is reasonable.
Created attachment 119629 [details] Proposed patch for 3.4
Note that patch from comment 6 contains a fix in AbstractImageBuilder for another bug. It should not be part of this patch. Other than that, +1 for 3.4.2
Good point. I will not commit this part.
Released for 3.4.2
Verified for 3.5M4 using I20081209-0100
Verified for 3.4.2 using M20090127-1710