8049075: javac, wildcards and generic vararg method invocation not accepted
authorvromero
Fri, 04 Jul 2014 16:34:44 +0100
changeset 25435 928866794984
parent 25434 823512a72660
child 25436 93247e8442a1
8049075: javac, wildcards and generic vararg method invocation not accepted Reviewed-by: mcimadamore
langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java
langtools/test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jul 04 10:52:22 2014 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java	Fri Jul 04 16:34:44 2014 +0100
@@ -95,7 +95,7 @@
     public final boolean varargsEnabled;
     public final boolean allowMethodHandles;
     public final boolean allowFunctionalInterfaceMostSpecific;
-    public final boolean checkVarargsAccessDuringResolution;
+    public final boolean checkVarargsAccessAfterResolution;
     private final boolean debugResolve;
     private final boolean compactMethodDiags;
     final EnumSet<VerboseResolutionMode> verboseResolutionMode;
@@ -137,7 +137,7 @@
         Target target = Target.instance(context);
         allowMethodHandles = target.hasMethodHandles();
         allowFunctionalInterfaceMostSpecific = source.allowFunctionalInterfaceMostSpecific();
-        checkVarargsAccessDuringResolution =
+        checkVarargsAccessAfterResolution =
                 source.allowPostApplicabilityVarargsAccessCheck();
         polymorphicSignatureScope = new Scope(syms.noSymbol);
 
@@ -836,13 +836,16 @@
                                     Warner warn) {
             super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn);
             //should we expand formals?
-            if ((!checkVarargsAccessDuringResolution ||
-                (checkVarargsAccessDuringResolution &&
-                 deferredAttrContext.mode == AttrMode.CHECK)) &&
-                deferredAttrContext.phase.isVarargsRequired()) {
-                //check varargs element type accessibility
-                varargsAccessible(env, types.elemtype(formals.last()),
-                        deferredAttrContext.inferenceContext);
+            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);
+                }
             }
         }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java	Fri Jul 04 16:34:44 2014 +0100
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 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
+ * 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 8049075
+ * @summary javac, wildcards and generic vararg method invocation not accepted
+ * @compile VarargsAndWildcardParameterizedTypeTest.java
+ */
+
+class VarargsAndWildcardParameterizedTypeTest {
+    interface I<T> {
+        String m(T... t);
+    }
+
+    void m() {
+        I<? super Integer> i = null;
+        i.m(Integer.valueOf(1), Integer.valueOf(1));
+    }
+}