Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13c42f4e authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Fix potential NPE with null cursor

Detect and handle null cursors returned from CP2 queries.

Bug:12767708
Change-Id: I1571463b80e5b85656fe119c6bc83de36be30c7f
parent 89fac3ba
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -157,6 +157,9 @@ public class SplitAggregateView extends ListView {
        Uri dataUri = Uri.withAppendedPath(mAggregateUri, Data.CONTENT_DIRECTORY);
        Cursor cursor = getContext().getContentResolver().query(dataUri,
                SplitQuery.COLUMNS, null, null, null);
        if (cursor == null) {
            return Collections.emptyList();
        }
        try {
            while (cursor.moveToNext()) {
                long rawContactId = cursor.getLong(SplitQuery.RAW_CONTACT_ID);
+6 −1
Original line number Diff line number Diff line
@@ -300,6 +300,9 @@ public class AggregationSuggestionEngine extends HandlerThread {
    private void loadAggregationSuggestions(Uri uri) {
        ContentResolver contentResolver = mContext.getContentResolver();
        Cursor cursor = contentResolver.query(uri, new String[]{Contacts._ID}, null, null, null);
        if (cursor == null) {
            return;
        }
        try {
            // If a new request is pending, chuck the result of the previous request
            if (getHandler().hasMessages(MESSAGE_NAME_CHANGE)) {
@@ -324,7 +327,9 @@ public class AggregationSuggestionEngine extends HandlerThread {

            Cursor dataCursor = contentResolver.query(Data.CONTENT_URI,
                    DataQuery.COLUMNS, sb.toString(), null, Data.CONTACT_ID);
            if (dataCursor != null) {
                mMainHandler.sendMessage(mMainHandler.obtainMessage(MESSAGE_DATA_CURSOR, dataCursor));
            }
        } finally {
            cursor.close();
        }
+24 −22
Original line number Diff line number Diff line
@@ -263,6 +263,7 @@ public class SuggestedMemberListAdapter extends ArrayAdapter<SuggestedMember> {
                    "=?) AND " + rawContactIdSelectionBuilder.toString(),
                    selectionArgs.toArray(new String[0]), null);

            if (memberDataCursor != null) {
                try {
                    memberDataCursor.moveToPosition(-1);
                    while (memberDataCursor.moveToNext()) {
@@ -289,6 +290,7 @@ public class SuggestedMemberListAdapter extends ArrayAdapter<SuggestedMember> {
                } finally {
                    memberDataCursor.close();
                }
            }
            results.values = suggestionsList;
            return results;
        }