提交 f13e39db 编写于 作者: D dlsmith

8075520: Varargs access check mishandles capture variables

8077786: Check varargs access against inferred signature
Reviewed-by: vromero
上级 4fa87630
......@@ -836,20 +836,19 @@ public class Resolve {
List<Type> formals,
Warner warn) {
super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn);
//should we expand formals?
// should we check varargs element type accessibility?
if (deferredAttrContext.phase.isVarargsRequired()) {
Type typeToCheck = null;
if (!checkVarargsAccessAfterResolution) {
typeToCheck = types.elemtype(formals.last());
} else if (deferredAttrContext.mode == AttrMode.CHECK) {
typeToCheck = types.erasure(types.elemtype(formals.last()));
}
if (typeToCheck != null) {
varargsAccessible(env, typeToCheck, deferredAttrContext.inferenceContext);
if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) {
varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext);
}
}
}
/**
* Test that the runtime array element type corresponding to 't' is accessible. 't' should be the
* varargs element type of either the method invocation type signature (after inference completes)
* or the method declaration signature (before inference completes).
*/
private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) {
if (inferenceContext.free(t)) {
inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() {
......@@ -859,7 +858,7 @@ public class Resolve {
}
});
} else {
if (!isAccessible(env, t)) {
if (!isAccessible(env, types.erasure(t))) {
Symbol location = env.enclClass.sym;
reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location);
}
......
/*
* Copyright (c) 2015, 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.
*/
/*
* Auxiliary file for VarargsInferredPrivateType
*/
package otherpackage;
public class OtherPackage {
public static Private getPrivate() {
return new Private();
}
private static class Private {}
}
\ No newline at end of file
......@@ -26,6 +26,8 @@
* @bug 8049075
* @summary javac, wildcards and generic vararg method invocation not accepted
* @compile VarargsAndWildcardParameterizedTypeTest.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest.java
*/
class VarargsAndWildcardParameterizedTypeTest {
......
/*
* Copyright (c) 2015, 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 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest2.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest2.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest2.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(T... t);
}
interface Box<T> {
T get();
}
void m(I i, Box<? extends Number> b) {
i.m(b.get());
}
}
/*
* Copyright (c) 2015, 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 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest3.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest3.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest3.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(Box<? extends T> iter, T... t);
}
interface Box<T> {}
void m(I i, Box<? extends Number> b) {
i.m(b);
}
}
/*
* Copyright (c) 2015, 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 8075520
* @summary Varargs access check mishandles capture variables
* @compile VarargsAndWildcardParameterizedTypeTest4.java
* @compile -source 8 VarargsAndWildcardParameterizedTypeTest4.java
* @compile -source 7 VarargsAndWildcardParameterizedTypeTest4.java
*/
class VarargsAndWildcardParameterizedTypeTest2 {
interface I {
<T> void m(Box<T> iter, T... t);
}
interface Box<T> {}
void m(I i, Box<? extends Number> b) {
i.m(b);
}
}
VarargsInferredPrivateType.java:16:10: compiler.err.cant.apply.symbol: kindname.method, m, T[], otherpackage.OtherPackage.Private, kindname.interface, VarargsInferredPrivateType.I, (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType)
- compiler.note.unchecked.filename: VarargsInferredPrivateType.java
- compiler.note.unchecked.recompile
1 error
/*
* @test /nodynamiccopyright/
* @bug 8077786
* @summary Check varargs access against inferred signature
* @compile/fail/ref=VarargsInferredPrivateType.out -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
* @compile/fail/ref=VarargsInferredPrivateType.out -source 8 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
* @compile/fail/ref=VarargsInferredPrivateType-source7.out -source 7 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java
*/
class VarargsInferredPrivateType {
interface I {
<T> void m(T... t);
}
void m(I i) {
i.m(otherpackage.OtherPackage.getPrivate());
}
}
VarargsInferredPrivateType.java:16:12: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType)
- compiler.note.unchecked.filename: VarargsInferredPrivateType.java
- compiler.note.unchecked.recompile
1 error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册