8036953: Fix timing of varargs access check, per JDK-8016205
Reviewed-by: mcimadamore, dlsmith
This commit is contained in:
parent
f2e2245e7b
commit
e4773094de
@ -237,6 +237,9 @@ public enum Source {
|
||||
public boolean allowFunctionalInterfaceMostSpecific() {
|
||||
return compareTo(JDK1_8) >= 0;
|
||||
}
|
||||
public boolean allowPostApplicabilityVarargsAccessCheck() {
|
||||
return compareTo(JDK1_8) >= 0;
|
||||
}
|
||||
public static SourceVersion toSourceVersion(Source source) {
|
||||
switch(source) {
|
||||
case JDK1_2:
|
||||
|
@ -95,6 +95,7 @@ public class Resolve {
|
||||
public final boolean varargsEnabled;
|
||||
public final boolean allowMethodHandles;
|
||||
public final boolean allowFunctionalInterfaceMostSpecific;
|
||||
public final boolean checkVarargsAccessDuringResolution;
|
||||
private final boolean debugResolve;
|
||||
private final boolean compactMethodDiags;
|
||||
final EnumSet<VerboseResolutionMode> verboseResolutionMode;
|
||||
@ -136,6 +137,8 @@ public class Resolve {
|
||||
Target target = Target.instance(context);
|
||||
allowMethodHandles = target.hasMethodHandles();
|
||||
allowFunctionalInterfaceMostSpecific = source.allowFunctionalInterfaceMostSpecific();
|
||||
checkVarargsAccessDuringResolution =
|
||||
source.allowPostApplicabilityVarargsAccessCheck();
|
||||
polymorphicSignatureScope = new Scope(syms.noSymbol);
|
||||
|
||||
inapplicableMethodException = new InapplicableMethodException(diags);
|
||||
@ -833,7 +836,10 @@ public class Resolve {
|
||||
Warner warn) {
|
||||
super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn);
|
||||
//should we expand formals?
|
||||
if (deferredAttrContext.phase.isVarargsRequired()) {
|
||||
if ((!checkVarargsAccessDuringResolution ||
|
||||
(checkVarargsAccessDuringResolution &&
|
||||
deferredAttrContext.mode == AttrMode.CHECK)) &&
|
||||
deferredAttrContext.phase.isVarargsRequired()) {
|
||||
//check varargs element type accessibility
|
||||
varargsAccessible(env, types.elemtype(formals.last()),
|
||||
deferredAttrContext.inferenceContext);
|
||||
|
@ -1,18 +1,26 @@
|
||||
/*
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 6313164
|
||||
* @bug 6313164 8036953
|
||||
* @author mcimadamore
|
||||
* @summary javac generates code that fails byte code verification for the varargs feature
|
||||
* @compile/fail/ref=T6313164.out -XDrawDiagnostics T6313164.java
|
||||
* @compile/fail/ref=T6313164Source7.out -source 7 -XDrawDiagnostics T6313164.java
|
||||
* @compile/fail/ref=T6313164Source8AndHigher.out -XDrawDiagnostics T6313164.java
|
||||
*/
|
||||
import p1.*;
|
||||
|
||||
class T6313164 {
|
||||
{ B b = new B();
|
||||
b.foo1(new B(), new B()); //error - A not accesible
|
||||
b.foo2(new B(), new B()); //ok - A not accessible, but foo2(Object...) applicable
|
||||
b.foo3(null, null); //error - A (inferred) not accesible
|
||||
b.foo4(null, null); //error - A (inferred in 15.12.2.8 - no resolution backtrack) not accesible
|
||||
b.foo4(new B(), new C()); //ok - A (inferred in 15.12.2.7) not accessible, but foo4(Object...) applicable
|
||||
{
|
||||
B b = new B();
|
||||
b.foo1(new B(), new B()); //error - A not accessible
|
||||
/* 7 : ok - A not accessible, but foo2(Object...) applicable
|
||||
* 8+ : error - A not accessible
|
||||
*/
|
||||
b.foo2(new B(), new B());
|
||||
b.foo3(null, null); //error - A (inferred) not accessible
|
||||
b.foo4(null, null); //error - A not accesible
|
||||
/* 7 : ok - A not accessible, but foo4(Object...) applicable
|
||||
* 8+ : error - A not accessible
|
||||
*/
|
||||
b.foo4(new B(), new C());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +0,0 @@
|
||||
T6313164.java:12:8: compiler.err.cant.apply.symbol: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:14:13: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:15:13: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
- compiler.note.unchecked.filename: B.java
|
||||
- compiler.note.unchecked.recompile
|
||||
3 errors
|
@ -0,0 +1,6 @@
|
||||
- compiler.warn.source.no.bootclasspath: 1.7
|
||||
T6313164.java:14:10: compiler.err.cant.apply.symbol: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:19:15: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:20:15: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
3 errors
|
||||
1 warning
|
@ -0,0 +1,6 @@
|
||||
T6313164.java:14:15: compiler.err.cant.apply.symbol: kindname.method, foo1, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:18:15: compiler.err.cant.apply.symbol: kindname.method, foo2, p1.A[], p1.B,p1.B, kindname.class, p1.B, (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:19:15: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:20:15: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
T6313164.java:24:15: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: p1.A, kindname.class, T6313164)
|
||||
5 errors
|
@ -1,31 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2012, 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
|
||||
* @test /nodynamiccopyright/
|
||||
* @bug 7175433 6313164
|
||||
* @summary Inference cleanup: add helper class to handle inference variables
|
||||
*
|
||||
* @compile/fail/ref=T7175433.out -XDrawDiagnostics T7175433.java
|
||||
*/
|
||||
|
||||
import java.util.List;
|
||||
@ -34,26 +11,16 @@ class Bar {
|
||||
|
||||
private class Foo { }
|
||||
|
||||
<Z> List<Z> m(Object... o) { T7175433.assertTrue(true); return null; }
|
||||
<Z> List<Z> m(Foo... o) { T7175433.assertTrue(false); return null; }
|
||||
<Z> List<Z> m(Object... o) { return null; }
|
||||
<Z> List<Z> m(Foo... o) { return null; }
|
||||
|
||||
Foo getFoo() { return null; }
|
||||
}
|
||||
|
||||
public class T7175433 {
|
||||
|
||||
static int assertionCount;
|
||||
|
||||
static void assertTrue(boolean b) {
|
||||
assertionCount++;
|
||||
if (!b) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Bar b = new Bar();
|
||||
b.m(b.getFoo());
|
||||
assertTrue(assertionCount == 1);
|
||||
}
|
||||
}
|
||||
|
2
langtools/test/tools/javac/varargs/6313164/T7175433.out
Normal file
2
langtools/test/tools/javac/varargs/6313164/T7175433.out
Normal file
@ -0,0 +1,2 @@
|
||||
T7175433.java:24:12: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: Bar.Foo, kindname.class, T7175433)
|
||||
1 error
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2011, 2014, 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
|
||||
@ -23,13 +23,12 @@
|
||||
|
||||
package p1;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class B extends A {
|
||||
public B() {}
|
||||
public void foo1(A... args) { }
|
||||
public void foo2(A... args) { }
|
||||
public void foo2(Object... args) { }
|
||||
public <X extends A> void foo3(X... args) { }
|
||||
public <X extends A> void foo4(X... args) { }
|
||||
public void foo4(Object... args) { }
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user