JDK-6526842 : another type system loophole in wildcard substitution
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux
  • CPU: x86
  • Submitted: 2007-02-20
  • Updated: 2010-04-04
  • Resolved: 2009-01-05
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

A DESCRIPTION OF THE PROBLEM :
There is still a loophole related to wildcard substitution.
In the attached example, Eppb's second parameter extends a box of a box of its first param. Applied to  Ebbp<?,?> this means the second parameter has Box<Box<?>> as upperbound, which is wrong.

According to bug 5044625 this should already have been fixed by applying capture conversion on the left-hand side of supertype, but apparently the change there wasn't enough.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class Break {
	public static void main(String[] args) {
		Ebbp<A,Box<Box<A>>> realFrom = new Ebbp<A,Box<Box<A>>>(new Box<Box<A>>(new Box<A>(new A())));
		caster(realFrom).q.p = new Box<B>(new B());
		A a = realFrom.q.p.p;
	}
	
	static Ebbp<?,? extends Box<Box<?>>> caster(Ebbp<?,?> from) {
		Box<Ebbp<?,?>> boxedFrom = new Box<Ebbp<?,?>>(from);
		Box<? extends Ebbp<?,? extends Box<Box<?>>>> boxedTo = boxedFrom;
		return boxedTo.p;
	}
}

class Box<P> {
	P p;
	Box(P p) {this.p = p;}
}

class Ebbp<P, Q extends Box<Box<P>>> {
	Q q;
	Ebbp(Q q) {this.q = q;}
}

class A {}
class B {}
---------- END SOURCE ----------

Comments
EVALUATION Not reproducible after fixes of 6651719 (jdk 7 b33) and 6732484 (jdk 7 b40)
05-01-2009