JDK-8275387 : Incorrect deserialization of a method reference with additional marker interface
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang.invoke
  • Affected Version: 8,11,17,18
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2021-10-16
  • Updated: 2021-10-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
If some class is a capturing class for several method references to the same method, method references with additional marker interfaces might be deserialized incorrectly.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the given source code.



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This code should write the following to standard output:

y1 IS Marker1
y1 IS NOT Marker2
y2 IS NOT Marker1
y2 IS Marker2
ACTUAL -
Actual output is:

y1 IS Marker1
y1 IS NOT Marker2
y2 IS Marker1
y2 IS NOT Marker2

---------- BEGIN SOURCE ----------
import java.io.*;

public class Test {
    public interface IFoo extends Serializable {
        void foo();
    }

    public interface Marker1 {
    }

    public interface Marker2 {
    }

    public static void foo() {
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Object x1 = (IFoo & Marker1) Test::foo;
        Object y1 = roundtrip(x1);

        Object x2 = (IFoo & Marker2) Test::foo;
        Object y2 = roundtrip(x2);

        check(y1, "y1");
        check(y2, "y2");
    }

    private static void check(Object y, String name) {
        if (y instanceof Marker1) {
            System.out.println(name + " IS Marker1");
        } else {
            System.out.println(name + " IS NOT Marker1");
        }

        if (y instanceof Marker2) {
            System.out.println(name + " IS Marker2");
        } else {
            System.out.println(name + " IS NOT Marker2");
        }
    }

    private static Object roundtrip(Object x) throws IOException, ClassNotFoundException {
        ByteArrayOutputStream out1 = new ByteArrayOutputStream();
        new ObjectOutputStream(out1).writeObject(x);
        return new ObjectInputStream(new ByteArrayInputStream(out1.toByteArray())).readObject();
    }
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
Please take a look, as it is related to similar bug you've looked at. tnx
20-10-2021

JDK-8208752 seems to be related. The root cause is always the same: java.lang.invoke.SerializedLambda can not hold enough information to correctly identify the which lambda should be (de-)serialized.
19-10-2021

The observations on Windows 10: JDK 8: Failed, y2 IS Marker1 JDK 11: Failed. JDK 17: Failed. JDK 18ea+1: Failed.
18-10-2021