mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8194554: filterArguments runs multiple filters in the wrong order
Reviewed-by: psandoz, jrose
This commit is contained in:
parent
22762d1cdc
commit
869f9e2ed0
2 changed files with 138 additions and 4 deletions
|
@ -3766,6 +3766,7 @@ assertEquals("xy", h3.invoke("x", "y", 1, "a", "b", "c"));
|
|||
* specified in the elements of the {@code filters} array.
|
||||
* The first element of the filter array corresponds to the {@code pos}
|
||||
* argument of the target, and so on in sequence.
|
||||
* The filter functions are invoked in left to right order.
|
||||
* <p>
|
||||
* Null arguments in the array are treated as identity functions,
|
||||
* and the corresponding arguments left unchanged.
|
||||
|
@ -3836,11 +3837,12 @@ assertEquals("XY", (String) f2.invokeExact("x", "y")); // XY
|
|||
MethodHandle filterArguments(MethodHandle target, int pos, MethodHandle... filters) {
|
||||
filterArgumentsCheckArity(target, pos, filters);
|
||||
MethodHandle adapter = target;
|
||||
int curPos = pos-1; // pre-incremented
|
||||
for (MethodHandle filter : filters) {
|
||||
curPos += 1;
|
||||
// process filters in reverse order so that the invocation of
|
||||
// the resulting adapter will invoke the filters in left-to-right order
|
||||
for (int i = filters.length - 1; i >= 0; --i) {
|
||||
MethodHandle filter = filters[i];
|
||||
if (filter == null) continue; // ignore null elements of filters
|
||||
adapter = filterArgument(adapter, curPos, filter);
|
||||
adapter = filterArgument(adapter, pos + i, filter);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue