RFR: 8255531: MethodHandles::permuteArguments throws NPE when duplicating dropped arguments

Claes Redestad redestad at openjdk.java.net
Wed Jan 20 23:22:54 UTC 2021

On Tue, 12 Jan 2021 16:58:45 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

> Hi,
> This small patch fixes the NPE in the following case:
>     MethodHandle mh = MethodHandles.empty(MethodType.methodType(void.class, int.class, int.class));
>     MethodHandles.permuteArguments(mh, MethodType.methodType(void.class, int.class), 0, 0);
> If a parameter name was changed by a lambda form edit, `LambdaForm::endEdit` will try to sort the names that fall into the old range of parameter names (starting from `firstChanged` and up to `arity` in the code) to make sure that non-parameter names (`exprs`) properly appear after parameter names. But, if a parameter was dropped, and there are no non-paramter names, a `null` will fall into the range that is being sorted, and the call to `name.isParam()` in the sorting algorithm will result in an NPE.
> We can just add a `name != null` check there, since `null` is definitely not a parameter. However, we still need to do the loop in order to get an accurate `exprp` value, which is later used to adjust the `arity` after sorting (there are other ways to get there that don't involve copying the extra `null`, but they are more convoluted, so I elected to go for this solution).
> Thanks,
> Jorn
> Testing: tier1-tier2



Marked as reviewed by redestad (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/2054

More information about the core-libs-dev mailing list