From 4d5a4c58d614a0c1b8e5befc4c6f77ce3997f621 Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Wed, 17 Jul 2013 14:14:49 +0100 Subject: [PATCH] 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 --- .../com/sun/tools/javac/code/Types.java | 2 +- .../com/sun/tools/javac/comp/Resolve.java | 2 +- .../javac/generics/7034511/T7034511a.java | 5 +-- .../javac/generics/7034511/T7034511a.out | 2 +- .../javac/generics/7034511/T7034511b.java | 5 +-- .../javac/generics/7034511/T7034511b.out | 2 +- .../javac/generics/7034511/T7041019.java | 39 +++++++++++++++++++ 7 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 test/tools/javac/generics/7034511/T7041019.java 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 8a3b4235..d3b6f4bc 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -2864,7 +2864,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/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/share/classes/com/sun/tools/javac/comp/Resolve.java index 6c523089..ff4d048f 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -345,7 +345,7 @@ public class Resolve { boolean isAccessible(Env 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); } diff --git a/test/tools/javac/generics/7034511/T7034511a.java b/test/tools/javac/generics/7034511/T7034511a.java index af1f5a97..26418d63 100644 --- a/test/tools/javac/generics/7034511/T7034511a.java +++ b/test/tools/javac/generics/7034511/T7034511a.java @@ -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 { diff --git a/test/tools/javac/generics/7034511/T7034511a.out b/test/tools/javac/generics/7034511/T7034511a.out index e05cd632..4ce8eafd 100644 --- a/test/tools/javac/generics/7034511/T7034511a.out +++ b/test/tools/javac/generics/7034511/T7034511a.out @@ -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, (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, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: 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 index 2adebca0..93d16787 100644 --- a/test/tools/javac/generics/7034511/T7034511b.java +++ b/test/tools/javac/generics/7034511/T7034511b.java @@ -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 toArray(E[] e) { return null; } diff --git a/test/tools/javac/generics/7034511/T7034511b.out b/test/tools/javac/generics/7034511/T7034511b.out index 8d0d9335..1cff6c38 100644 --- a/test/tools/javac/generics/7034511/T7034511b.out +++ b/test/tools/javac/generics/7034511/T7034511b.out @@ -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, (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, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inconvertible.types: java.lang.Object[], compiler.misc.type.captureof: 1, ?[])) 1 error diff --git a/test/tools/javac/generics/7034511/T7041019.java b/test/tools/javac/generics/7034511/T7041019.java new file mode 100644 index 00000000..78b7bed7 --- /dev/null +++ b/test/tools/javac/generics/7034511/T7041019.java @@ -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 { + List[] m(List l) { return null; } + + void test(List ls) { + int i = m(ls).length; + } +} -- GitLab