# HG changeset patch # User mcimadamore # Date 1288875509 0 # Node ID e9e41c88b03ec9f7f3a50b71bff40a13ca7e5038 # Parent f2048d9c666e13808d993a89f8e23d7e64f1e7ca 6714835: Safe cast is rejected (with warning) by javac Summary: Rules for unchecked cast conversion do not take into account type-containment Reviewed-by: jjg diff -r f2048d9c666e -r e9e41c88b03e src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Thu Nov 04 12:57:48 2010 +0000 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Nov 04 12:58:29 2010 +0000 @@ -3151,7 +3151,7 @@ return to.isParameterized() && (!(isUnbounded(to) || isSubtype(from, to) || - ((subFrom != null) && isSameType(subFrom, to)))); + ((subFrom != null) && containsType(to.allparams(), subFrom.allparams())))); } private List superClosure(Type t, Type s) { diff -r f2048d9c666e -r e9e41c88b03e test/tools/javac/cast/6467183/T6467183a.out --- a/test/tools/javac/cast/6467183/T6467183a.out Thu Nov 04 12:57:48 2010 +0000 +++ b/test/tools/javac/cast/6467183/T6467183a.out Thu Nov 04 12:58:29 2010 +0000 @@ -1,6 +1,4 @@ T6467183a.java:16:26: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a.B, T6467183a.A -T6467183a.java:24:41: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a.A, T6467183a.C -T6467183a.java:28:42: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), T6467183a.A, T6467183a.C - compiler.err.warnings.and.werror 1 error -3 warnings +1 warning diff -r f2048d9c666e -r e9e41c88b03e test/tools/javac/cast/6714835/T6714835.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/6714835/T6714835.java Thu Nov 04 12:58:29 2010 +0000 @@ -0,0 +1,21 @@ +/* + * @test /nodynamiccopyright/ + * @author mcimadamore + * @bug 6714835 + * @summary Safe cast is rejected (with warning) by javac + * @compile/fail/ref=T6714835.out -Xlint:unchecked -Werror -XDrawDiagnostics T6714835.java + */ + +import java.util.*; + +class T6714835 { + void cast1(Iterable x) { + Collection x1 = (Collection)x; //ok + Collection x2 = (Collection)x; //warn + } + + void cast2(Iterable x) { + Collection x1 = (Collection)x; //ok + Collection x2 = (Collection)x; //warn + } +} diff -r f2048d9c666e -r e9e41c88b03e test/tools/javac/cast/6714835/T6714835.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/cast/6714835/T6714835.out Thu Nov 04 12:58:29 2010 +0000 @@ -0,0 +1,5 @@ +T6714835.java:14:71: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Iterable, java.util.Collection +T6714835.java:19:73: compiler.warn.prob.found.req: (compiler.misc.unchecked.cast.to.type), java.lang.Iterable, java.util.Collection +- compiler.err.warnings.and.werror +1 error +2 warnings