JDK-8150360 : augment/correct MethodHandle API documentation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2016-02-22
  • Updated: 2017-05-17
  • Resolved: 2016-02-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b108Fixed
Related Reports
Relates :  
Description
These two excerpts from the documentation of MethodHandles.tryFinally() contradict each other:

"The pseudocode for the resulting adapter looks as follows. In the code, {@code V} represents the result type of the {@code try/finally} construct; {@code A}/{@code a}, the types and values of arguments to the resulting handle consumed by the cleanup; and {@code B}/{@code b}, those of arguments to the resulting handle discarded by the cleanup."

"The {@code target} and {@code cleanup} handles' return types must be the same. Their parameter type lists also must be the same, but the {@code cleanup} handle must accept one or two more leading parameters"

Also, several handle combinators' documentation should be extended with this hint:

+     * <p>
+     * Note:  The resulting adapter is never a {@linkplain MethodHandle#asVarargsCollector
+     *  variable-arity method handle}, even if the original target method handle was.

This applies to MH.bindTo(), MHs.insertArguments(), MHs.filterArguments(), MHs.filterReturnValue(), and any other combinator which (usually) leaves a trailing argument list invariant, and therefore may surprise users when it produces a non-varargs output from a varargs input.