Hello,
I am using Kryo 3.0.0.
Occasionally (once every thousands-millions of calls to serialize/deserialize but with not apparent pattern), I am encountering the exception below.
I don't have the exact scenario, but I have done some digging/debugging.
It occurs when I am trying to serialize a HashMap<String, String> with 5 values. This HashMap is not an object field, but is being serialized by itself. Nevertheless, when the issue occurs, I see in the debugger that the generics fields are set on the MapSerialzier, which causes the class information not to be written during serialization. As a result, during deserialziation kryo thinks the first key in the map ("Location") is the class of the key, which causes the exception below.
I am using KryoPool, so it is probably not a multi-threading issue. Also, if it was a multi-threading issue, I'd expect to see different errors each time, and that is the only error I experience, even though kryo is used heavily in multiple components in the application.
I thought that perhaps somehow a MapSerializer instance becomes dirty with generics info which isn't being cleared (in my scenario/flow multiple objects are being serialized and deserialized by this kryo instance before the issue occurs), but looking at the code I couldn't find a scenario which leads to this behaviour.
I'd greatly appreciate some help (so far I've already invested a few days of work into this research). I have also looked a bit in any potential changes in the code up until Kryo 4, and none seems to address this issue.
Exception:
Caused by: com.esotericsoftware.kryo.KryoException: Unable to find class: ocation
at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:138)
at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass(DefaultClassResolver.java:115)
at com.esotericsoftware.kryo.Kryo.readClass(Kryo.java:666)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:777)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:135)
at com.esotericsoftware.kryo.serializers.MapSerializer.read(MapSerializer.java:21)
at com.esotericsoftware.kryo.Kryo.readClassAndObject(Kryo.java:786)
at com.aeroscout.mobileview.common.util.SerializationUtils.deserializeObject(SerializationUtils.java:82)
... 15 more
Caused by: java.lang.ClassNotFoundException: ocation
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1332)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1166)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.esotericsoftware.kryo.util.DefaultClassResolver.readName(DefaultClassResolver.java:136)
... 22 more
Thanks,
Mark