From 1709cde7fcacaa20f14f6c88ec4cac98fe898371 Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Thu, 4 Nov 2010 12:58:29 +0000 Subject: [PATCH] 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 --- .../com/sun/tools/javac/code/Types.java | 2 +- test/tools/javac/cast/6467183/T6467183a.out | 4 +--- test/tools/javac/cast/6714835/T6714835.java | 21 +++++++++++++++++++ test/tools/javac/cast/6714835/T6714835.out | 5 +++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/tools/javac/cast/6714835/T6714835.java create mode 100644 test/tools/javac/cast/6714835/T6714835.out diff --git a/src/share/classes/com/sun/tools/javac/code/Types.java b/src/share/classes/com/sun/tools/javac/code/Types.java index f6fd8fd7..d9bd17ef 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -3151,7 +3151,7 @@ public class Types { 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 --git a/test/tools/javac/cast/6467183/T6467183a.out b/test/tools/javac/cast/6467183/T6467183a.out index 972d54de..562a48a0 100644 --- a/test/tools/javac/cast/6467183/T6467183a.out +++ b/test/tools/javac/cast/6467183/T6467183a.out @@ -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 --git a/test/tools/javac/cast/6714835/T6714835.java b/test/tools/javac/cast/6714835/T6714835.java new file mode 100644 index 00000000..6c31596a --- /dev/null +++ b/test/tools/javac/cast/6714835/T6714835.java @@ -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 --git a/test/tools/javac/cast/6714835/T6714835.out b/test/tools/javac/cast/6714835/T6714835.out new file mode 100644 index 00000000..dc4a86b0 --- /dev/null +++ b/test/tools/javac/cast/6714835/T6714835.out @@ -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 -- GitLab