7034511: Loophole in typesafety
authormcimadamore
Tue, 12 Apr 2011 20:56:16 -0700
changeset 9301 da48f63f0b22
parent 9300 c2de4dd9853b
child 9302 13a19cf713fd
7034511: Loophole in typesafety Summary: Type-variable substutution takes upper bound of replaced captured type-variable Reviewed-by: dlsmith
langtools/src/share/classes/com/sun/tools/javac/code/Types.java
langtools/test/tools/javac/generics/7034511/T7034511a.java
langtools/test/tools/javac/generics/7034511/T7034511a.out
langtools/test/tools/javac/generics/7034511/T7034511b.java
langtools/test/tools/javac/generics/7034511/T7034511b.out
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Wed Apr 06 19:30:57 2011 -0700
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java	Tue Apr 12 20:56:16 2011 -0700
@@ -2309,7 +2309,7 @@
             if (elemtype == t.elemtype)
                 return t;
             else
-                return new ArrayType(upperBound(elemtype), t.tsym);
+                return new ArrayType(elemtype, t.tsym);
         }
 
         @Override
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034511/T7034511a.java	Tue Apr 12 20:56:16 2011 -0700
@@ -0,0 +1,21 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     7034511
+ * @summary Loophole in typesafety
+ * @compile/fail/ref=T7034511a.out -XDrawDiagnostics T7034511a.java
+ */
+
+class T7034511a {
+
+    interface A<T> {
+        void foo(T x);
+    }
+
+    interface B<T> extends A<T[]> { }
+
+    static abstract class C implements B<Integer> {
+        <T extends B<?>> void test(T x, String[] ss) {
+            x.foo(ss);
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034511/T7034511a.out	Tue Apr 12 20:56:16 2011 -0700
@@ -0,0 +1,2 @@
+T7034511a.java:18:14: compiler.err.cant.apply.symbol.1: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: java.lang.String[], compiler.misc.type.captureof: 1, ?[])
+1 error
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034511/T7034511b.java	Tue Apr 12 20:56:16 2011 -0700
@@ -0,0 +1,16 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug     7034511
+ * @summary Loophole in typesafety
+ * @compile/fail/ref=T7034511b.out -XDrawDiagnostics T7034511b.java
+ */
+
+class T7034511b {
+    static class MyList<E> {
+        E toArray(E[] e) { return null; }
+    }
+
+    void test(MyList<?> ml, Object o[]) {
+        ml.toArray(o);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034511/T7034511b.out	Tue Apr 12 20:56:16 2011 -0700
@@ -0,0 +1,2 @@
+T7034511b.java:14:11: compiler.err.cant.apply.symbol.1: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: java.lang.Object[], compiler.misc.type.captureof: 1, ?[])
+1 error