sockeqwe / sqlbrite-dao

DAO for SQLBrite
http://hannesdorfmann.com/android/sqlbrite-dao
Apache License 2.0
182 stars 22 forks source link

Crash in Dao constructor #23

Closed davidbilik closed 8 years ago

davidbilik commented 8 years ago

Hi, I am using your library in one of our production apps and we have discovered one weird bug in Xperia phones with android 4.0.

The crash looks like this

java.lang.RuntimeException: Unable to create application cz.ackee.androidskeleton.App: java.lang.IllegalArgumentException: DatabaseErrorHandler param value can't be null. at android.app.ActivityThread.handleBindApplication(ActivityThread.java:3957) at android.app.ActivityThread.access$1300(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1185) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.IllegalArgumentException: DatabaseErrorHandler param value can't be null. at android.database.sqlite.SQLiteOpenHelper.<init>(SQLiteOpenHelper.java:95) at com.hannesdorfmann.sqlbrite.dao.DaoManager$OpenHelper.<init>(SourceFile:102) at com.hannesdorfmann.sqlbrite.dao.DaoManager.<init>(SourceFile:39) at com.hannesdorfmann.sqlbrite.dao.DaoManager.<init>(SourceFile:33)

I`ve found that problem is that in one of your DaoManager constructor you are sending DatabaseHandler as null, I fixed this by passing instance of DefaultDatabaseErrorHandler() to the more expressive constructor. I think that its worth to fix this. Thanks!

sockeqwe commented 8 years ago

Hm, I'm not entirely sure what actually the problem is. I have a custom SQLiteOpenHelper called OpenHelper. Yes I pass null as default error handler in DaoManager costructor

Passing null as error handler means using the default error handler according to the [android documentation](https://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#SQLiteOpenHelper%28android.content.Context, java.lang.String, android.database.sqlite.SQLiteDatabase.CursorFactory, int, android.database.DatabaseErrorHandler%29):

the DatabaseErrorHandler to be used when sqlite reports database corruption, or null to use the default error handler.

If you want to have a look source code of android SQLiteDatabase implementation you will see

mErrorHandler = errorHandler != null ? errorHandler : new DefaultDatabaseErrorHandler();

So not sure where your issue comes from, but it seems to be a sony ericsson ROM problem

davidbilik commented 8 years ago

Yes, I know that its problem just with Xperias (or maybe android version), but we had 14 of this crashes in week, so it was critical for us to fix this somehow. If you look at this file https://android.googlesource.com/platform/frameworks/base/+/1c423b8/core/java/android/database/sqlite/SQLiteOpenHelper.java on line 93, you can see that earlier this crash was happening if DatabaseHandler was null.