Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PriorityQueueSerializer fails to load empty empty queue #865

Closed
holgerbrandl opened this issue Nov 10, 2021 · 3 comments · Fixed by #866
Closed

PriorityQueueSerializer fails to load empty empty queue #865

holgerbrandl opened this issue Nov 10, 2021 · 3 comments · Fixed by #866
Labels

Comments

@holgerbrandl
Copy link

Describe the bug
Consider the following example:

PriorityQueue<String> foo  = new PriorityQueue<>();

Kryo kryo = KryoKoinKt.buildKryoKoin();

File saveFile = new File("dat.bin");
Output o = new Output(new FileOutputStream(saveFile));
kryo.writeObject(o, foo);
o.close();

Input i = new Input(new FileInputStream(saveFile));

PriorityQueue<String> restored = kryo.readObject(i, PriorityQueue.class);

System.out.println(restored);

Expected: it should read the empty queue.

Observed:

Exception in thread "main" java.lang.IllegalArgumentException
	at java.base/java.util.PriorityQueue.<init>(PriorityQueue.java:171)
	at com.esotericsoftware.kryo.serializers.DefaultSerializers$PriorityQueueSerializer.createPriorityQueue(DefaultSerializers.java:746)
	at com.esotericsoftware.kryo.serializers.DefaultSerializers$PriorityQueueSerializer.create(DefaultSerializers.java:738)
	at com.esotericsoftware.kryo.serializers.DefaultSerializers$PriorityQueueSerializer.create(DefaultSerializers.java:732)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:216)
	at com.esotericsoftware.kryo.serializers.CollectionSerializer.read(CollectionSerializer.java:44)
	at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:774)
	at KryoPrioMap.main(KryoPrioMap.java:25)

Environment:

  • OS: Windows
  • JDK Version: 11
  • Kryo Version: 5.2
@theigl
Copy link
Collaborator

theigl commented Nov 10, 2021

Good catch. I think we need to use a minimum capacity of 1.

@theigl
Copy link
Collaborator

theigl commented Nov 10, 2021

Fixed. Please test against the lastest snapshot.

@holgerbrandl
Copy link
Author

Works for me. Thanks for the quick update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants