Skip to content

Database object locked on error #162

@xrubioj

Description

@xrubioj

While debugging our application which uses SQLCipher for Android v3.3.0, I've found the following constructions in net.sqlcipher.database.SQLiteDatabase (they're also present in other methods):

    public SQLiteStatement compileStatement(String sql) throws SQLException {
        this.lock();
        if(!this.isOpen()) {
            throw new IllegalStateException("database not open");
        } else {
            SQLiteStatement var2;
            try {
                var2 = new SQLiteStatement(this, sql);
            } finally {
                this.unlock();
            }
            return var2;
        }
    }

From my understanding, if you call this with database closed the object will be left locked, as this.unlock() is never called. So, I guess that this function should be rewritten like that:

    public SQLiteStatement compileStatement(String sql) throws SQLException {
        this.lock();
        try {
            if(!this.isOpen()) {
                throw new IllegalStateException("database not open");
            } else {
                SQLiteStatement var2;
                var2 = new SQLiteStatement(this, sql);
                return var2;
            }
        } finally {
            this.unlock();
        }
    }

Probably this is a minor issue, because you should not call this method on a closed DB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions