Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8201371

filterArguments runs multiple filters in the wrong order

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • core-libs
    • None
    • behavioral
    • minimal
    • Minimal. The likelyhood of existing method handle filter argument code relying on invocation in argument order from right to left is considered very small, since it is expected most filters will not be stateful in their results.
    • Java API
    • SE

      Summary

      Fix the implementation of MethodHandles.filterArguments to conform to the specification (the pseudocode) and clarify the specification as the pseudocode behaviour could easily be missed.

      Problem

      MethodHandles.filterArguments pseudocode specifies that the filter method handles are invoked in argument order from left to right. However, the implementation invoked the filter method handles from right to left. This behaviour is observable if the filter arguments retain some global state that affects the results, likely an edge case. However that edge case is exposed for string concatenation using invokedynamic where the toString implementation has side-effects that affect the String result (see JDK-8200118).

      Solution

      Fix the implementation to invoke filter method handles in argument order from left to right. Clarify the specification.

      Specification

      Update to JavaDoc of java/lang/invoke/MethodHandles.java:

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

            psandoz Paul Sandoz
            jrose John Rose
            Alan Bateman, Aleksey Shipilev
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: