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

Commit 74b5d6ce authored by Jay Shrauner's avatar Jay Shrauner
Browse files

Fix NPE when cursor is null

Fix JoinContactLoader background loader to null-check returned cursor before
wrapping in a JoinContactLoaderResult CursorWrapper. Change
JoinContactListFragment to in turn check for a null JoinContactLoaderResult.

Bug:18373971
Change-Id: Ib973d1609ba4e555a98b2b9b8c07bd7e5e4e3601
parent be360b04
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;
    }
}