SQLiteException: unable to close due to unfinalized statements or unfinished backups

For SafeRoom, I have a report of a crash from an encrypt() utility method:

Caused by net.sqlcipher.database.SQLiteException: unable to close due to unfinalized statements or unfinished backups: sqlite3_close() failed
       at net.sqlcipher.database.SQLiteDatabase.dbclose(SQLiteDatabase.java)
       at net.sqlcipher.database.SQLiteDatabase.onAllReferencesReleased + 513(SQLiteDatabase.java:513)
       at net.sqlcipher.database.SQLiteDatabase.close + 1401(SQLiteDatabase.java:1401)
       at com.commonsware.cwac.saferoom.SQLCipherUtils.encrypt + 215(SQLCipherUtils.java:215)
       at com.commonsware.cwac.saferoom.SQLCipherUtils.encrypt + 152(SQLCipherUtils.java:152)

This encrypt() method encrypts an unencrypted SQLite database using sqlcipher_export. It has no background threads.

Does that “unable to close due to unfinalized statements or unfinished backups” message ring any bells?

Thanks!

Hi @commonsguy

Are you able to reproduce it? I wonder if you call close() on your SQLiteStatement if the behavior would change?

Are you able to reproduce it?

Nope. Neither can the person who reported the problem.

I wonder if you call close() on your SQLiteStatement if the behavior would change?

I can certainly add that — thanks for the suggestion!

Certainly, keep us posted on what you find out!

Hello,

I am continuously getting this error. even though I don’t know how to recreate it at will. any help will be appreciated. following is the log. (where NuTransactionDB extends net.sqlcipher.database.SQLiteOpenHelper;)

2020-01-06 18:21:15.854 17155-17155/com.msikkay.test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.msikkay.test, PID: 17155
net.sqlcipher.database.SQLiteException: unable to close due to unfinalized statements or unfinished backups: sqlite3_close() failed
at net.sqlcipher.database.SQLiteDatabase.dbclose(Native Method)
at net.sqlcipher.database.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:470)
at net.sqlcipher.database.SQLiteDatabase.close(SQLiteDatabase.java:1255)
at com.msikkay.payment.databases.NuTransactionDB.GetSumType(NuTransactionDB.java:610)

The issue is not occurring any more after a new instance of “SQLiteOpenHelper” was invoked.