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

Commit 790728c5 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "Fix NPE when cursor is null"

parents 6d1f12a9 51846255
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;
    }
}