Avi-Levi / kryo

Automatically exported from code.google.com/p/kryo
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error in TreeMapSerializer MapReferenceResolver readObjects ID #81

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.Class has one TreeMap and two other same type member.
2.The other type members have same value.
3.Write and read.

What is the expected output? What do you see instead?
The second other type deserialize failed. Because when TreeMap deserialize 
,Comparator & TreeMap use same readObjects index. So all index after TreeMap is 
wrong, and reference fails.
In sample list below x2 will get wrong value.

What version of the Kryo are you using?
2.18

Please provide any additional information below.

public class TreeMapSerializerTestData implements Serializable {
    private static final long serialVersionUID = 8449423540690186724L;

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

    public TreeMapSerializerTestData(){
        treeMap=new TreeMap<String, Map<String, Object>>(new FakeComparator());
    }
    public TreeMapSerializerTestData(String name){
        treeMap=new TreeMap<String, Map<String, Object>>(new FakeComparator()); 
    }
    public static class FakeComparator implements Comparator<Object>, Serializable
    {
        private static final long serialVersionUID = 3667761299603933963L;
        public int compare(Object o, Object o1)
        {
            return 0;
        }
    }
}

Original issue reported on code.google.com by rawl...@gmail.com on 24 Jul 2012 at 9:39

GoogleCodeExporter commented 9 years ago
I think my issue is related.  We're using 2.14.  This one field cannot be 
serialized:

    public SortedStringIndex<List<T>> index = new SortedStringIndex<List<T>>();

Stack trace:

com.esotericsoftware.kryo.KryoException: java.lang.ClassCastException: 
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to 
java.lang.Class
Serialization trace:
index ([omitted package name (it's ours)])
digraphKeyMappedTokens ([omitted package name (it's ours)])
dynamicGraph ([omitted package name (it's ours)])
languageContainers ([omitted package name(it's ours)])
    at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:208)
    at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:393)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:187)
    at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:393)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:187)
    at com.esotericsoftware.kryo.Kryo.writeClassAndObject(Kryo.java:481)
    at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:95)
    at com.esotericsoftware.kryo.serializers.MapSerializer.write(MapSerializer.java:18)
    at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:393)
    at com.esotericsoftware.kryo.serializers.FieldSerializer.write(FieldSerializer.java:187)
    at com.esotericsoftware.kryo.Kryo.writeObject(Kryo.java:371)
    at [omitted package name (it's ours)](CacheWriter.java:64)
    at [omitted package name (it's ours)](CacheWriter.java:94)
    at [omitted package name (it's ours)](Publisher.java:98)
    at [omitted package name (it's ours)](QuickTest.java:229)
...

Original comment by seandod...@gmail.com on 31 Jul 2012 at 5:05

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r337.

Original comment by nathan.s...@gmail.com on 18 Aug 2012 at 4:02

GoogleCodeExporter commented 9 years ago
This one was interesting, see the javadocs for Kryo#references() and then 
TreeMapSerializer for the fix. Thanks for reporting the issue!

Original comment by nathan.s...@gmail.com on 18 Aug 2012 at 4:02