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

Jorn Vernee jvernee at openjdk.java.net
Tue Jan 12 19:21:08 UTC 2021


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).


Testing: tier1-tier2


Commit messages:
 - Avoid NPEs in permuteArguments in cases where parameters are dropped from LambdaForms that don't have any other names (e.g. empty)

Changes: https://git.openjdk.java.net/jdk/pull/2054/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2054&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8255531
  Stats: 9 lines in 2 files changed: 8 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2054.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2054/head:pull/2054

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

More information about the core-libs-dev mailing list