Skip to content

Lambda field (functional interface) deserialize failed with CompatiableFieldSerializer #821

@nicreve

Description

@nicreve

Describe the bug
We have a class with a field to store lambda, the field's class is a functional interface, something like this:

public class TestClass implements Serializable {
    private static final long serialVersionUID = 4061358520297707007L;

    @FunctionalInterface
    public interface Callback extends Serializable {
        void execute();
    }

    private Callback callback;
}

When serialize then deserialize this class with CompatiableFieldSerializer, we encountered this exception:

Caused by: com.esotericsoftware.kryo.KryoException: Read type is incompatible with the field type: com.esotericsoftware.kryo.serializers.ClosureSerializer$Closure -> com.esotericsoftware.kryo.serializers.ClosureSerializer$Closure (com.xxx.TestClass#callback)

I believe it's because CompatiableFieldSerializer cached the field's value class (set to TestClass#callback) during serialization, but the actual output content is ClosureSerializer$Closure. Then during deserialization, it's mismatched.
To Reproduce
Use CompatiableFieldSerializer to serialize a class with lambda field(s), then deserialize it.

Environment:

  • OS: Ubuntu 20.04
  • JDK Version: 8
  • Kryo Version: 5.0.4

Additional context
I switch to FieldSerializer it works fine, but I didn't test TaggedFieldSerializer and VersionFieldSerializer.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions