Nov11 / kryo

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

2D arrays are incorrectly (de)serialized #39

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the following code:
public static void main(String[] args)
  {
    Kryo kryo = new Kryo();
    kryo.setRegistrationOptional(true);
    ByteBuffer buffer = ByteBuffer.allocate(1024);

    float[][] array = new float[4][];
    array[0] = new float[]{0.0f,1.0f};
    array[1] = null;
    array[2] = new float[]{2.0f,3.0f};
    array[3] = new float[]{3.0f};
    print(array,"Original array:");

    kryo.writeClassAndObject(buffer, array);
    buffer.rewind();
    Object o = kryo.readClassAndObject(buffer);
    float[][] array_ = (float[][])o;
    print(array_,"Deserialized array:");
  }

  static void print(float[][] array, String header)
  {
    System.out.println(header);
    for(int i=0;i<array.length;i++)
    {
      System.out.println(Arrays.toString(array[i]));
    }
    System.out.println();
  }

I get this:
Original array:
[0.0, 1.0]
null
[2.0, 3.0]
[3.0]

Deserialized array:
[0.0, 1.0]
[2.0, 3.0]
[3.0, 0.0]
[0.0, 0.0]

What is the expected output? What do you see instead?
I expect the data to be deserialized into array with the same data.
Deserialized array should be the same as Original array, but it isn't.

What version of the Kryo are you using?
1.04

Please provide any additional information below.
With 1.02 I had an ArrayOutOfBoundsException in not the same, but similar 
situation.

Original issue reported on code.google.com by yuri.gav...@gmail.com on 3 Mar 2011 at 7:18

GoogleCodeExporter commented 9 years ago
Hmm, you're right, 2D+ arrays are pretty broken. Will fix soon.

Original comment by nathan.s...@gmail.com on 4 Mar 2011 at 4:51

GoogleCodeExporter commented 9 years ago
Any plans to fix this problem?  My 2D arrays seem to crash the program, rather 
than just deserialize incorrectly.  The exception is a 
ArrayIndexOutOfBoundsException.

Original comment by ddu...@gmail.com on 28 Mar 2012 at 4:00

GoogleCodeExporter commented 9 years ago
ArraySerializer now handles 2+ dimension arrays that are jagged or null.
r157

Original comment by nathan.s...@gmail.com on 29 Mar 2012 at 6:19