Skip to content

Commit fd61e70

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "Only populate stack when StrictMode will use it." into ics-mr1
2 parents b8c76af + 7978a41 commit fd61e70

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

core/java/android/database/sqlite/SQLiteCompiledSql.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
/** the following are for debugging purposes */
5151
private String mSqlStmt = null;
52-
private Throwable mStackTrace = null;
52+
private final Throwable mStackTrace;
5353

5454
/** when in cache and is in use, this member is set */
5555
private boolean mInUse = false;
@@ -59,7 +59,11 @@
5959
db.verifyLockOwner();
6060
mDatabase = db;
6161
mSqlStmt = sql;
62-
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
62+
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
63+
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
64+
} else {
65+
mStackTrace = null;
66+
}
6367
nHandle = db.mNativeHandle;
6468
native_compile(sql);
6569
}
@@ -112,7 +116,7 @@ protected void finalize() throws Throwable {
112116
// but if the database itself is not closed and is GC'ed, then
113117
// all sub-objects attached to the database could end up getting GC'ed too.
114118
// in that case, don't print any warning.
115-
if (mInUse && StrictMode.vmSqliteObjectLeaksEnabled()) {
119+
if (mInUse && mStackTrace != null) {
116120
int len = mSqlStmt.length();
117121
StrictMode.onSqliteObjectLeaked(
118122
"Releasing statement in a finalizer. Please ensure " +

core/java/android/database/sqlite/SQLiteCursor.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery que
9595
if (query.mDatabase == null) {
9696
throw new IllegalArgumentException("query.mDatabase cannot be null");
9797
}
98-
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
98+
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
99+
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
100+
} else {
101+
mStackTrace = null;
102+
}
99103
mDriver = driver;
100104
mEditTable = editTable;
101105
mColumnNameMap = null;
@@ -319,7 +323,7 @@ protected void finalize() {
319323
try {
320324
// if the cursor hasn't been closed yet, close it first
321325
if (mWindow != null) {
322-
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
326+
if (mStackTrace != null) {
323327
int len = mQuery.mSql.length();
324328
StrictMode.onSqliteObjectLeaked(
325329
"Finalizing a Cursor that has not been deactivated or closed. " +

0 commit comments

Comments
 (0)