# HG changeset patch # User mcimadamore # Date 1271849096 -3600 # Node ID e7af65bf75779fff9fc60b9e770c01b385633b14 # Parent ac6d66f658cbd7ebb66d77e37ba71d931131c995 6730476: invalid "unchecked generic array" warning Summary: Reifiable-ness of varargs element type should be checked after JLS3 15.12.2.8 Reviewed-by: jjg diff -r ac6d66f658cb -r e7af65bf7577 langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Sat Apr 17 08:12:45 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Apr 21 12:24:56 2010 +0100 @@ -2621,12 +2621,10 @@ } if (useVarargs) { JCTree tree = env.tree; - Type argtype = owntype.getParameterTypes().last(); - if (!types.isReifiable(argtype)) - chk.warnUnchecked(env.tree.pos(), - "unchecked.generic.array.creation", - argtype); - Type elemtype = types.elemtype(argtype); + if (owntype.getReturnType().tag != FORALL || warned) { + chk.checkVararg(env.tree.pos(), owntype.getParameterTypes()); + } + Type elemtype = types.elemtype(owntype.getParameterTypes().last()); switch (tree.getTag()) { case JCTree.APPLY: ((JCMethodInvocation) tree).varargsElement = elemtype; diff -r ac6d66f658cb -r e7af65bf7577 langtools/src/share/classes/com/sun/tools/javac/comp/Check.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Sat Apr 17 08:12:45 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Apr 21 12:24:56 2010 +0100 @@ -677,6 +677,19 @@ } } + /** + * Check that vararg method call is sound + * @param pos Position to be used for error reporting. + * @param argtypes Actual arguments supplied to vararg method. + */ + void checkVararg(DiagnosticPosition pos, List argtypes) { + Type argtype = argtypes.last(); + if (!types.isReifiable(argtype)) + warnUnchecked(pos, + "unchecked.generic.array.creation", + argtype); + } + /** Check that given modifiers are legal for given symbol and * return modifiers together with any implicit modififiers for that symbol. * Warning: we can't use flags() here since this method diff -r ac6d66f658cb -r e7af65bf7577 langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Sat Apr 17 08:12:45 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Infer.java Wed Apr 21 12:24:56 2010 +0100 @@ -287,7 +287,8 @@ /** Instantiate method type `mt' by finding instantiations of * `tvars' so that method can be applied to `argtypes'. */ - public Type instantiateMethod(List tvars, + public Type instantiateMethod(final Env env, + List tvars, MethodType mt, final List argtypes, final boolean allowBoxing, @@ -416,6 +417,9 @@ // check that inferred bounds conform to their bounds checkWithinBounds(all_tvars, types.subst(inferredTypes, tvars, inferred), warn); + if (useVarargs) { + chk.checkVararg(env.tree.pos(), formals); + } return super.inst(inferred, types); }}; return mt2; diff -r ac6d66f658cb -r e7af65bf7577 langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java --- a/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Sat Apr 17 08:12:45 2010 -0700 +++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Resolve.java Wed Apr 21 12:24:56 2010 +0100 @@ -345,7 +345,8 @@ if (instNeeded) return - infer.instantiateMethod(tvars, + infer.instantiateMethod(env, + tvars, (MethodType)mt, argtypes, allowBoxing, diff -r ac6d66f658cb -r e7af65bf7577 langtools/test/tools/javac/varargs/6730476/T6730476a.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/varargs/6730476/T6730476a.java Wed Apr 21 12:24:56 2010 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6730476 + * + * @summary invalid "unchecked generic array" warning + * @author mcimadamore + * @compile T6730476a.java -Xlint -Werror + * + */ + +class T6730476a { + void f(int i, T ... x) {} + void g() { + f(1); + } +} diff -r ac6d66f658cb -r e7af65bf7577 langtools/test/tools/javac/varargs/6730476/T6730476b.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/langtools/test/tools/javac/varargs/6730476/T6730476b.java Wed Apr 21 12:24:56 2010 +0100 @@ -0,0 +1,36 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test + * @bug 6730476 + * + * @summary invalid "unchecked generic array" warning + * @author mcimadamore + * @compile T6730476b.java -Xlint -Werror + * + */ + +class T6730476b { + java.util.List ints = java.util.Arrays.asList(); +}