youxinren / kryo

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

Asynchronous deserialization: String instead of real class type is attempted to be set as a field #149

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. This class is used as a property in an abstract superclass: 
http://pastebin.com/L8DjuGhW
2. If deserialize the object synchronously, everything works fine. See the code 
in step 3. When it's not wrapped in a Runnable and started by an 
ExecutorService Thread it's deserialized correctly.
3. If I do it asynchronously (see: http://pastebin.com/mvWfV5Yy), I get this 
exception, because kryo tries to set an String instead of the MetaDataClass. 

ERROR [pool-5-thread-4] messaging.ZeroMqEventSink: 
java.lang.IllegalArgumentException: Can not set datatypes.MetaDataClass field 
events.AbstractBaseEvent.metaData to java.lang.String
Serialization trace:
metaData (entities.LocationEvent)
com.esotericsoftware.kryo.KryoException: java.lang.IllegalArgumentException: 
Can not set datatypes.MetaDataClass field entities.AbstractBaseEvent.metaData 
to java.lang.String
Serialization trace:
metaData (entities.LocationEvent)
    at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:626) ~[kryo-2.20.jar:?]
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:221) ~[kryo-2.20.jar:?]
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:629) ~[kryo-2.20.jar:?]
    at messaging.ZeroMqEventSink$DeserRunnable.getObject(ZeroMqEventSink.java:155) ~[classes/:?]
    at messaging.ZeroMqEventSink$DeserRunnable.run(ZeroMqEventSink.java:103) ~[classes/:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[?:1.7.0_40-ea]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[?:1.7.0_40-ea]
    at java.lang.Thread.run(Thread.java:724) ~[?:1.7.0_40-ea]
Caused by: java.lang.IllegalArgumentException: Can not set 
entities.datatypes.MetaDataClass field 
entities.events.AbstractBaseEvent.metaData to java.lang.String
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:164) ~[?:1.7.0_40-ea]
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:168) ~[?:1.7.0_40-ea]
    at sun.reflect.UnsafeObjectFieldAccessorImpl.set(UnsafeObjectFieldAccessorImpl.java:81) ~[?:1.7.0_40-ea]
    at java.lang.reflect.Field.set(Field.java:741) ~[?:1.7.0_40-ea]
    at com.esotericsoftware.kryo.serializers.FieldSerializer$ObjectField.read(FieldSerializer.java:619) ~[kryo-2.20.jar:?]
    ... 7 more

What is the expected output? What do you see instead?
Kryo serializes the field correctly, but when done asynchronously Kryo tries to 
set the field as a String.

What version of the Kryo are you using?
2.20

Please provide any additional information below.

Original issue reported on code.google.com by dabuks...@gmail.com on 24 Mar 2014 at 9:01

GoogleCodeExporter commented 9 years ago
The exact same code executed with kryo 2.22 yields this interesting error for 
every deserialized object (only the size values vary):

2014-03-24 22:05:08,499 ERROR [pool-5-thread-7] .messaging.ZeroMqEventSink: 
java.lang.IndexOutOfBoundsException: Index: 108, Size: 53
Serialization trace:
metaData (entities.events.DocumentEvent)
com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: 
Index: 108, Size: 53
Serialization trace:
metaData (entities.events.DocumentEvent)
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) ~[kryo-2.22.jar:?]
    at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:507) ~[kryo-2.22.jar:?]
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:672) ~[kryo-2.22.jar:?]
    at messaging.ZeroMqEventSink$DeserRunnable.getObject(ZeroMqEventSink.java:155) ~[classes/:?]
    at messaging.ZeroMqEventSink$DeserRunnable.run(ZeroMqEventSink.java:103) ~[classes/:?]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[?:1.7.0_40-ea]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[?:1.7.0_40-ea]
    at java.lang.Thread.run(Thread.java:724) ~[?:1.7.0_40-ea]
Caused by: java.lang.IndexOutOfBoundsException: Index: 108, Size: 53
    at java.util.ArrayList.rangeCheck(ArrayList.java:635) ~[?:1.7.0_40-ea]
    at java.util.ArrayList.get(ArrayList.java:411) ~[?:1.7.0_40-ea]
    at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42) ~[kryo-2.22.jar:?]
    at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:820) ~[kryo-2.22.jar:?]
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:692) ~[kryo-2.22.jar:?]
    at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106) ~[kryo-2.22.jar:?]
    ... 7 more
#
[thread 30979 also had an error]
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x0000000101dd9923, pid=7027, tid=35075
#
# JRE version: Java(TM) SE Runtime Environment (7.0_40-b35) (build 
1.7.0_40-ea-b35)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.0-b54 mixed mode bsd-amd64 
compressed oops)
# Problematic frame:
# J  java.util.HashMap.hash(Ljava/lang/Object;)I
#
# Failed to write core dump. Core dumps have been disabled. To enable core 
dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /Users/logs/hs_err_pid7027.log
Compiled method (c2)   35064   32             java.util.HashMap::hash (55 bytes)
 total in heap  [0x0000000101dd9790,0x0000000101dd9b90] = 1024
 relocation     [0x0000000101dd98b0,0x0000000101dd98e0] = 48
 main code      [0x0000000101dd98e0,0x0000000101dd9a40] = 352
 stub code      [0x0000000101dd9a40,0x0000000101dd9a68] = 40
 oops           [0x0000000101dd9a68,0x0000000101dd9a78] = 16
 scopes data    [0x0000000101dd9a78,0x0000000101dd9ad8] = 96
 scopes pcs     [0x0000000101dd9ad8,0x0000000101dd9b48] = 112
 dependencies   [0x0000000101dd9b48,0x0000000101dd9b50] = 8
 handler table  [0x0000000101dd9b50,0x0000000101dd9b80] = 48
 nul chk table  [0x0000000101dd9b80,0x0000000101dd9b90] = 16
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#

Original comment by dabuks...@gmail.com on 24 Mar 2014 at 9:12

GoogleCodeExporter commented 9 years ago
Moved to https://github.com/EsotericSoftware/kryo/issues/206

Original comment by dabuks...@gmail.com on 25 Mar 2014 at 4:26