8029844: Enhance argument validation

Make defensive copy of a varargs array

Reviewed-by: mchung, twisti, ahgross
This commit is contained in:
John R Rose 2013-12-13 18:06:31 -08:00
parent f87f771956
commit e50534c1eb

View File

@ -2070,6 +2070,7 @@ assert((int)twice.invokeExact(21) == 42);
*/
public static
MethodHandle permuteArguments(MethodHandle target, MethodType newType, int... reorder) {
reorder = reorder.clone();
checkReorder(reorder, newType, target.type());
return target.permuteArguments(newType, reorder);
}
@ -2264,6 +2265,7 @@ assertEquals("yz", (String) d0.invokeExact(123, "x", "y", "z"));
throw newIllegalArgumentException("no argument type to remove");
ArrayList<Class<?>> ptypes = new ArrayList<>(oldType.parameterList());
ptypes.addAll(pos, valueTypes);
if (ptypes.size() != inargs) throw newIllegalArgumentException("valueTypes");
MethodType newType = MethodType.methodType(oldType.returnType(), ptypes);
return target.dropArguments(newType, pos, dropped);
}