Skip to content

Commit

Permalink
Merge pull request #7163 from fengxue-IS/mhinvokeloop
Browse files Browse the repository at this point in the history
Fix Varargs.invokeWithArguments to process excess paramenter
  • Loading branch information
DanHeidinga committed Oct 8, 2019
2 parents c3b8f18 + f74f34b commit cd07261
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit cd07261

Please sign in to comment.