Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException #29

Open
tieubao opened this issue Nov 8, 2014 · 8 comments

Comments

@tieubao
Copy link

tieubao commented Nov 8, 2014

11-08 22:37:05.412 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ com.esotericsoftware.kryo.KryoException: java.lang.IndexOutOfBoundsException: Invalid index 104, size is 11 11-08 22:37:05.412 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ Serialization trace: 11-08 22:37:05.412 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ auditItems (com.cloudjay.cjay.model.Session) 11-08 22:37:05.412 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:125) 11-08 22:37:05.412 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.serializers.FieldSerializer.read(FieldSerializer.java:528) 11-08 22:37:05.422 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:657) 11-08 22:37:05.422 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.snappydb.internal.DBImpl.getObject(DBImpl.java:276) 11-08 22:37:05.422 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.cloudjay.cjay.DataCenter.uploadImportSession(DataCenter.java:1110) 11-08 22:37:05.432 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.cloudjay.cjay.task.job.UploadSessionJob.onRun(UploadSessionJob.java:141) 11-08 22:37:05.432 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.path.android.jobqueue.BaseJob.safeRun(BaseJob.java:109) 11-08 22:37:05.432 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.path.android.jobqueue.JobHolder.safeRun(JobHolder.java:60) 11-08 22:37:05.432 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.path.android.jobqueue.executor.JobConsumerExecutor$JobConsumer.run(JobConsumerExecutor.java:209) 11-08 22:37:05.442 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at java.lang.Thread.run(Thread.java:856) 11-08 22:37:05.472 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ Caused by: java.lang.IndexOutOfBoundsException: Invalid index 104, size is 11 11-08 22:37:05.472 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251) 11-08 22:37:05.482 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at java.util.ArrayList.get(ArrayList.java:304) 11-08 22:37:05.482 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.util.MapReferenceResolver.getReadObject(MapReferenceResolver.java:42) 11-08 22:37:05.482 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.Kryo.readReferenceOrNull(Kryo.java:805) 11-08 22:37:05.492 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.Kryo.readObject(Kryo.java:677) 11-08 22:37:05.492 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ at com.esotericsoftware.kryo.serializers.ObjectField.read(ObjectField.java:106) 11-08 22:37:05.492 22269-22925/com.cloudjay.cjay.dev W/System.err﹕ ... 9 more

Sorry for pasting a lot of text but I just want to provide you full stack trace.

I face this problem when I try to call getObject() from multi-thread. Then it throw this Exception and say that:

 com.snappydb.SnappydbException: Maybe you tried to retrieve an array using this method ? please use getObjectArray instead java.lang.IndexOutOfBoundsException: Invalid index 104, size is 31
    Serialization trace:
    auditItems (com.cloudjay.cjay.model.Session)
            at com.snappydb.internal.DBImpl.getObject(DBImpl.java:280)
            at com.cloudjay.cjay.DataCenter.uploadImportSession(DataCenter.java:1110)```
@thedamfr
Copy link

Did you solved this problem ?

@nhachicha
Copy link
Owner

Hi @tieubao
Can you please provide some code to reproduce this?
I'll try to take a look.
Cheers,

@tieubao
Copy link
Author

tieubao commented Nov 27, 2014

hi @nhachicha , my code is tight coupling so I can't provide it to you. But we apply the architecture described in this article which use a mutual class to query data from Snappy DB (we call it DataCenter) then use EventBus to post back the query results.

And this problem happens when UI layer (fragments & activities) and other background threads (upload via network, get notification from server ... then save results to snappy) query at the same time.

    public static DB getDB(Context context) throws SnappydbException {
        if (snappyDB == null || snappyDB.isOpen() == false) {
            snappyDB = DBFactory.open(context, CJayConstant.DB_NAME);
        }
        return snappyDB;
    }
// Multiple functions have called this line of code at the same time.
// I think it cause the problem.

...
Session session = db.getObject(key, Session.class);
...

Note: I only close the database after the app is terminated. It opens all the time.

@rfermontero
Copy link

Did you solve this?I have the same problem.

@tieubao
Copy link
Author

tieubao commented Jan 23, 2015

@colymore I get Kryo instance from SnappyDB, then I use it to register all models. This may make things work.

@rfermontero
Copy link

Can You show me a little example of take kyro instance from snapy?thank u.

@tieubao
Copy link
Author

tieubao commented Jan 25, 2015


public static DB getDB(Context context) throws SnappydbException {
        if (snappyDB == null || snappyDB.isOpen() == false) {
            snappyDB = DBFactory.open(context, DB_NAME);
        }
        return snappyDB;
}

...


Kryo kryo = getDB(getApplicationContext()).getKryoInstance();
kryo.register(Session.class);
kryo.register(AuditItem.class);

@rfermontero
Copy link

Thank u so much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants