objectbox-java
objectbox-java copied to clipboard
io.objectbox.exception.DbException Not a database file (-30793)
Describe the bug io.objectbox.exception.DbException Not a database file (-30793)
Basic info (please complete the following information):
- ObjectBox version : [2.8.1]
- Reproducibility: [occasionally without visible pattern]
- Device: [series]
- OS: [series]
Expected behavior A clear and concise description of what you expected to happen.
Code
boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()
Logs, stack traces
io.objectbox.exception.DbException: Not a database file (-30793)
--
java.lang.RuntimeException:Unable to create application com.qq.ac.android.ComicApplication: io.objectbox.exception.DbException: Not a database file (-30793) (error code -30793)
android.app.ActivityThread.handleBindApplication(ActivityThread.java:5770)
......
Caused by:
io.objectbox.exception.DbException:Not a database file (-30793)
io.objectbox.BoxStore.nativeCreateWithFlatOptions(Native Method)
io.objectbox.BoxStore.<init>(SourceFile:17)
f.b.d.b(SourceFile:5)
Additional context Initialization of the database is in the main thread, the main process. It was initialized only once.
Does your code supply the database file? Does it somehow (delete and) create the database file? Note that on Android ObjectBox stores the database file in the app's files folder.
Does your code supply the database file? Does it somehow (delete and) create the database file? Note that on Android ObjectBox stores the database file in the app's files folder.
I used ObjectBox in my app witch has ten millions of users, thousands of users crashed, but count millions of crashes, this means the users crashed always keep crashing. i just init ObjectBox in Application’ onCreate().
I saw this crash on a crash analysis platform like Fabric. It is difficult to determine the user's actual environment.
What happens if the database file is corrupted? Is it going to crash?
Well, as a quick fix, you could catch that exception and delete the offending data file and start over with a clean slate.
Alternatively, we could think about how a user may provide the data file to you/us to investigate this further.
In order to repeat this crash, I edit the data.mdb file on my device, it crashed. But the crash log is different.
io.objectbox.exception.DbException: Could not open database environment; please check options and file system (13) (error code 13)
I got this log.
To fix the crash, first i need to repeat it. Do you know how to repeat the crash on my device?
What @greenrobot meant was that the database is likely corrupted. Try to write code that catches the exception, then deletes the broken file. Then try to create a new BoxStore. E.g. like:
try {
boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()
} catch (e: DbException) {
BoxStore.deleteAllFiles(context.applicationContext)
// Try to create a new empty store.
boxStore = MyObjectBox.builder().androidContext(context.applicationContext).build()
}
If possible, you might add an error dialog and ask users to send the corrupted database file (then send it to us for analysis).
If possible, you might add an error dialog and ask users to send the corrupted database file (then send it to us for analysis).
this is a good idea. So, you don't know how the file gets corrupted when you throw this exception?
As I said before, I placed one wrong file in the corresponding folder and got another crash log.
So, you don't know how the file gets corrupted when you throw this exception?
There are some consistency checks in place when opening a data file. If it finds data in the file that is not plausible it will trigger an error. So, no we do not know how this happened. You are the first one to report this. Other apps with millions of users do not have that issue.
I placed one wrong file in the corresponding folder and got another crash log.
It's unlikely that you hit exactly the same bytes that caused the -30793 error code.
Got it. I will try to get the corrupted database file, then send it to you. It will take some time.
Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.
@hzhyan If you have none already, we have published example code on how to safely get a copy of the database file and offer users to share it via email. Note this uses a new API BoxStore.isDatabaseOpen introduced in version 2.9.0.
https://github.com/objectbox/objectbox-examples/commit/d8658ec8867541db4b5516534abbd2c350eec339
data.mdb.gz About this question, I finally got the error database file. @greenrobot-team @greenrobot