--- a/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Fri Sep 23 03:15:00 2016 -0700
+++ b/jdk/src/java.base/share/classes/java/lang/invoke/MethodHandles.java Fri Sep 23 15:20:49 2016 +0200
@@ -4368,10 +4368,11 @@
}
// Step 4: fill in missing parameter types.
- List<MethodHandle> finit = fillParameterTypes(init, commonSuffix);
- List<MethodHandle> fstep = fillParameterTypes(step, commonParameterSequence);
- List<MethodHandle> fpred = fillParameterTypes(pred, commonParameterSequence);
- List<MethodHandle> ffini = fillParameterTypes(fini, commonParameterSequence);
+ // Also convert all handles to fixed-arity handles.
+ List<MethodHandle> finit = fixArities(fillParameterTypes(init, commonSuffix));
+ List<MethodHandle> fstep = fixArities(fillParameterTypes(step, commonParameterSequence));
+ List<MethodHandle> fpred = fixArities(fillParameterTypes(pred, commonParameterSequence));
+ List<MethodHandle> ffini = fixArities(fillParameterTypes(fini, commonParameterSequence));
assert finit.stream().map(MethodHandle::type).map(MethodType::parameterList).
allMatch(pl -> pl.equals(commonSuffix));
@@ -4389,6 +4390,10 @@
}).collect(Collectors.toList());
}
+ private static List<MethodHandle> fixArities(List<MethodHandle> hs) {
+ return hs.stream().map(MethodHandle::asFixedArity).collect(Collectors.toList());
+ }
+
/**
* Constructs a {@code while} loop from an initializer, a body, and a predicate. This is a convenience wrapper for
* the {@linkplain #loop(MethodHandle[][]) generic loop combinator}.
@@ -4887,7 +4892,8 @@
// target parameter list.
cleanup = dropArgumentsToMatch(cleanup, (rtype == void.class ? 1 : 2), targetParamTypes, 0);
- return MethodHandleImpl.makeTryFinally(target, cleanup, rtype, targetParamTypes);
+ // Use asFixedArity() to avoid unnecessary boxing of last argument for VarargsCollector case.
+ return MethodHandleImpl.makeTryFinally(target.asFixedArity(), cleanup.asFixedArity(), rtype, targetParamTypes);
}
/**