8019340: varargs-related warnings are meaningless on signature-polymorphic methods such as MethodHandle.invokeExact
authormcimadamore
Wed, 17 Jul 2013 14:19:25 +0100
changeset 18917 33c954cf3825
parent 18916 d93bea397df9
child 18918 4e8769f15a95
8019340: varargs-related warnings are meaningless on signature-polymorphic methods such as MethodHandle.invokeExact Summary: Disable certain varargs warnings when compiling polymorphic signature calls Reviewed-by: jjg
langtools/src/share/classes/com/sun/tools/javac/comp/Check.java
langtools/test/tools/javac/meth/VarargsWarn.java
langtools/test/tools/javac/meth/VarargsWarn.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 14:19:02 2013 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java	Wed Jul 17 14:19:25 2013 +0100
@@ -897,7 +897,8 @@
                     assertConvertible(arg, arg.type, varArg, warn);
                     args = args.tail;
                 }
-            } else if ((sym.flags() & VARARGS) != 0 && allowVarargs) {
+            } else if ((sym.flags() & (VARARGS | SIGNATURE_POLYMORPHIC)) == VARARGS &&
+                    allowVarargs) {
                 // non-varargs call to varargs method
                 Type varParam = owntype.getParameterTypes().last();
                 Type lastArg = argtypes.last();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/meth/VarargsWarn.java	Wed Jul 17 14:19:25 2013 +0100
@@ -0,0 +1,17 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8019340
+ * @summary varargs-related warnings are meaningless on signature-polymorphic methods such as MethodHandle.invokeExact
+ *
+ * @compile/fail/ref=VarargsWarn.out -XDrawDiagnostics -Werror VarargsWarn.java
+ */
+
+import java.lang.invoke.*;
+
+class VarargsWarn {
+    void test(MethodHandle mh) throws Throwable {
+        mh.invokeExact((Integer[])null);
+        mh.invoke((Integer[])null);
+        mh.invokeWithArguments((Integer[])null); //not a sig poly method - warning here!
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/meth/VarargsWarn.out	Wed Jul 17 14:19:25 2013 +0100
@@ -0,0 +1,4 @@
+VarargsWarn.java:15:32: compiler.warn.inexact.non-varargs.call: java.lang.Object, java.lang.Object[]
+- compiler.err.warnings.and.werror
+1 error
+1 warning