aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormcimadamore <none@none>2011-04-12 20:56:16 -0700
committermcimadamore <none@none>2011-04-12 20:56:16 -0700
commit0f687cdd3ae597526fe51795e9186d5735bce9ba (patch)
treef8d396c0035cf5ba98d58ed4372a92798571afee
parenta68caab503085ae2e28521913fd95ba7f4896db5 (diff)
7034511: Loophole in typesafety
Summary: Type-variable substutution takes upper bound of replaced captured type-variable Reviewed-by: dlsmith
-rw-r--r--src/share/classes/com/sun/tools/javac/code/Types.java2
-rw-r--r--test/tools/javac/generics/7034511/T7034511a.java21
-rw-r--r--test/tools/javac/generics/7034511/T7034511a.out2
-rw-r--r--test/tools/javac/generics/7034511/T7034511b.java16
-rw-r--r--test/tools/javac/generics/7034511/T7034511b.out2
5 files changed, 42 insertions, 1 deletions
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 8de4750d..6408a06e 100644
--- a/src/share/classes/com/sun/tools/javac/code/Types.java
+++ b/src/share/classes/com/sun/tools/javac/code/Types.java
@@ -2309,7 +2309,7 @@ public class Types {
if (elemtype == t.elemtype)
return t;
else
- return new ArrayType(upperBound(elemtype), t.tsym);
+ return new ArrayType(elemtype, t.tsym);
}
@Override
diff --git a/test/tools/javac/generics/7034511/T7034511a.java b/test/tools/javac/generics/7034511/T7034511a.java
new file mode 100644
index 00000000..522b52ef
--- /dev/null
+++ b/test/tools/javac/generics/7034511/T7034511a.java
@@ -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);
+ }
+ }
+}
diff --git a/test/tools/javac/generics/7034511/T7034511a.out b/test/tools/javac/generics/7034511/T7034511a.out
new file mode 100644
index 00000000..8636950a
--- /dev/null
+++ b/test/tools/javac/generics/7034511/T7034511a.out
@@ -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
diff --git a/test/tools/javac/generics/7034511/T7034511b.java b/test/tools/javac/generics/7034511/T7034511b.java
new file mode 100644
index 00000000..49f47d47
--- /dev/null
+++ b/test/tools/javac/generics/7034511/T7034511b.java
@@ -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);
+ }
+}
diff --git a/test/tools/javac/generics/7034511/T7034511b.out b/test/tools/javac/generics/7034511/T7034511b.out
new file mode 100644
index 00000000..5d3da3f4
--- /dev/null
+++ b/test/tools/javac/generics/7034511/T7034511b.out
@@ -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