10000 Merge branch 'boxer-bugfix/crash-from-finalize' · dw3/android-database-sqlcipher@803caad · GitHub
[go: up one dir, main page]

Skip to content

Commit 803caad

Browse files
Merge branch 'boxer-bugfix/crash-from-finalize'
2 parents fba7fa5 + c4dbd90 commit 803caad

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

src/net/sqlcipher/database/SQLiteProgram.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ public abstract class SQLiteProgram extends SQLiteClosable {
5858
@Deprecated
5959
protected long nStatement = 0;
6060

61+
/**
62+
* Indicates whether {@link #close()} has been called.
63+
*/
64+
boolean mClosed = false;
65+
6166
/* package */ SQLiteProgram(SQLiteDatabase db, String sql) {
6267
mDatabase = db;
6368
mSql = sql.trim();
@@ -142,7 +147,7 @@ private void releaseCompiledSqlIfNotInCache() {
142147
// it is in compiled-sql cache. reset its CompiledSql#mInUse flag
143148
mCompiledSql.release();
144149
}
145-
}
150+
}
146151
}
147152

148153
/**
@@ -177,6 +182,9 @@ protected void compile(String sql, boolean forceCompilation) {
177182
* @param index The 1-based index to the parameter to bind null to
178183
*/
179184
public void bindNull(int index) {
185+
if (mClosed) {
186+
throw new IllegalStateException("program already closed");
187+
}
180188
if (!mDatabase.isOpen()) {
181189
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
182190
}
@@ -196,6 +204,9 @@ public void bindNull(int index) {
196204
* @param value The value to bind
197205
*/
198206
public void bindLong(int index, long value) {
207+
if (mClosed) {
208+
throw new IllegalStateException("program already closed");
209+
}
199210
if (!mDatabase.isOpen()) {
200211
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
201212
}
@@ -215,6 +226,9 @@ public void bindLong(int index, long value) {
215226
* @param value The value to bind
216227
*/
217228
public void bindDouble(int index, double value) {
229+
if (mClosed) {
230+
throw new IllegalStateException("program already closed");
231+
}
218232
if (!mDatabase.isOpen()) {
219233
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
220234
}
@@ -237,6 +251,9 @@ public void bindString(int index, String value) {
237251
if (value == null) {
238252
throw new IllegalArgumentException("the bind value at index " + index + " is null");
239253
}
254+
if (mClosed) {
255+
throw new IllegalStateException("program already closed");
256+
}
240257
if (!mDatabase.isOpen()) {
241258
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
242259
}
@@ -259,6 +276,9 @@ public void bindBlob(int index, byte[] value) {
259276
if (value == null) {
260277
throw new IllegalArgumentException("the bind value at index " + index + " is null");
261278
}
279+
if (mClosed) {
280+
throw new IllegalStateException("program already closed");
281+
}
262282
if (!mDatabase.isOpen()) {
263283
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
264284
}
@@ -274,6 +294,9 @@ public void bindBlob(int index, byte[] value) {
274294
* Clears all existing bindings. Unset bindings are treated as NULL.
275295
*/
276296
public void clearBindings() {
297+
if (mClosed) {
298+
throw new IllegalStateException("program already closed");
299+
}
277300
if (!mDatabase.isOpen()) {
278301
throw new IllegalStateException("database " + mDatabase.getPath() + " already closed");
279302
}
@@ -289,6 +312,9 @@ public void clearBindings() {
289312
* Release this program's resources, making it invalid.
290313
*/
291314
public void close() {
315+
if (mClosed) {
316+
return;
317+
}
292318
if (!mDatabase.isOpen()) {
293319
return;
294320
}
@@ -298,6 +324,7 @@ public void close() {
298324
} finally {
299325
mDatabase.unlock();
300326
}
327+
mClosed = true;
301328
}
302329

303330
/**

src/net/sqlcipher/database/SQLiteQuery.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,17 @@ public class SQLiteQuery extends SQLiteProgram {
3232

3333
/** The index of the unbound OFFSET parameter */
3434
private int mOffsetIndex;
35-
35+
3636
/** Args to bind on requery */
3737
private String[] mBindArgs;
3838
private Object[] mObjectBindArgs;
3939

40-
private boolean mClosed = false;
41-
4240
/**
4341
* Create a persistent query object.
44-
*
42+
*
4543
* @param db The database that this query object is associated with
46-
* @param query The SQL string for this query.
47-
* @param offsetIndex The 1-based index to the OFFSET parameter,
44+
* @param query The SQL string for this query.
45+
* @param offsetIndex The 1-based index to the OFFSET parameter,
4846
*/
4947
/* package */ SQLiteQuery(SQLiteDatabase db, String query, int offsetIndex, String[] bindArgs) {
5048
super(db, query);
@@ -105,7 +103,7 @@ public class SQLiteQuery extends SQLiteProgram {
105103
* Get the column count for the statement. Only valid on query based
106104
* statements. The database must be locked
107105
* when calling this method.
108-
*
106+
*
109107
* @return The number of column in the statement's result set.
110108
*/
111109
/* package */ int columnCountLocked() {
@@ -120,7 +118,7 @@ public class SQLiteQuery extends SQLiteProgram {
120118
/**
121119
* Retrieves the column name for the given column index. The database must be locked
122120
* when calling this method.
123-
*
121+
*
124122
* @param columnIndex the index of the column to get the name for
125123
* @return The requested column's name
126124
*/
@@ -132,17 +130,11 @@ public class SQLiteQuery extends SQLiteProgram {
132130
releaseReference();
133131
}
134132
}
135-
133+
136134
@Override
137135
public String toString() {
138136
return "SQLiteQuery: " + mSql;
139137
}
140-
141-
@Override
142-
public void close() {
143-
super.close();
144-
mClosed = true;
145-
}
146138

147139
/**
148140
* Called by SQLiteCursor when it is requeried.
@@ -167,7 +159,7 @@ public void close() {
167159
errMsg.append(" ");
168160
IllegalStateException leakProgram = new IllegalStateException(
169161
errMsg.toString(), e);
170-
throw leakProgram;
162+
throw leakProgram;
171163
}
172164
}
173165
}

0 commit comments

Comments
 (0)
0