On Mon, 5 Oct 2026 02:53:37 GMT, Yunbo Zhang <[email protected]> wrote:
>> Please review this small fix. >> >> `MethodHandles.foldArguments` throws an unspecified >> `ArrayIndexOutOfBoundsException` for negative `pos` values. Extreme values >> such as `Integer.MAX_VALUE` can also overflow the existing addition-based >> bounds check. >> >> **Fix:** >> >> Reject invalid positions with `IllegalArgumentException` and include the >> position in the error message. Use a subtraction-based bounds check to avoid >> overflow, and document the valid range for `pos`. >> >> **Testing:** >> >> - Added regression tests. >> - `make test TEST=test/jdk/java/lang/invoke`: 198 passed, 4 excluded, 0 >> failed. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Yunbo Zhang has updated the pull request incrementally with one additional > commit since the last revision: > > 8367022: MethodHandles.foldArguments throws unspecified > ArrayIndexOutOfBoundsException for negative pos > > Document the legal fold position range and report an invalid position > before checking target and combiner types. Two suggestions: 1. The list of conditions can be an HTML `<ol><li></ol>` 2. The OOB condition can be something more straightforward, like: {@code pos} is negative or greater than the target's arity, or there is not sufficient arguments after {@code pos} in {@code target} to match {@code combiner} ------------- Marked as reviewed by liach (Reviewer). PR Review: https://git.openjdk.org/jdk/pull/32618#pullrequestreview-5459971823
