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

TreeMap deserialization error #112

Closed
ghost opened this issue Nov 11, 2013 · 2 comments
Closed

TreeMap deserialization error #112

ghost opened this issue Nov 11, 2013 · 2 comments

Comments

@ghost
Copy link

ghost commented Nov 11, 2013

From michael....@gmail.com on April 29, 2013 10:15:36

What steps will reproduce the problem?
test code:
bean for serialization
public class TreeMapSerializerTestData implements Serializable {
private static final long serialVersionUID = 8449423540690186724L;

public String x1 = "abc";
private Map<String, String> treeMap;
public String x2 = "abc";
public String x3 = "def";

public TreeMapSerializerTestData() {
treeMap = new TreeMap<String, String>(new FakeComparator());
}

public TreeMapSerializerTestData(Map<String, String> init) {
treeMap = new TreeMap<String, String>(new FakeComparator());
treeMap.putAll(init);
}

public static class FakeComparator implements Comparator<String>, Serializable {
private static final long serialVersionUID = 3667761299603933963L;

@OverRide
public int compare(String o1, String o2) {
return o2.compareTo(o1);
}
}
}

client code:
public void testTreeMap2() {
TreeMapSerializerTestData tm =
new TreeMapSerializerTestData(ImmutableMap.of("zxczxc", "qweasd", "fghfghd", "567652", "vbnvbn", "2013-04-29"));

Kryo kryo = new Kryo();
Output output = new Output(16384, 1024*1024);
kryo.writeClassAndObject(output, tm);
output.close();

byte[] bytes = output.toBytes();
TreeMapSerializerTestData utm = (TreeMapSerializerTestData) kryo.readClassAndObject(new Input(bytes));

assertEquals(utm, tm);
}

What is the expected output? What do you see instead?
I expect test passed, but get exception instead:

com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: Index: 120, Size: 2
Serialization trace:
treeMap (com.zina.serializer.beans.test.TreeMapSerializerTestData)
at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:626)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:221)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:729)
...
Caused by: java.lang.IndexOutOfBoundsException: Index: 120, Size: 2
at java.util.ArrayList.RangeCheck(ArrayList.java:547)
at java.util.ArrayList.get(ArrayList.java:322)
at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42)
at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:773)
at com.esotericsoftware.kryo.Kryo.readObjectOrNull(Kryo.java:697)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:122)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:17)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:648)
at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:605)
... 26 more


What version of the Kryo are you using?
2.21 has this issue, 2.20 - no

Please provide any additional information below.
Any class that contains TreeMap fails to deserialize - sometimes get java.lang.IndexOutOfBoundsException, sometimes class cast exception

Original issue: http://code.google.com/p/kryo/issues/detail?id=112

@ghost
Copy link
Author

ghost commented Nov 11, 2013

From mat...@peel.com on May 09, 2013 13:00:45

I'm experiencing the same problem with using Kryo 2.21 -- and my class contains TreeMap:

May 09 19:47:42 ERROR - Something went wrong: java.lang.IndexOutOfBoundsException: Index: 118, Size: 0
java.lang.IndexOutOfBoundsException: Index: 118, Size: 0
at java.util.ArrayList.rangeCheck(ArrayList.java:571)
at java.util.ArrayList.get(ArrayList.java:349)
at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42)
at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:773)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:624)
at java.lang.Thread.run(Thread.java:679)

@ghost
Copy link
Author

ghost commented Nov 11, 2013

From romixlev on July 23, 2013 06:21:04

Hi Michael,

Yes. This is a bug and it is now fixed in trunk, i.e. in the v2.22-SNAPSHOT
Thanks for reporting it!

-Leo

Status: Verified

@ghost ghost closed this as completed Nov 11, 2013
@ink-ua
Copy link

ink-ua commented Apr 25, 2014

Hi,

I have a similar IndexOutOfBoundsException error with Kryo 2.21 and ConcurrentHashMap, but in my case it's a new field added to the new version of class. Could someone please point out which commit fixed this issue? So I can check if this fixes my issue. Unfortunately we can't just upgrade to kryo 2.22 or more because of binary incompatibility of serialized data.

Thanks in advance

@romix
Copy link
Collaborator

romix commented Apr 25, 2014

If I'm not mistaken, this is this commit:
00ffc7e

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants