lishunli / kryo

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

Registered Class IDs failing #104

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Android App saves out an object using registered classes.
(On a side note when trying to register as class's 1,2,3 this failed because 
the IDs seemed to already be in use so moved the range).
m_kryo =  new Kryo();
m_kryo.register(someclassA.class, 10);
m_kryo.register(someclassB.class, 12);
m_kryo.register(someclassC.class, 14);

2. On windows I have an app that will read in the files, written in Java.
m_kryo =  new Kryo();
m_kryo.register(someclassA.class, 10);
m_kryo.register(someclassB.class, 12);
m_kryo.register(someclassC.class, 14);

Again I have the same setup for Kryo making sure the ID's are the same

What is the expected output? 
I expect to open the object in the windows app

What do you see instead?
I get an exception :-
com.esotericsoftware.kryo.KryoException: Encountered unregistered class ID: 121
Serialization trace:
values (someclassB)
fields (someclassA)

What version of the Kryo are you using?
2.21

Please provide any additional information below.
As you can see its talking about an unregistered class, 121. Also this file is 
opened and closed many times in the Android app, during app usage then again 
after a device reboot and seems to work fine.
I'm sure sure why its looking for class ID 121 when clearly i'm registering it 
as 12.

Original issue reported on code.google.com by me...@ntlworld.com on 11 Mar 2013 at 11:18

GoogleCodeExporter commented 9 years ago
Tried
m_kryo.register(someclassB.class, 111);
m_kryo.register(someclassA.class, 112);
m_kryo.register(someclassC.class, 113);

"Encountered unregistered class ID: 121", same error.

Original comment by me...@ntlworld.com on 11 Mar 2013 at 12:03

GoogleCodeExporter commented 9 years ago
m_kryo.register(someclassB.class);
m_kryo.register(someclassA.class);
m_kryo.register(someclassC.class);

"Encountered unregistered class ID: 121", same error.

Also with v2.20

Original comment by me...@ntlworld.com on 11 Mar 2013 at 1:19

GoogleCodeExporter commented 9 years ago
Did a test where I didn't register anything, just a straight call.
On the PC when reading the file I get.

Error: Unable to find class: SomeValueDataInTheObject
Serialization trace:
values (someclassB)
fields (someclassA)

Seems like its reading data from the wrong place in the file.
I created the file on the Device then copied it over to the PC via USB.

I'm guessing that its to-do with byte formatting ?
If so then I guess the way around it would be to convert it on the device to a 
more acceptable format before it gets passed over.

Original comment by me...@ntlworld.com on 11 Mar 2013 at 5:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Seems while its quite happy to save/load List<Obj> on the same device/pc. When 
you move the file to either side it fails, it seems to loose its way while 
reading the file even if you register all the required class's.

For example I created a file on the PC, copied it over to the device. The 
Strings in the List were prefixed with a square unprintable byte. The other way 
about resulted in the error I mentioned before, "Error: Unable to find class: 
SomeValueDataInTheObject" where some of the data was mistaken for a class.

I had List problems to begin with due to Array.asList being immutable so I 
stopped using it. Then things seems to save/load ok, it wasn't until I tried to 
read the file on the PC that I came across the errors I first encountered.

I have stripped it back to basics using just a primitive array String[] and 
Object[] and now it all seems to be working as expected.

Original comment by me...@ntlworld.com on 12 Mar 2013 at 2:25

GoogleCodeExporter commented 9 years ago
Hi,

Reading your bug report, I assume that reading/writing on the same platform 
works properly. Only if you move the serialized file to a different platform it 
starts misbehaving. Is it correct?

If so, I would suspect that this problem could be related to byte ordering, 
which could be different on those devices. 

BTW, have you tried to use v2.21 or current trunk? Is it any better?
-Leo

Original comment by romixlev on 23 Jul 2013 at 9:06

GoogleCodeExporter commented 9 years ago
Yes, save the object with a List in on Android. Fails to open in the Windows 
Java app but opens fine in Android. 

Yes, I too think its probably got something to-do with byte ordering.

As I said thou I've worked around it by stripping back to basic primitives.

I was using 2.21 as mentioned in the first part.

Original comment by me...@ntlworld.com on 23 Jul 2013 at 12:48

GoogleCodeExporter commented 9 years ago
OK. I'm glad you found a workaround.

It would be still nice, if you could provide a test-case. Binary compatibility 
between different platforms is important for Kryo. Your test-case could help us 
to fix the issue, if it still exists. We could even include a (modified) 
version of your test-case into the set of Kryo's unit tests, so that this 
problem never occurs again.

Would it be possible for you to provide a test-case?

Thanks,
  Leo

Original comment by romixlev on 23 Jul 2013 at 1:35

GoogleCodeExporter commented 9 years ago
There were some recent changes in the trunk based on a similar bug report. It 
could be that your problem is solved now. 

The issue fixed was related to the fact that different versions of JDK handle 
arrays used as generic type parameters differently (e.g. Map<String, int[]> 
mymap). It hopefully should work now.

Let us know if it is fixed or not.

Btw, the kryo-2.22-SNAPSHOT is available in the sonatype snapshots repo: 
https://oss.sonatype.org/content/repositories/snapshots/ 
(https://oss.sonatype.org/content/repositories/snapshots/com/esotericsoftware/kr
yo/kryo/) 

Original comment by romixlev on 22 Aug 2013 at 7:56

GoogleCodeExporter commented 9 years ago
Did this issue ever get fixed? I am beginning to use kryo for serialization 
between a linux and a windows system and want to make sure I don't run into 
this issue. Also, is the issue just with arrays used as generic type parameters?

Original comment by zsol...@gmail.com on 15 Oct 2013 at 10:47

GoogleCodeExporter commented 9 years ago
Do you still have problems using the latest Kryo release, i.e. 2.22? If it 
still fails, can you provide a reproducible test-case?

Original comment by romixlev on 15 Oct 2013 at 10:49