-
Bug
-
Resolution: Unresolved
-
P4
-
8, 9, 10, 10.0.1, 11
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
The capture conversion of a wildcard for a type variable with a bound referring to an outer class is created incorrectly. It creates a capture type that still has an unresolved type variable in it.
This can expose the type variable outside the scope where it is defined; or cause other type confusion, leading to heap pollution.
---------- BEGIN SOURCE ----------
public class OuterInnerConfusion {
static class Outer<P> {
class MyList<I extends P> extends ArrayList<I> {
MyList(I i) {add(i);}
}
P getIt(Outer<?>.MyList<?> myList) {
// myList is a MyList<capture of ?>, where the capture has upper bound P...
// but that's supposed to be a different P than the return type P here.
return myList.get(0); // this should not be valid
}
}
public static void main(String args[]) {
// ClassCastException
String s = new Outer<String>().getIt(new Outer<Integer>().new MyList<Integer>(1));
}
}
---------- END SOURCE ----------
FREQUENCY : always
The capture conversion of a wildcard for a type variable with a bound referring to an outer class is created incorrectly. It creates a capture type that still has an unresolved type variable in it.
This can expose the type variable outside the scope where it is defined; or cause other type confusion, leading to heap pollution.
---------- BEGIN SOURCE ----------
public class OuterInnerConfusion {
static class Outer<P> {
class MyList<I extends P> extends ArrayList<I> {
MyList(I i) {add(i);}
}
P getIt(Outer<?>.MyList<?> myList) {
// myList is a MyList<capture of ?>, where the capture has upper bound P...
// but that's supposed to be a different P than the return type P here.
return myList.get(0); // this should not be valid
}
}
public static void main(String args[]) {
// ClassCastException
String s = new Outer<String>().getIt(new Outer<Integer>().new MyList<Integer>(1));
}
}
---------- END SOURCE ----------
FREQUENCY : always
- relates to
-
JDK-8030746 4.10: Define subtyping for inner classes of parameterized types
- Open