Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Releasing statement in a finalizer #1496

Closed
WonderCsabo opened this issue Dec 19, 2017 · 3 comments
Closed

Releasing statement in a finalizer #1496

WonderCsabo opened this issue Dec 19, 2017 · 3 comments
Milestone

Comments

@WonderCsabo
Copy link
Contributor

WonderCsabo commented Dec 19, 2017

We are using DBFlow 4.2.1 and SQLCipher 3.5.7.

When we are saving model objects, these warning messages pop up.

Releasing statement in a finalizer. Please ensure that you explicitly call close() on your cursor: UPDATE <redacted>
net.sqlcipher.database.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
    at net.sqlcipher.database.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:62)
    at net.sqlcipher.database.SQLiteProgram.<init>(SQLiteProgram.java:109)
    at net.sqlcipher.database.SQLiteStatement.<init>(SQLiteStatement.java:39)
    at net.sqlcipher.database.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1589)
    at com.raizlabs.android.dbflow.sqlcipher.SQLCipherDatabase.compileStatement(SQLCipherDatabase.java:56)
    at com.raizlabs.android.dbflow.structure.ModelAdapter.getUpdateStatement(ModelAdapter.java:129)
    at com.raizlabs.android.dbflow.sql.saveable.ModelSaver.save(ModelSaver.java:36)
    at com.raizlabs.android.dbflow.structure.ModelAdapter.save(ModelAdapter.java:190)
    <redacted>

We are passing the databaseWrapper to the save() method.

@agrosner
Copy link
Owner

agrosner commented Dec 19, 2017

its because it gets the statements when the parameters are less, thus not closing them. makes sense. for now you can patch this with:



public class ModelSaverFix<TModel> extends ModelSaver<TModel> {

    @Override
    public synchronized boolean save(@NonNull TModel model, @NonNull DatabaseWrapper wrapper) {
        boolean exists = getModelAdapter().exists(model, wrapper);

        if (exists) {
            exists = update(model, wrapper);
        }

        if (!exists) {
            exists = insert(model, wrapper) > INSERT_FAILED;
        }

        if (exists) {
            NotifyDistributor.get().notifyModelChanged(model, getModelAdapter(), BaseModel.Action.SAVE);
        }

        // return successful store into db.
        return exists;
    }
}

then in TableConfig.Builder specify it as the modelAdapterModelSaver() parameter.

@agrosner agrosner added this to the 4.2.3 milestone Dec 19, 2017
@agrosner
Copy link
Owner

in develop, try it out with commit 7d0d039f1a instead of version 4.2.2 until 4.2.3 is released.

@agrosner agrosner mentioned this issue Dec 20, 2017
@WonderCsabo
Copy link
Contributor Author

WonderCsabo commented Dec 20, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants