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

Commit bae68675 authored by calderwoodra's avatar calderwoodra Committed by Eric Erfanian
Browse files

Fixed ArrayIndexOutOfBoundsException in Contacts Fragment.

If a user caused their activity to undergo several state changes rapidly, they
could get the contacts fragment into a state where it wouldn't have any
elements but still call onScrollChange. This would result in calls to
getFirstCompletelyVisibleItemPosition returning NO_POSITION (-1) and throw an
AIOOBE when attempting to get a row's header value.

Bug: 63594129
Test: manual.
PiperOrigin-RevId: 161610423
Change-Id: I0c53587a6499c42abe5e51b6ac2b4108c0971545
parent b3d73844
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -170,6 +170,10 @@ public class ContactsFragment extends Fragment
    fastScroller.updateContainerAndScrollBarPosition(recyclerView);
    int firstVisibleItem = manager.findFirstVisibleItemPosition();
    int firstCompletelyVisible = manager.findFirstCompletelyVisibleItemPosition();
    if (firstCompletelyVisible == RecyclerView.NO_POSITION) {
      // No items are visible, so there are no headers to update.
      return;
    }
    String anchoredHeaderString = adapter.getHeaderString(firstCompletelyVisible);

    // If the user swipes to the top of the list very quickly, there is some strange behavior