Candyjing1024 / kryo

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

int[].class and DeflaterInputStream fails #114

Closed GoogleCodeExporter closed 8 years ago

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

int[] testArray = new int[100];
Arrays.fill(testArray, 6);
Output output = new Output(new 
DeflaterOutputStream(Gdx.files.external("kryofile.bin").write(false)));             
kryo.writeObject(output, testArray);
output.close();

//.....

FileHandle fh = Gdx.files.external("kryofile.bin");

if(fh.exists())
{
   Input input = new Input(new DeflaterInputStream(fh.read()));

   int[] testArray = kryo.readObject(input, int[].class);
   input.close();   
}   

What is the expected output? What do you see instead?
Expected: An evil array full of sixes ;)
but get this instead.

Exception in thread "Thread-7" java.lang.IndexOutOfBoundsException: Index: 118, 
Size: 0
    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:773)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:624)
    at com.frustaci.miners.Main.InitLevel(Main.java:3586)
    at com.frustaci.miners.Main$StateRestart$1.run(Main.java:789)

What version of the Kryo are you using?

kryo-2.21-all.jar

Please provide any additional information below.

Also, if you remove the DeflaterIOSteam it works fine.

Original issue reported on code.google.com by frust...@gmail.com on 29 May 2013 at 12:56

GoogleCodeExporter commented 8 years ago
Maybe it's time for a new release, it seems some recent commits might have 
fixed this problem :)
I'll try the trunk later

Original comment by frust...@gmail.com on 29 May 2013 at 1:25

GoogleCodeExporter commented 8 years ago
Just built a snapshot from trunk with maven, it seems the problem is still 
there. Same crash stack.

Original comment by frust...@gmail.com on 29 May 2013 at 2:29

GoogleCodeExporter commented 8 years ago
Also tried to use this:

kryo.register(int[].class, new 
DeflateSerializer(kryo.getDefaultSerializer(int[].class)));

Removing the DeflaterIOStream usage from the input/output.

There's no crash stack, but kryo.readObject(input, int[].class); returns a null 
object

So i'm clueless now, how can i save primitive arrays?

Original comment by frust...@gmail.com on 29 May 2013 at 3:20

GoogleCodeExporter commented 8 years ago
Okey finally replaced the DeflaterStream with GZIPStream and now it works. Good 
enough, but the original bug remains and the docs (Compression and encryption) 
on the project home are leading to it.

Original comment by frust...@gmail.com on 29 May 2013 at 3:40

GoogleCodeExporter commented 8 years ago
Don't use DeflaterInputStream. Try this:
Input input = new Input(new InflaterInputStream(fh.read()));

Original comment by nathan.s...@gmail.com on 29 May 2013 at 4:04

GoogleCodeExporter commented 8 years ago
Ow i see now, very misleading stream terminology. :)
Thanks

Original comment by frust...@gmail.com on 29 May 2013 at 4:42