From 17d266469a185c44a705732310b8296393bc1668 Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Fri, 7 Jun 2013 08:48:23 -0700 Subject: Fix a NPE We may not get a cursor back from query(), and if that happens, we shouldn't try to use the null cursor. Bug: 9287151 Change-Id: Ie91d8003f51ea160e5b709a5cd6bcabefc3c687a --- .../ex/chips/RecipientAlternatesAdapter.java | 60 ++++++++++++---------- 1 file changed, 33 insertions(+), 27 deletions(-) (limited to 'chips') diff --git a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java index 0693df2..ef34379 100644 --- a/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java +++ b/chips/src/com/android/ex/chips/RecipientAlternatesAdapter.java @@ -140,8 +140,12 @@ public class RecipientAlternatesAdapter extends CursorAdapter { try { directoryCursor = context.getContentResolver().query(DirectoryListQuery.URI, DirectoryListQuery.PROJECTION, null, null, null); - paramsList = BaseRecipientAdapter.setupOtherDirectories(context, directoryCursor, - account); + if (directoryCursor == null) { + paramsList = null; + } else { + paramsList = BaseRecipientAdapter.setupOtherDirectories(context, + directoryCursor, account); + } } finally { if (directoryCursor != null) { directoryCursor.close(); @@ -157,35 +161,37 @@ public class RecipientAlternatesAdapter extends CursorAdapter { matchesNotFound.addAll(unresolvedAddresses); - Cursor directoryContactsCursor = null; - for (String unresolvedAddress : unresolvedAddresses) { - for (int i = 0; i < paramsList.size(); i++) { - try { - directoryContactsCursor = doQuery(unresolvedAddress, 1, - paramsList.get(i).directoryId, account, - context.getContentResolver(), query); - } finally { - if (directoryContactsCursor != null - && directoryContactsCursor.getCount() == 0) { - directoryContactsCursor.close(); - directoryContactsCursor = null; - } else { - break; + if (paramsList != null) { + Cursor directoryContactsCursor = null; + for (String unresolvedAddress : unresolvedAddresses) { + for (int i = 0; i < paramsList.size(); i++) { + try { + directoryContactsCursor = doQuery(unresolvedAddress, 1, + paramsList.get(i).directoryId, account, + context.getContentResolver(), query); + } finally { + if (directoryContactsCursor != null + && directoryContactsCursor.getCount() == 0) { + directoryContactsCursor.close(); + directoryContactsCursor = null; + } else { + break; + } } } - } - if (directoryContactsCursor != null) { - try { - final Map entries = - processContactEntries(directoryContactsCursor); + if (directoryContactsCursor != null) { + try { + final Map entries = + processContactEntries(directoryContactsCursor); - for (final String address : entries.keySet()) { - matchesNotFound.remove(address); - } + for (final String address : entries.keySet()) { + matchesNotFound.remove(address); + } - callback.matchesFound(entries); - } finally { - directoryContactsCursor.close(); + callback.matchesFound(entries); + } finally { + directoryContactsCursor.close(); + } } } } -- cgit v1.2.3 From c438c7b3b8a621c3aeccfeaa56f66935fdb1b177 Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Wed, 19 Jun 2013 11:52:08 -0700 Subject: Prepare to remove a null check I am fairly convinced that the fix for 9408464 will also fix the underlying problem of this adapter being null. If this log method is ever called, then I'll know it didn't work, but I believe this will never be called. Bug: 9497893 Change-Id: I08518ceecee6985462d0165fb16b1dea95181b07 --- chips/src/com/android/ex/chips/RecipientEditTextView.java | 1 + 1 file changed, 1 insertion(+) (limited to 'chips') diff --git a/chips/src/com/android/ex/chips/RecipientEditTextView.java b/chips/src/com/android/ex/chips/RecipientEditTextView.java index d2e5806..aaf4a05 100644 --- a/chips/src/com/android/ex/chips/RecipientEditTextView.java +++ b/chips/src/com/android/ex/chips/RecipientEditTextView.java @@ -2494,6 +2494,7 @@ public class RecipientEditTextView extends MultiAutoCompleteTextView implements } final BaseRecipientAdapter adapter = (BaseRecipientAdapter) getAdapter(); if (adapter == null) { + Log.wtf(TAG, "My assumption that this was fixed is wrong."); return null; } RecipientAlternatesAdapter.getMatchingRecipients(getContext(), addresses, -- cgit v1.2.3