Wait for Kryo 6: ImmutableCollections ListN nulls - #1302
Conversation
Stream.toList() can produce ListN instances that contain nulls, but the immutable list serializer assumed non-null elements and rebuilt lists with List.of/List.copyOf. Enable null element serialization and rebuild with stream().toList() per maintainer guidance on EsotericSoftware#1239. Fixes EsotericSoftware#1239
|
Thanks for the PR @arimu1. Unfortunately, this doesn't work for 2 reasons:
We will have to wait for Kryo 6 to merge this. Also I'd be interested to know how this affects performance. Can you do a benchmark (preferable JMH) and compare the performance of |
Requested on EsotericSoftware#1302 for the Kryo 6 reconstruction path, using the existing benchmarks module. Sizes 0, 1, 2, 10, 100, and 1000.
|
Thanks @theigl — agreed on both blockers.
I added
No production rewrite on this Kryo 5 PR. |
Kryo 5 cannot use Stream.toList (JDK 16+) and setElementsCanBeNull is not backwards compatible. Wait for Kryo 6; drop the JMH source from this tree.
|
Closing this Kryo 5 PR: there is no production path here. Waiting for Kryo 6 (JDK 11 cannot compile |
|
Thank you for the benchmark @arimu1! It is unfortunate that the stream API is so much slower. But I don't see another way to handle this. The only option would be to use reflection to check if the list allows nulls ( I have to revisit this once main is on JDK17+. |
Summary
This PR is not a Kryo 5 production change.
Stream.toList()can produceImmutableCollections$ListNinstances that contain nulls, but Kryo 5 cannot adopt that reconstruction path:Stream.toListis JDK 16+).setElementsCanBeNullis not backwards compatible.Per review on this PR, the production fix waits for Kryo 6. The Kryo 5 serializer/tests were reverted to
master(setElementsCanBeNull(false),List.of/List.copyOf). JMH numbers forList.ofvsStream.toListare in the thread: #1302 (comment)Related: #1239
Test plan
JdkImmutableListSerializerandImmutableCollectionsSerializersTestto upstreammasterImmutableListFactoryBenchmarkfrom this tree (JDK 11mvn installmust not compileStream.toList)