diff options
author | 2014-02-18 16:02:51 +0900 | |
---|---|---|
committer | 2014-02-18 19:58:23 +0900 | |
commit | b8ff8ca9d9d17f61f3f0e019ed0b62fe13d1a33f (patch) | |
tree | 4b211dd65e708eed2706456baccfb0c9ac5f2aee /java/src/com/android/inputmethod/latin/userdictionary | |
parent | db21fad18f70eb4abaf60a8c0ae7f285682acf20 (diff) | |
download | latinime-b8ff8ca9d9d17f61f3f0e019ed0b62fe13d1a33f.tar.gz latinime-b8ff8ca9d9d17f61f3f0e019ed0b62fe13d1a33f.tar.xz latinime-b8ff8ca9d9d17f61f3f0e019ed0b62fe13d1a33f.zip |
Straighten out database cursors behavior.
Some were never closed, other closed twice. This change
makes all Cursor instances behave, having the #close()
call in a finally{} clause, and puts the burden of closing
the cursor squarely on the creator rather than in the
called methods.
There is however one exception that is beyond the scope
of this change: UserDictionarySettings have a Cursor
member, it's never closed, and fixing the problem is not
obvious. This change adds a TODO for now.
It's not very clear if this change actually helps with
bug#12670151, but it may be related and it's a good
think to do anyway.
Bug: 12670151
Change-Id: I87cc44387e7dee3da1488671b93a28d9d73f7dc0
Diffstat (limited to 'java/src/com/android/inputmethod/latin/userdictionary')
-rw-r--r-- | java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java | 17 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java | 2 |
2 files changed, 13 insertions, 6 deletions
diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java index 32c4950da..2f41ce9ce 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionaryList.java @@ -61,12 +61,17 @@ public class UserDictionaryList extends PreferenceFragment { if (null == cursor) { // The user dictionary service is not present or disabled. Return null. return null; - } else if (cursor.moveToFirst()) { - final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE); - do { - final String locale = cursor.getString(columnIndex); - localeSet.add(null != locale ? locale : ""); - } while (cursor.moveToNext()); + } + try { + if (cursor.moveToFirst()) { + final int columnIndex = cursor.getColumnIndex(UserDictionary.Words.LOCALE); + do { + final String locale = cursor.getString(columnIndex); + localeSet.add(null != locale ? locale : ""); + } while (cursor.moveToNext()); + } + } finally { + cursor.close(); } if (!UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) { // For ICS, we need to show "For all languages" in case that the keyboard locale diff --git a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java index 7571e87c5..220efb5d3 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java @@ -140,6 +140,8 @@ public class UserDictionarySettings extends ListFragment { } mLocale = locale; + // WARNING: The following cursor is never closed! TODO: don't put that in a member, and + // make sure all cursors are correctly closed. mCursor = createCursor(locale); TextView emptyView = (TextView) getView().findViewById(android.R.id.empty); emptyView.setText(R.string.user_dict_settings_empty_text); |