You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
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
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)
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.
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
The text was updated successfully, but these errors were encountered: