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

Method reference identity is broken by serialization

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 11
    • core-libs
    • None
    • behavioral
    • minimal
    • Java API
    • SE

      Summary

      Specify that the identity of a function object produced from a lambda expression or method reference (specifically that produced by the invocation of the LambdaMetafactory's CallSite's target) or produced by deserialization of a serialized lambda can be unpredictable.

      Problem

      The intention was that the identity of function objects is unpredictable but it is not specified.

      Solution

      Specify that the identity of a function object produced from a lambda expression or method reference (specifically that produced by the invocation of the LambdaMetafactory's CallSite's target) or produced by deserialization of a serialized lambda can be unpredictable.

      Different implementations may be unpredictable, or different invocations or deserializations within the same implementation may also be unpredictable.

      JDK-8204255 tracks an informational update to section 15.27.4 of the language specification.

      Specification

      diff --git a/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java b/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java
      --- a/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java
      +++ b/src/java.base/share/classes/java/lang/invoke/LambdaMetafactory.java
      @@ -61,7 +61,13 @@
        *     parameters</em>, which must be provided as arguments to the
        *     {@code CallSite} target, and which may be early-bound to the behavior
        *     {@code MethodHandle}.  The number of captured parameters and their types
      - *     are determined during linkage.</li>
      + *     are determined during linkage.
      + *     The identity of a function object produced by invoking the
      + *     {@code CallSite}'s target is unpredictable, and therefore
      + *     identity-sensitive operations (such as reference equality, object
      + *     locking, and {@code System.identityHashCode()} may produce different
      + *     results in different implementations, or even upon different invocations
      + *     in the same implementation.</li>
        *
        *     <li><em>Invocation</em> occurs when an implemented interface method
        *     is invoked on a function object.  This may occur many times for a single
      diff --git a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
      --- a/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
      +++ b/src/java.base/share/classes/java/lang/invoke/SerializedLambda.java
      @@ -53,6 +53,12 @@
        * that the properties of the {@code SerializedLambda} are consistent with a
        * lambda actually captured by that class.
        *
      + * <p>The identity of a function object produced by deserializing the serialized
      + * form is unpredictable, and therefore identity-sensitive operations (such as
      + * reference equality, object locking, and {@code System.identityHashCode()} may
      + * produce different results in different implementations, or even upon
      + * different deserializations in the same implementation.
      + *
        * @see LambdaMetafactory
        * @since 1.8
        */

            psandoz Paul Sandoz
            shade Aleksey Shipilev
            Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: