chill icon indicating copy to clipboard operation
chill copied to clipboard

Java8 lambda expression in PriorityQueue cannot be serialized

Open Jiayi-Liao opened this issue 4 years ago • 4 comments

When I'm using PriorityQueueSerializer from chill-java package, I got NPE when serializing PriorityQueue instance like this:

PriorityQueue<String> pq = new PriorityQueue<>((o1, o2) -> o1.length() - o2.length() - 1);
pq.add("1234135");
pq.add("12323424135");
java.lang.NullPointerException
	at com.esotericsoftware.kryo.util.DefaultClassResolver.writeClass(DefaultClassResolver.java:80)
	at com.esotericsoftware.kryo.Kryo.writeClass(Kryo.java:488)
	at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:593)

Perhaps it's because the lambda expression is not serializable. But the strange thing is that when I removed the registration of PriorityQueueSerializer from kryo's registrations, the serialization works.

Is this expected?

Jiayi-Liao avatar Apr 22 '20 14:04 Jiayi-Liao

thanks for the bug report. This isn't expected. So, this is a bug. Would you be willing to open a PR with a test that shows the bug?

johnynek avatar Apr 27 '20 03:04 johnynek

note, we have a test here:

https://github.com/twitter/chill/blob/develop/chill-java/src/test/scala/com/twitter/chill/java/PriorityQueueTest.scala

johnynek avatar Apr 27 '20 03:04 johnynek

here is the serializer: https://github.com/twitter/chill/blob/develop/chill-java/src/main/java/com/twitter/chill/java/PriorityQueueSerializer.java

johnynek avatar Apr 27 '20 03:04 johnynek

@johnynek Hi, I've created a PR to reproduce the problem (not a NPE but the same strange phenomenon). Could you take a look ?

By the way I notice that this project is still using java 1.6, does it mean that the project doesn't support java 1.8 and also dosen't take the java 1.8 lambda expression into consideration?

Jiayi-Liao avatar Apr 27 '20 05:04 Jiayi-Liao