FULL PRODUCT VERSION :
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
A cast that formerly gave at most a unchecked warning now gives an inconvertible types error and I am not persuaded that the cast is illegal: it looks like the compiler is not looking past the apparent number of arguments, oblivious to the fact that XAxis<?,?> "expands" to Axis<?,?,?>.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compiler the code below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
unchecked cast warning at most
ACTUAL -
compiler errors
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Bug34.java:10: inconvertible types
found : Bug34.Axis<capture#829 of ?,capture#552 of ?,capture#955 of ?>
required: Bug34.XAxis<?,?>
return (XAxis<?, ?>)map.get("X");
^
Bug34.java:16: inconvertible types
found : Bug34.Axis<capture#683 of ?,capture#276 of ?,capture#397 of ?>
required: Bug34.XAxis<TX,? extends Bug34.Scale>
return (XAxis<TX, ? extends Scale>)map.get("X");
^
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Map;
public class Bug34 {
private static Map<String, Axis<?, ?, ?>> map;
public static <TX extends Comparable <TX>> XAxis<?, ?> getXAxis1() {
// no errors or warnings with 1.5
// inconvertible types error with 1.6
return (XAxis<?, ?>)map.get("X");
}
public static <TX extends Comparable <TX>> XAxis<TX, ? extends Scale> getXAxis2() {
// unchecked cast warning with 1.5
// inconvertible types error with 1.6
return (XAxis<TX, ? extends Scale>)map.get("X");
}
public static interface XAxis<TX extends Comparable<TX>, SX extends Scale> extends Axis<TX, SX, XFoo<TX, SX>> { }
public static interface XScale extends Scale { }
public static interface XFoo<TX extends Comparable<TX>, SX extends Scale> extends Foo<TX, SX> { }
public static interface Axis<T extends Comparable<T>, S extends Scale, F extends Foo<T, S>> { }
public static interface Scale { }
public static interface Foo<T extends Comparable<T>, S extends Scale> { }
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Type the map really loosely, i.e., as Map<String, Object>