From 0f95b77f8c21b0f03590ae34500c929dae9b669e Mon Sep 17 00:00:00 2001 From: mcimadamore Date: Wed, 17 Jul 2013 14:19:25 +0100 Subject: [PATCH] 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 --- .../classes/com/sun/tools/javac/comp/Check.java | 3 ++- test/tools/javac/meth/VarargsWarn.java | 17 +++++++++++++++++ test/tools/javac/meth/VarargsWarn.out | 4 ++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 test/tools/javac/meth/VarargsWarn.java create mode 100644 test/tools/javac/meth/VarargsWarn.out diff --git a/src/share/classes/com/sun/tools/javac/comp/Check.java b/src/share/classes/com/sun/tools/javac/comp/Check.java index 76440d0b..da991f57 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -897,7 +897,8 @@ public class Check { 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(); diff --git a/test/tools/javac/meth/VarargsWarn.java b/test/tools/javac/meth/VarargsWarn.java new file mode 100644 index 00000000..476617b4 --- /dev/null +++ b/test/tools/javac/meth/VarargsWarn.java @@ -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! + } +} diff --git a/test/tools/javac/meth/VarargsWarn.out b/test/tools/javac/meth/VarargsWarn.out new file mode 100644 index 00000000..13decfad --- /dev/null +++ b/test/tools/javac/meth/VarargsWarn.out @@ -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 -- GitLab