7034019: ClassCastException in javac with conjunction types
authormcimadamore
Tue, 12 Apr 2011 20:58:06 -0700
changeset 9302 13a19cf713fd
parent 9301 da48f63f0b22
child 9303 eae35c201e19
7034019: ClassCastException in javac with conjunction types Summary: Resolve.mostSpecific doesn't handle case of raw override Reviewed-by: dlsmith
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/test/tools/javac/generics/7034019/T7034019a.java
langtools/test/tools/javac/generics/7034019/T7034019b.java
langtools/test/tools/javac/generics/7034019/T7034019c.java
langtools/test/tools/javac/generics/7034019/T7034019c.out
langtools/test/tools/javac/generics/7034019/T7034019d.java
langtools/test/tools/javac/generics/7034019/T7034019d.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Apr 12 20:56:16 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Apr 12 20:58:06 2011 -0700
@@ -770,12 +770,9 @@
                     return ambiguityError(m1, m2);
                 // both abstract, neither overridden; merge throws clause and result type
                 Symbol mostSpecific;
-                Type result2 = mt2.getReturnType();
-                if (mt2.tag == FORALL)
-                    result2 = types.subst(result2, ((ForAll)mt2).tvars, ((ForAll)mt1).tvars);
-                if (types.isSubtype(mt1.getReturnType(), result2))
+                if (types.returnTypeSubstitutable(mt1, mt2))
                     mostSpecific = m1;
-                else if (types.isSubtype(result2, mt1.getReturnType()))
+                else if (types.returnTypeSubstitutable(mt2, mt1))
                     mostSpecific = m2;
                 else {
                     // Theoretically, this can't happen, but it is possible
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019a.java	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile T7034019a.java
+ */
+
+class T7034019a {
+    interface A {
+        abstract <T> void foo();
+    }
+
+    interface B {
+        abstract void foo();
+    }
+
+    static class C<T extends A & B> {
+        void test(T x) {
+            x.foo();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019b.java	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile T7034019b.java
+ */
+
+class T7034019a {
+    interface A {
+        <T> void foo();
+    }
+
+    interface B {
+        void foo();
+    }
+
+    static abstract class E implements A,B {
+        void test() {
+            foo();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019c.java	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile/fail/ref=T7034019c.out -XDrawDiagnostics T7034019c.java
+ */
+
+class T7034019c {
+    interface A {
+        abstract <T extends Number> T foo();
+    }
+
+    interface B {
+        abstract <T> T foo();
+    }
+
+    static class C<T extends A & B> {
+        void test(T x) {
+            x.foo();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019c.out	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,3 @@
+T7034019c.java:18:20: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
+T7034019c.java:20:14: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019d.java	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,23 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 7034019
+ * @summary ClassCastException in javac with conjunction types
+ *
+ * @compile/fail/ref=T7034019d.out -XDrawDiagnostics T7034019d.java
+ */
+
+class T7034019c {
+    interface A {
+        abstract <T extends Number> T foo();
+    }
+
+    interface B {
+        abstract <T> T foo();
+    }
+
+    static abstract class E implements A,B {
+        void test() {
+            foo();
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034019/T7034019d.out	Tue Apr 12 20:58:06 2011 -0700
@@ -0,0 +1,3 @@
+T7034019d.java:18:21: compiler.err.name.clash.same.erasure.no.override: <T>foo(), T7034019c.B, <T>foo(), T7034019c.A
+T7034019d.java:20:13: compiler.err.ref.ambiguous: foo, kindname.method, <T>foo(), T7034019c.B, kindname.method, <T>foo(), T7034019c.A
+2 errors