From 14b60e747cdf16b79bb755b42dd766348c4f1880 Mon Sep 17 00:00:00 2001 From: Vasu Nori Date: Mon, 1 Mar 2010 14:47:47 -0800 Subject: [PATCH] add warning in finalizer. deprecate protected members. finalizer shoudl not be called ever. add a warning to say that. adeprecate a few members in SQLiteProgram.java. they should not have had protected access level. shoudl be package. --- api/current.xml | 6 +++--- .../database/sqlite/SQLiteCompiledSql.java | 19 +++++++++++++++++-- .../database/sqlite/SQLiteProgram.java | 9 ++++++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/api/current.xml b/api/current.xml index d74127ad2d062..28a71687e3ad6 100644 --- a/api/current.xml +++ b/api/current.xml @@ -55017,7 +55017,7 @@ volatile="false" static="false" final="false" - deprecated="not deprecated" + deprecated="deprecated" visibility="protected" > @@ -55027,7 +55027,7 @@ volatile="false" static="false" final="false" - deprecated="not deprecated" + deprecated="deprecated" visibility="protected" > @@ -55037,7 +55037,7 @@ volatile="false" static="false" final="false" - deprecated="not deprecated" + deprecated="deprecated" visibility="protected" > diff --git a/core/java/android/database/sqlite/SQLiteCompiledSql.java b/core/java/android/database/sqlite/SQLiteCompiledSql.java index a7a1d9ae6d25d..486ad20dcb7f4 100644 --- a/core/java/android/database/sqlite/SQLiteCompiledSql.java +++ b/core/java/android/database/sqlite/SQLiteCompiledSql.java @@ -28,6 +28,8 @@ import android.util.Log; */ /* package */ class SQLiteCompiledSql { + private static final String TAG = "SQLiteCompiledSql"; + /** The database this program is compiled against. */ /* package */ SQLiteDatabase mDatabase; @@ -44,11 +46,17 @@ import android.util.Log; */ /* package */ int nStatement = 0; + /** the following are for debugging purposes */ + private String mSqlStmt = null; + private Throwable mStackTrace = null; + /** when in cache and is in use, this member is set */ private boolean mInUse = false; /* package */ SQLiteCompiledSql(SQLiteDatabase db, String sql) { mDatabase = db; + mSqlStmt = sql; + mStackTrace = new Exception().fillInStackTrace(); this.nHandle = db.mNativeHandle; compile(sql, true); } @@ -115,8 +123,15 @@ import android.util.Log; * Make sure that the native resource is cleaned up. */ @Override - protected void finalize() { - releaseSqlStatement(); + protected void finalize() throws Throwable { + try { + if (nStatement == 0) return; + // finalizer should NEVER get called + Log.w(TAG, "finalizer should never be called. sql: " + mSqlStmt, mStackTrace); + releaseSqlStatement(); + } finally { + super.finalize(); + } } /** diff --git a/core/java/android/database/sqlite/SQLiteProgram.java b/core/java/android/database/sqlite/SQLiteProgram.java index 63acab767d718..389e15e6935a4 100644 --- a/core/java/android/database/sqlite/SQLiteProgram.java +++ b/core/java/android/database/sqlite/SQLiteProgram.java @@ -21,7 +21,10 @@ package android.database.sqlite; */ public abstract class SQLiteProgram extends SQLiteClosable { - /** The database this program is compiled against. */ + /** The database this program is compiled against. + * @deprecated do not use this + */ + @Deprecated protected SQLiteDatabase mDatabase; /** The SQL used to create this query */ @@ -30,7 +33,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { /** * Native linkage, do not modify. This comes from the database and should not be modified * in here or in the native code. + * @deprecated do not use this */ + @Deprecated protected int nHandle = 0; /** @@ -41,7 +46,9 @@ public abstract class SQLiteProgram extends SQLiteClosable { /** * SQLiteCompiledSql statement id is populated with the corresponding object from the above * member. This member is used by the native_bind_* methods + * @deprecated do not use this */ + @Deprecated protected int nStatement = 0; /* package */ SQLiteProgram(SQLiteDatabase db, String sql) {