pilgr / Paper

Paper is a fast NoSQL-like storage for Java/Kotlin objects on Android with automatic schema migration support.
Apache License 2.0
2.34k stars 234 forks source link

PaperDbException while reading #172

Closed Joseph82 closed 4 years ago

Joseph82 commented 4 years ago

I am using version 2.6, and I saw that one device (with Android 10) was keep getting this error while reading an object from the db:

Caused by: io.paperdb.PaperDbException: 
  at io.paperdb.DbStoragePlainFile.readTableFile (DbStoragePlainFile.java:298)
  at io.paperdb.DbStoragePlainFile.select (DbStoragePlainFile.java:158)
  at io.paperdb.Book.read (Book.java:73)
  at io.paperdb.Book.read (Book.java:58)
  .
  . 
  .
  at .Caused
  at com.esotericsoftware.kryo.io.Input.require (Input.java:199)
  at com.esotericsoftware.kryo.io.Input.readVarInt (Input.java:373)
  at com.esotericsoftware.kryo.util.DefaultClassResolver.readClass (DefaultClassResolver.java:127)
  at com.esotericsoftware.kryo.Kryo.readClass (Kryo.java:693)
  at com.esotericsoftware.kryo.serializers.ObjectField.read (ObjectField.java:118)
  at com.esotericsoftware.kryo.serializers.FieldSerializer.read (FieldSerializer.java:543)
  at com.esotericsoftware.kryo.Kryo.readObject (Kryo.java:712)
  at io.paperdb.DbStoragePlainFile.readContent (DbStoragePlainFile.java:307)
  at io.paperdb.DbStoragePlainFile.readTableFile (DbStoragePlainFile.java:291)

I am quite sure there is no problem in the model. The db was created just once and the model never changed.

Phone specs: Samsung Galaxy S10+ (beyond2q), 7680MB RAM, Android 10

pilgr commented 4 years ago

@Joseph82 Do you have an inner root cause, the one following the line at .Caused?

Joseph82 commented 4 years ago

@pilgr unfortunately I don't. It is a simple reading of an object with this structure:

data class MyClass(val data: String)

So far it only happened with 1 user.

pilgr commented 4 years ago

I could assume that user changed some permissions which now prevents Paper from reading data or made some manual changes to the *.pt file. It's hard to say for sure.

Unfortunately without the additional information, it's not reasonable to keep the issue open so I'm going to close it for now.

Please add more info as soon as you know.

Joseph82 commented 4 years ago

It seems like the cause was a Buffer underflow while reading a value from Kryo. I see there is already an open issue for that, so I will not report it.

Joseph82 commented 4 years ago

@pilgr I am back with some extra info :)

  1. All users (currently 4) have Android 10
  2. We are not sure that the data was written before, but we are sure the key is there Paper.book(DbConstants.DB_NAME).allKeys.contains(DbConstants.DEVICE_ID_KEY) indeed returns true.
  3. The read operation is mistakenly happening in the UI thread.

Considering the first point, I think the problem could be related with the scoped storage introduced in Android 10. About using the UI thread, we will fix that for sure, but I am not sure it can be the cause of the problem.

Is Paper using external storage? Can you maybe share more info about how Paper deal with File? Thank you.

pilgr commented 4 years ago

Sure, with Paper you can store data anywhere. For that, Book instance can be created at the custom location. Please find more here https://github.com/pilgr/Paper#set-storage-location-for-book-instances

By default, the book is created in the internal app's storage which should be freely accessible by the app itself.

Joseph82 commented 4 years ago

Thank you, @pilgr yes, I checked the source code. Do you think that reading from UI-thread can be the cause of the problem on some devices?