Bug 537047 - [1.8] Lambda serialization error when using method references vs lambdas expressions
Summary: [1.8] Lambda serialization error when using method references vs lambdas expr...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Srikanth Sankaran CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-15 15:44 EDT by Jonathan Fomby CLA
Modified: 2023-06-01 05:25 EDT (History)
3 users (show)

See Also:


Attachments
Standalone class demonstrating bug (1.87 KB, text/x-java)
2018-07-15 15:44 EDT, Jonathan Fomby CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Fomby CLA 2018-07-15 15:44:25 EDT
Created attachment 274988 [details]
Standalone class demonstrating bug

I recently upgraded from Mars to Photon, and quickly ran into some unexpected problems with the new compiler.

Basically, Serializing and then deserializing a lambda declared via the normal arrow syntax works fine, but if the lambda is declared via the method reference then the subsequent deserialization fails.

This sounds similar to https://bugs.eclipse.org/bugs/show_bug.cgi?id=516620 but will fail when serializing/deserializing everything via eclipse.

// simulating a Wicket Model
public static class DummyModel<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private T object;

    public DummyModel(T t) {
        this.object = t;
    }

    public T getObject() {
        return object;
    }
}

// Shows the working and failing methods
@SuppressWarnings("unchecked")
public void runTest() throws IOException, ClassNotFoundException {
    final DummyModel<Boolean> booleanModel = new DummyModel<Boolean>(false);

    // Works with both eclipse and javac
    Object supp0 = (Serializable & Supplier<Boolean>) () -> booleanModel.getObject();
    System.out.println("result 0 - " + deserialize(serialize(supp0)).getClass());

    // Works with both javac but not eclipse
    Object supp1 = (Serializable & Supplier<Boolean>) booleanModel::getObject;
    System.out.println("result 1 - " + deserialize(serialize(supp1)).getClass());
}

// Error
Exception in thread "main" java.io.IOException: unexpected exception type
...
Caused by: java.lang.reflect.InvocationTargetException
....
Caused by: java.lang.IllegalArgumentException: Invalid lambda deserialization
	at SerializationBug.$deserializeLambda$(SerializationBug.java:1)
	... 16 more
Comment 1 Alexander Lehmann CLA 2020-05-13 05:32:03 EDT
This could be a duplicate of https://bugs.eclipse.org/bugs/show_bug.cgi?id=515323
Comment 2 Stephan Herrmann CLA 2020-05-14 17:37:07 EDT
(In reply to Alexander Lehmann from comment #1)
> This could be a duplicate of
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=515323

related but not necessarily the same. See that the other bug is specifically about a difference between a lambda an an equivalent method reference.
Comment 3 Eclipse Genie CLA 2022-05-05 16:26:14 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Srikanth Sankaran CLA 2023-06-01 05:25:44 EDT
I don't see the problem with master.