Program: 1947
Project: 1947
Buggy source:
/** 
 * Handle an arrow scroll going up or down.  Take into account whether items are selectable, whether there are focusable items etc.
 * @param direction Either {@link android.view.View#FOCUS_UP} or {@link android.view.View#FOCUS_DOWN}.
 * @return Whether any scrolling, selection or focus change occured.
 */
private boolean arrowScrollImpl(int direction){
  if (getChildCount() <= 0) {
    return false;
  }
  View selectedView=getSelectedView();
  int selectedPos=mSelectedPosition;
  int nextSelectedPosition=nextSelectedPositionForDirection(selectedPos,direction);
  int amountToScroll=amountToScroll(direction,nextSelectedPosition);
  final ArrowScrollFocusResult focusResult=mItemsCanFocus ? arrowScrollFocused(direction) : null;
  if (focusResult != null) {
    nextSelectedPosition=focusResult.getSelectedPosition();
    amountToScroll=focusResult.getAmountToScroll();
  }
  boolean needToRedraw=focusResult != null;
  if (nextSelectedPosition != INVALID_POSITION) {
    handleNewSelectionChange(selectedView,direction,nextSelectedPosition,focusResult != null);
    setSelectedPositionInt(nextSelectedPosition);
    setNextSelectedPositionInt(nextSelectedPosition);
    selectedView=getSelectedView();
    selectedPos=nextSelectedPosition;
    if (mItemsCanFocus && focusResult == null) {
      final View focused=getFocusedChild();
      if (focused != null) {
        focused.clearFocus();
      }
    }
    needToRedraw=true;
    checkSelectionChanged();
  }
  if (amountToScroll > 0) {
    scrollListItemsBy((direction == View.FOCUS_UP) ? amountToScroll : -amountToScroll);
    needToRedraw=true;
  }
  if (mItemsCanFocus && (focusResult == null) && selectedView != null && selectedView.hasFocus()) {
    final View focused=selectedView.findFocus();
    if (!isViewAncestorOf(focused,this) || distanceToView(focused) > 0) {
      focused.clearFocus();
    }
  }
  if (nextSelectedPosition == INVALID_POSITION && selectedView != null && !isViewAncestorOf(selectedView,this)) {
    selectedView=null;
    hideSelector();
    mResurrectToPosition=INVALID_POSITION;
  }
  if (needToRedraw) {
    if (selectedView != null) {
      positionSelector(selectedPos,selectedView);
      mSelectedTop=selectedView.getTop();
    }
    if (!awakenScrollBars()) {
      invalidate();
    }
    invokeOnItemScrollListener();
    return true;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Handle an arrow scroll going up or down.  Take into account whether items are selectable, whether there are focusable items etc.
 * @param direction Either {@link android.view.View#FOCUS_UP} or {@link android.view.View#FOCUS_DOWN}.
 * @return Whether any scrolling, selection or focus change occured.
 */
private boolean arrowScrollImpl(int direction){
  if (getChildCount() <= 0) {
    return false;
  }
  View selectedView=getSelectedView();
  int selectedPos=mSelectedPosition;
  int nextSelectedPosition=nextSelectedPositionForDirection(selectedView,selectedPos,direction);
  int amountToScroll=amountToScroll(direction,nextSelectedPosition);
  final ArrowScrollFocusResult focusResult=mItemsCanFocus ? arrowScrollFocused(direction) : null;
  if (focusResult != null) {
    nextSelectedPosition=focusResult.getSelectedPosition();
    amountToScroll=focusResult.getAmountToScroll();
  }
  boolean needToRedraw=focusResult != null;
  if (nextSelectedPosition != INVALID_POSITION) {
    handleNewSelectionChange(selectedView,direction,nextSelectedPosition,focusResult != null);
    setSelectedPositionInt(nextSelectedPosition);
    setNextSelectedPositionInt(nextSelectedPosition);
    selectedView=getSelectedView();
    selectedPos=nextSelectedPosition;
    if (mItemsCanFocus && focusResult == null) {
      final View focused=getFocusedChild();
      if (focused != null) {
        focused.clearFocus();
      }
    }
    needToRedraw=true;
    checkSelectionChanged();
  }
  if (amountToScroll > 0) {
    scrollListItemsBy((direction == View.FOCUS_UP) ? amountToScroll : -amountToScroll);
    needToRedraw=true;
  }
  if (mItemsCanFocus && (focusResult == null) && selectedView != null && selectedView.hasFocus()) {
    final View focused=selectedView.findFocus();
    if (!isViewAncestorOf(focused,this) || distanceToView(focused) > 0) {
      focused.clearFocus();
    }
  }
  if (nextSelectedPosition == INVALID_POSITION && selectedView != null && !isViewAncestorOf(selectedView,this)) {
    selectedView=null;
    hideSelector();
    mResurrectToPosition=INVALID_POSITION;
  }
  if (needToRedraw) {
    if (selectedView != null) {
      positionSelector(selectedPos,selectedView);
      mSelectedTop=selectedView.getTop();
    }
    if (!awakenScrollBars()) {
      invalidate();
    }
    invokeOnItemScrollListener();
    return true;
  }
  return false;
}