aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvromero <none@none>2014-06-17 17:33:01 +0100
committervromero <none@none>2014-06-17 17:33:01 +0100
commit249a54dbcaca8a48ac989444c3eff97bf6272497 (patch)
treeecd52edda4ab56ec02536546dedff95c733281a7
parentc596e58444f46689e0093fddf343de45689454b7 (diff)
8036953: Fix timing of varargs access check, per JDK-8016205
Reviewed-by: mcimadamore, dlsmith
-rw-r--r--src/share/classes/com/sun/tools/javac/code/Source.java3
-rw-r--r--src/share/classes/com/sun/tools/javac/comp/Resolve.java8
-rw-r--r--test/tools/javac/varargs/6313164/T6313164.java24
-rw-r--r--test/tools/javac/varargs/6313164/T6313164.out6
-rw-r--r--test/tools/javac/varargs/6313164/T6313164Source7.out6
-rw-r--r--test/tools/javac/varargs/6313164/T6313164Source8AndHigher.out6
-rw-r--r--test/tools/javac/varargs/6313164/T7175433.java41
-rw-r--r--test/tools/javac/varargs/6313164/T7175433.out2
-rw-r--r--test/tools/javac/varargs/6313164/p1/B.java5
9 files changed, 46 insertions, 55 deletions
diff --git a/src/share/classes/com/sun/tools/javac/code/Source.java b/src/share/classes/com/sun/tools/javac/code/Source.java
index 4216df5c..ab15d6db 100644
--- a/src/share/classes/com/sun/tools/javac/code/Source.java
+++ b/src/share/classes/com/sun/tools/javac/code/Source.java
@@ -233,6 +233,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:
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 1535e1d4..043833e5 100644
--- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java
+++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java
@@ -96,6 +96,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;
@@ -137,6 +138,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);
@@ -834,7 +837,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);
diff --git a/test/tools/javac/varargs/6313164/T6313164.java b/test/tools/javac/varargs/6313164/T6313164.java
index 3e828453..7df40d0f 100644
--- a/test/tools/javac/varargs/6313164/T6313164.java
+++ b/test/tools/javac/varargs/6313164/T6313164.java
@@ -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());
}
}
diff --git a/test/tools/javac/varargs/6313164/T6313164.out b/test/tools/javac/varargs/6313164/T6313164.out
deleted file mode 100644
index 7b2de272..00000000
--- a/test/tools/javac/varargs/6313164/T6313164.out
+++ /dev/null
@@ -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
diff --git a/test/tools/javac/varargs/6313164/T6313164Source7.out b/test/tools/javac/varargs/6313164/T6313164Source7.out
new file mode 100644
index 00000000..8c12e727
--- /dev/null
+++ b/test/tools/javac/varargs/6313164/T6313164Source7.out
@@ -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
diff --git a/test/tools/javac/varargs/6313164/T6313164Source8AndHigher.out b/test/tools/javac/varargs/6313164/T6313164Source8AndHigher.out
new file mode 100644
index 00000000..0257a5d5
--- /dev/null
+++ b/test/tools/javac/varargs/6313164/T6313164Source8AndHigher.out
@@ -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
diff --git a/test/tools/javac/varargs/6313164/T7175433.java b/test/tools/javac/varargs/6313164/T7175433.java
index b4627eb7..4384cf5d 100644
--- a/test/tools/javac/varargs/6313164/T7175433.java
+++ b/test/tools/javac/varargs/6313164/T7175433.java
@@ -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);
}
}
diff --git a/test/tools/javac/varargs/6313164/T7175433.out b/test/tools/javac/varargs/6313164/T7175433.out
new file mode 100644
index 00000000..598f3bb5
--- /dev/null
+++ b/test/tools/javac/varargs/6313164/T7175433.out
@@ -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
diff --git a/test/tools/javac/varargs/6313164/p1/B.java b/test/tools/javac/varargs/6313164/p1/B.java
index 38ec371c..ebe7ba99 100644
--- a/test/tools/javac/varargs/6313164/p1/B.java
+++ b/test/tools/javac/varargs/6313164/p1/B.java
@@ -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) { }
-
}