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

Commit 699ac753 authored by Jay Shrauner's avatar Jay Shrauner Committed by Android (Google) Code Review
Browse files

Merge "Fix NPE when cursor is null" into lmp-mr1-dev

parents 8f39429b 74b5d6ce
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -81,8 +81,11 @@ public class JoinContactListFragment extends ContactEntryListFragment<JoinContac
                    break;
                }
                case JoinContactListAdapter.PARTITION_ALL_CONTACTS: {
                    Cursor suggestionsCursor = ((JoinContactLoaderResult) data).suggestionCursor;
                    if (data != null) {
                        final Cursor suggestionsCursor =
                                ((JoinContactLoaderResult) data).suggestionCursor;
                        onContactListLoaded(suggestionsCursor, data);
                    }
                    break;
                }
            }
+25 −4
Original line number Diff line number Diff line
@@ -52,12 +52,16 @@ public class JoinContactLoader extends CursorLoader {
        @Override
        public void close() {
            try {
                if (suggestionCursor != null) {
                    suggestionCursor.close();
                }
            } finally {
                if (super.getWrappedCursor() != null) {
                    super.close();
                }
            }
        }
    }

    public JoinContactLoader(Context context) {
        super(context, null, null, null, null, null);
@@ -79,6 +83,23 @@ public class JoinContactLoader extends CursorLoader {
        // 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;
    }
}