6730476: invalid "unchecked generic array" warning
Reifiable-ness of varargs element type should be checked after JLS3 15.12.2.8 Reviewed-by: jjg
This commit is contained in:
parent
a97d95a1b8
commit
dea5e42c57
langtools
src/share/classes/com/sun/tools/javac/comp
test/tools/javac/varargs/6730476
@ -2621,12 +2621,10 @@ public class Attr extends JCTree.Visitor {
|
||||
}
|
||||
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;
|
||||
|
@ -677,6 +677,19 @@ public class Check {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<Type> 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
|
||||
|
@ -287,7 +287,8 @@ public class Infer {
|
||||
/** Instantiate method type `mt' by finding instantiations of
|
||||
* `tvars' so that method can be applied to `argtypes'.
|
||||
*/
|
||||
public Type instantiateMethod(List<Type> tvars,
|
||||
public Type instantiateMethod(final Env<AttrContext> env,
|
||||
List<Type> tvars,
|
||||
MethodType mt,
|
||||
final List<Type> argtypes,
|
||||
final boolean allowBoxing,
|
||||
@ -416,6 +417,9 @@ public class Infer {
|
||||
// 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;
|
||||
|
@ -345,7 +345,8 @@ public class Resolve {
|
||||
|
||||
if (instNeeded)
|
||||
return
|
||||
infer.instantiateMethod(tvars,
|
||||
infer.instantiateMethod(env,
|
||||
tvars,
|
||||
(MethodType)mt,
|
||||
argtypes,
|
||||
allowBoxing,
|
||||
|
39
langtools/test/tools/javac/varargs/6730476/T6730476a.java
Normal file
39
langtools/test/tools/javac/varargs/6730476/T6730476a.java
Normal file
@ -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 {
|
||||
<T> void f(int i, T ... x) {}
|
||||
void g() {
|
||||
f(1);
|
||||
}
|
||||
}
|
36
langtools/test/tools/javac/varargs/6730476/T6730476b.java
Normal file
36
langtools/test/tools/javac/varargs/6730476/T6730476b.java
Normal file
@ -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<Integer> ints = java.util.Arrays.asList();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user