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

filterArguments runs multiple filters in the wrong order

    Details

    • Type: CSR
    • Status: Closed
    • Priority: P3
    • Resolution: Approved
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      behavioral
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      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.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: