Android-Debug-Database
Android-Debug-Database copied to clipboard
ClientServer Exception with Application database context
Hi, And at first thanks for this great tool. I used it today on test code and it worked great but after a while, I decided to put my DB at the application context level and to put it into a private static volatile variable. While the DB still works well, your debug tool doesn't like it...
The exception raised is the following one :
E/ClientServer: Exception.
net.sqlcipher.database.SQLiteException: file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
at net.sqlcipher.database.SQLiteCompiledSql.native_compile(Native Method)
at net.sqlcipher.database.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
at net.sqlcipher.database.SQLiteCompiledSql.
And the code I used is this one :
@Database(entities = {Review.class}, version = 1, exportSchema = false)
public abstract class ReviewsDatabase extends RoomDatabase {
private static volatile ReviewsDatabase INSTANCE;
public abstract ReviewDao reviewDao();
public static ReviewsDatabase getInstance(Context context) {
if (INSTANCE == null) {
synchronized (ReviewsDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
ReviewsDatabase.class, "myPersonalTest.db")
.allowMainThreadQueries()
.build();
}
}
}
return INSTANCE;
}
}
Thanks for your help,
Loïc
This seems weird. Is this working when you do not put it into a private static volatile variable?
I dig a bit further and the bug is much more weird than I thought... It seems to me that the "private static volatile" isn't involved in the process. But everytime I start with a fresh installation and a database name like "myDB.db", your debug app crashes. After that, starting the app without cleaning it produces an exception like that :
E/ClientServer: Exception. java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.util.HashMap.get(java.lang.Object)' on a null object reference at com.amitshekhar.server.RequestHandler.openDatabase(RequestHandler.java:182) at com.amitshekhar.server.RequestHandler.getTableListResponse(RequestHandler.java:304) at com.amitshekhar.server.RequestHandler.handle(RequestHandler.java:113) at com.amitshekhar.server.ClientServer.run(ClientServer.java:76) at java.lang.Thread.run(Thread.java:764)
Moreover it seems that sometimes my db logs and your web view aren't synchronized anymore. Restarting the app shows me sometimes a db corresponding to my log or to your web view, randomly... Could it be that using "synchronized" keywords or "allowMainThreadQueries()" function generate concurrent access to the database?