am 1cbbf23d: am fdb001c0: am 699ac753: Merge "Fix NPE when cursor is null" into lmp-mr1-dev
* commit '1cbbf23d5b141d6040fd7d090ed03adf30218806':
Fix NPE when cursor is null
diff --git a/src/com/android/contacts/list/JoinContactListFragment.java b/src/com/android/contacts/list/JoinContactListFragment.java
index f3788a4..3e42fdf 100644
--- a/src/com/android/contacts/list/JoinContactListFragment.java
+++ b/src/com/android/contacts/list/JoinContactListFragment.java
@@ -81,8 +81,11 @@
break;
}
case JoinContactListAdapter.PARTITION_ALL_CONTACTS: {
- Cursor suggestionsCursor = ((JoinContactLoaderResult) data).suggestionCursor;
- onContactListLoaded(suggestionsCursor, data);
+ if (data != null) {
+ final Cursor suggestionsCursor =
+ ((JoinContactLoaderResult) data).suggestionCursor;
+ onContactListLoaded(suggestionsCursor, data);
+ }
break;
}
}
diff --git a/src/com/android/contacts/list/JoinContactLoader.java b/src/com/android/contacts/list/JoinContactLoader.java
index beb5208..075d789 100644
--- a/src/com/android/contacts/list/JoinContactLoader.java
+++ b/src/com/android/contacts/list/JoinContactLoader.java
@@ -52,9 +52,13 @@
@Override
public void close() {
try {
- suggestionCursor.close();
+ if (suggestionCursor != null) {
+ suggestionCursor.close();
+ }
} finally {
- super.close();
+ if (super.getWrappedCursor() != null) {
+ super.close();
+ }
}
}
}
@@ -79,6 +83,23 @@
// to load the entire list
final Cursor suggestionsCursor = getContext().getContentResolver()
.query(mSuggestionUri, mProjection, null, null, null);
- return new JoinContactLoaderResult(super.loadInBackground(), suggestionsCursor);
+ if (suggestionsCursor == null) {
+ return null;
+ }
+ Cursor cursorToClose = suggestionsCursor;
+ try {
+ final Cursor baseCursor = super.loadInBackground();
+ if (baseCursor != null) {
+ final JoinContactLoaderResult result =
+ new JoinContactLoaderResult(baseCursor, suggestionsCursor);
+ cursorToClose = null;
+ return result;
+ }
+ } finally {
+ if (cursorToClose != null) {
+ cursorToClose.close();
+ }
+ }
+ return null;
}
-}
\ No newline at end of file
+}