Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Varargs.invokeWithArguments to process excess paramenter #7163

Merged
merged 1 commit into from
Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ int getModifiers() throws InternalError {
static MethodType varargsCollectorType(MethodType nextType, Class<?> arrayType) {
return nextType.changeParameterType(nextType.parameterCount() - 1, arrayType);
}


@Override
public Object invokeWithArguments(Object... args) throws Throwable, WrongMethodTypeException, ClassCastException {
int argsLength = 0;
if (args != null) {
Expand All @@ -122,9 +123,18 @@ public Object invokeWithArguments(Object... args) throws Throwable, WrongMethodT
for (int i = 0; i < numTrailingArgs; i++) {
arraySetter.invoke(trailingArgs, i, args[mhLength - 1 + i]);
}
args = Arrays.copyOf(args, mhLength);
args[mhLength - 1] = trailingArgs;
return this.asFixedArity().invokeWithArguments(args);

/* Create new object array to store the arguments
* This is to avoid the case where args passed to invokeWithArguments
* is a typed array (ie. not Object[]) which generates ArrayStoreException
*/
Object[] newArgs = new Object[mhLength];
for (int i = 0; i < mhLength - 1; i++) {
newArgs[i] = args[i];
}
newArgs[mhLength - 1] = trailingArgs;

return this.asFixedArity().invokeWithArguments(newArgs);
} else
/*[ENDIF]*/
{
Expand Down