When deserializing a serialized object (from a file) using Kryo, I get the following exception:
java.lang.ExceptionInInitializerError
(...)
Caused by: com.esotericsoftware.kryo.KryoException: (...)
Serialization trace: (...)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125)
at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:786)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:143)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:21)
at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:682)
(...)
Caused by: java.lang.IndexOutOfBoundsException: Index: 1582, Size: 2
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42)
at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:830)
at com.esotericsoftware.kryo.Kryo.readObjectOrNull(Kryo.java:753)
at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:113)
... 27 more
My hypothesis is that the serialized format is not properly understood when deserializing (ie. it changed). The Kryo version for serializing and deserializing was the same. The java version could have been different at the time of serialization: could this be an explanation?
If not, any other hints on what my generate such exceptions are more than welcome!
Many thanks, Thomas
UPDATE: as suggested, hereby the class that is being deserialized from the file
The main class deserialized is HashMap<Integer, PreflopEhsVO>
where the custom class definitions (child and parent) are:
public class PreflopEhsVOExtended extends PreflopEhsVO{
private int numbValues = 0;
public synchronized void addValue(PreflopEhsVO values){
if (numbValues == 0) this.valuesPerNumbOpp = values.valuesPerNumbOpp;
else{
//Weighted avg
for (int i=0; i<this.valuesPerNumbOpp.length; ++i) this.valuesPerNumbOpp[i] = (this.valuesPerNumbOpp[i] * numbValues + values.valuesPerNumbOpp[i]) / (float) (numbValues + 1);
++numbValues;
}
}
public PreflopEhsVOExtended(PreflopEhsVO values) {
this.valuesPerNumbOpp = values.valuesPerNumbOpp;
this.numbValues = 1;
}
}
public class PreflopEhsVO {
public float[] valuesPerNumbOpp = new float[9];
public PreflopEhsVO(){
}
public PreflopEhsVO(float[] valuesPerNumbOpp) {
this.valuesPerNumbOpp = valuesPerNumbOpp;
}
}