Avi-Levi / kryo

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

IndexOutOfBoundsException: Index: 54, Size: 0 MapReferenceResolver.getReadObject #150

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.when i want to serialize a object which contains a list in it, when the size 
of list exceeds some value the following exception will happen:
java.lang.IndexOutOfBoundsException: Index: 54, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:547)
    at java.util.ArrayList.get(ArrayList.java:322)
    at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42)
    at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:830)
    at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:680)
    at com.baidu.rigle.log.search.service.IndexWriterServiceTest.testDataPackageKryoCodec2(IndexWriterServiceTest.java:145)

the following is the java code:
public class DataPackage2 implements Serializable {

    private static final long serialVersionUID = 8645844340384510962L;

    private String shardingKey;

    private List<String> datas;

    public String getShardingKey() {
        return shardingKey;
    }

    public void setShardingKey(String shardingKey) {
        this.shardingKey = shardingKey;
    }

    /**
     * @return the datas
     */
    public List<String> getDatas() {
        return datas;
    }

    /**
     * @param datas the datas to set
     */
    public void setDatas(List<String> datas) {
        this.datas = datas;
    }
}

@Test
    public void testDataPackageKryoCodec2() throws CoordinatorCodecException {
        DataPackage2 dataPackage2 = new DataPackage2();
        dataPackage2.setShardingKey("2014-12-30/44/3");

        List<String> datas = new ArrayList<String>();
        int size=1000;
        for (int j = 0; j < size; j++) {
            datas.add("" + j + "" + j + "" + j);
        }
        dataPackage2.setDatas(datas);

        Kryo kryo = new Kryo();
        Output output = new Output(new ByteArrayOutputStream());
        kryo.register(DataPackage2.class);
        kryo.writeObject(output, dataPackage2);

        Input input = new Input(output.toBytes());
        kryo.register(DataPackage2.class);
        try {
            DataPackage2 res = kryo.readObject(input, DataPackage2.class);
            System.out.println(res);
        } catch (Exception e) {
            e.printStackTrace();
            throw new CoordinatorCodecException(e);
        }
    }

when I change the value of attribute size, ex: 200, 400, 1000, when used the 
200 and 400 the exception will not happen, but when used 1000 the exception 
happened, maybe outof memory happened, but i don't think so, because the total 
size of DataPackage2 object is small, and the exception print out means nothing 
aboubt outof memory excepion.

What version of the Kryo are you using?
is it a bug? i tried many version of kryo, like: 2.22, 2.24, 3.0.0, 
3.0.1-SNAPSHOT, but it didn't work

Please provide any additional information below.

Original issue reported on code.google.com by lixiaodong037 on 1 Jan 2015 at 4:39