7041019: Bogus type-variable substitution with array types with dependencies on accessibility check
Summary: call to upperBound() when performing type-variable substitution on element type leads to unsoundness
Reviewed-by: jjg
--- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jul 17 14:14:49 2013 +0100
@@ -2864,7 +2864,7 @@
if (elemtype == t.elemtype)
return t;
else
- return new ArrayType(upperBound(elemtype), t.tsym);
+ return new ArrayType(elemtype, t.tsym);
}
@Override
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Jul 17 14:14:49 2013 +0100
@@ -345,7 +345,7 @@
boolean isAccessible(Env<AttrContext> env, Type t, boolean checkInner) {
return (t.hasTag(ARRAY))
- ? isAccessible(env, types.elemtype(t))
+ ? isAccessible(env, types.upperBound(types.elemtype(t)))
: isAccessible(env, t.tsym, checkInner);
}
--- a/langtools/test/tools/javac/generics/7034511/T7034511a.java Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/test/tools/javac/generics/7034511/T7034511a.java Wed Jul 17 14:14:49 2013 +0100
@@ -1,13 +1,10 @@
/*
* @test /nodynamiccopyright/
- * @ignore 7041019 Bogus type-variable substitution with array types with dependencies on accessibility check
- * @bug 7034511 7040883
+ * @bug 7034511 7040883 7041019
* @summary Loophole in typesafety
* @compile/fail/ref=T7034511a.out -XDrawDiagnostics T7034511a.java
*/
-// backing out 7034511, see 7040883
-
class T7034511a {
interface A<T> {
--- a/langtools/test/tools/javac/generics/7034511/T7034511a.out Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/test/tools/javac/generics/7034511/T7034511a.out Wed Jul 17 14:14:49 2013 +0100
@@ -1,2 +1,2 @@
-T7034511a.java:18:14: compiler.err.cant.apply.symbol: 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, ?[])
+T7034511a.java:18:14: compiler.err.cant.apply.symbol: kindname.method, foo, compiler.misc.type.captureof: 1, ?[], java.lang.String[], kindname.interface, T7034511a.A<T>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.String[], compiler.misc.type.captureof: 1, ?[]))
1 error
--- a/langtools/test/tools/javac/generics/7034511/T7034511b.java Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/test/tools/javac/generics/7034511/T7034511b.java Wed Jul 17 14:14:49 2013 +0100
@@ -1,13 +1,10 @@
/*
* @test /nodynamiccopyright/
- * @ignore 7041019 Bogus type-variable substitution with array types with dependencies on accessibility check
- * @bug 7034511 7040883
+ * @bug 7034511 7040883 7041019
* @summary Loophole in typesafety
* @compile/fail/ref=T7034511b.out -XDrawDiagnostics T7034511b.java
*/
-// backing out 7034511, see 7040883
-
class T7034511b {
static class MyList<E> {
E toArray(E[] e) { return null; }
--- a/langtools/test/tools/javac/generics/7034511/T7034511b.out Wed Jul 17 14:14:32 2013 +0100
+++ b/langtools/test/tools/javac/generics/7034511/T7034511b.out Wed Jul 17 14:14:49 2013 +0100
@@ -1,2 +1,2 @@
-T7034511b.java:14:11: compiler.err.cant.apply.symbol: 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, ?[])
+T7034511b.java:14:11: compiler.err.cant.apply.symbol: kindname.method, toArray, compiler.misc.type.captureof: 1, ?[], java.lang.Object[], kindname.class, T7034511b.MyList<E>, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object[], compiler.misc.type.captureof: 1, ?[]))
1 error
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/generics/7034511/T7041019.java Wed Jul 17 14:14:49 2013 +0100
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2013, 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 7034511 7040883 7041019
+ * @summary Bogus type-variable substitution with array types with dependencies on accessibility check
+ *
+ * @compile T7041019.java
+ */
+import java.util.List;
+
+class T7041019 {
+ <E> List<E>[] m(List<E> l) { return null; }
+
+ void test(List<? extends String> ls) {
+ int i = m(ls).length;
+ }
+}