Program: 23350
Project: 23350
Buggy source:
@Override protected void layoutChildren(){
  final boolean blockLayoutRequests=mBlockLayoutRequests;
  if (!blockLayoutRequests) {
    mBlockLayoutRequests=true;
  }
 else {
    return;
  }
  try {
    super.layoutChildren();
    invalidate();
    if (mAdapter == null) {
      resetList();
      invokeOnItemScrollListener();
      return;
    }
    int childrenTop=mListPadding.top;
    int childrenBottom=mBottom - mTop - mListPadding.bottom;
    int childCount=getChildCount();
    int index;
    int delta=0;
    View sel;
    View oldSel=null;
    View oldFirst=null;
    View newSel=null;
    View focusLayoutRestoreView=null;
switch (mLayoutMode) {
case LAYOUT_SET_SELECTION:
      index=mNextSelectedPosition - mFirstPosition;
    if (index >= 0 && index < childCount) {
      newSel=getChildAt(index);
    }
  break;
case LAYOUT_FORCE_TOP:
case LAYOUT_FORCE_BOTTOM:
case LAYOUT_SPECIFIC:
case LAYOUT_SYNC:
break;
case LAYOUT_MOVE_SELECTION:
default :
index=mSelectedPosition - mFirstPosition;
if (index >= 0 && index < childCount) {
oldSel=getChildAt(index);
}
oldFirst=getChildAt(0);
if (mNextSelectedPosition >= 0) {
delta=mNextSelectedPosition - mSelectedPosition;
}
newSel=getChildAt(index + delta);
}
boolean dataChanged=mDataChanged;
if (dataChanged) {
handleDataChanged();
}
if (mItemCount == 0) {
resetList();
invokeOnItemScrollListener();
return;
}
 else if (mItemCount != mAdapter.getCount()) {
throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str" + getId() + "String_Node_Str"+ getClass()+ "String_Node_Str"+ mAdapter.getClass()+ "String_Node_Str");
}
setSelectedPositionInt(mNextSelectedPosition);
final int firstPosition=mFirstPosition;
final RecycleBin recycleBin=mRecycler;
View focusLayoutRestoreDirectChild=null;
if (dataChanged) {
for (int i=0; i < childCount; i++) {
recycleBin.addScrapView(getChildAt(i));
if (ViewDebug.TRACE_RECYCLER) {
ViewDebug.trace(getChildAt(i),ViewDebug.RecyclerTraceType.MOVE_TO_SCRAP_HEAP,index,i);
}
}
}
 else {
recycleBin.fillActiveViews(childCount,firstPosition);
}
final View focusedChild=getFocusedChild();
if (focusedChild != null) {
if (!dataChanged || isDirectChildHeaderOrFooter(focusedChild)) {
focusLayoutRestoreDirectChild=focusedChild;
focusLayoutRestoreView=findFocus();
if (focusLayoutRestoreView != null) {
focusLayoutRestoreView.onStartTemporaryDetach();
}
}
requestFocus();
}
detachAllViewsFromParent();
switch (mLayoutMode) {
case LAYOUT_SET_SELECTION:
if (newSel != null) {
sel=fillFromSelection(newSel.getTop(),childrenTop,childrenBottom);
}
 else {
sel=fillFromMiddle(childrenTop,childrenBottom);
}
break;
case LAYOUT_SYNC:
sel=fillSpecific(mSyncPosition,mSpecificTop);
break;
case LAYOUT_FORCE_BOTTOM:
sel=fillUp(mItemCount - 1,childrenBottom);
adjustViewsUpOrDown();
break;
case LAYOUT_FORCE_TOP:
mFirstPosition=0;
sel=fillFromTop(childrenTop);
adjustViewsUpOrDown();
break;
case LAYOUT_SPECIFIC:
sel=fillSpecific(reconcileSelectedPosition(),mSpecificTop);
break;
case LAYOUT_MOVE_SELECTION:
sel=moveSelection(oldSel,newSel,delta,childrenTop,childrenBottom);
break;
default :
if (childCount == 0) {
if (!mStackFromBottom) {
final int position=lookForSelectablePosition(0,true);
setSelectedPositionInt(position);
sel=fillFromTop(childrenTop);
}
 else {
final int position=lookForSelectablePosition(mItemCount - 1,false);
setSelectedPositionInt(position);
sel=fillUp(mItemCount - 1,childrenBottom);
}
}
 else {
if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
sel=fillSpecific(mSelectedPosition,oldSel == null ? childrenTop : oldSel.getTop());
}
 else if (mFirstPosition < mItemCount) {
sel=fillSpecific(mFirstPosition,oldFirst == null ? childrenTop : oldFirst.getTop());
}
 else {
sel=fillSpecific(0,childrenTop);
}
}
break;
}
recycleBin.scrapActiveViews();
if (sel != null) {
if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
final boolean focusWasTaken=(sel == focusLayoutRestoreDirectChild && focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
if (!focusWasTaken) {
final View focused=getFocusedChild();
if (focused != null) {
focused.clearFocus();
}
positionSelector(sel);
}
 else {
sel.setSelected(false);
mSelectorRect.setEmpty();
}
}
 else {
positionSelector(sel);
}
mSelectedTop=sel.getTop();
}
 else {
if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
View child=getChildAt(mMotionPosition - mFirstPosition);
if (child != null) positionSelector(child);
}
 else {
mSelectedTop=0;
mSelectorRect.setEmpty();
}
if (hasFocus() && focusLayoutRestoreView != null) {
focusLayoutRestoreView.requestFocus();
}
}
if (focusLayoutRestoreView != null && focusLayoutRestoreView.getWindowToken() != null) {
focusLayoutRestoreView.onFinishTemporaryDetach();
}
mLayoutMode=LAYOUT_NORMAL;
mDataChanged=false;
mNeedSync=false;
setNextSelectedPositionInt(mSelectedPosition);
updateScrollIndicators();
if (mItemCount > 0) {
checkSelectionChanged();
}
invokeOnItemScrollListener();
}
  finally {
if (!blockLayoutRequests) {
mBlockLayoutRequests=false;
}
}
}

Fixed version (ground truth):
@Override protected void layoutChildren(){
  final boolean blockLayoutRequests=mBlockLayoutRequests;
  if (!blockLayoutRequests) {
    mBlockLayoutRequests=true;
  }
 else {
    return;
  }
  try {
    super.layoutChildren();
    invalidate();
    if (mAdapter == null) {
      resetList();
      invokeOnItemScrollListener();
      return;
    }
    int childrenTop=mListPadding.top;
    int childrenBottom=mBottom - mTop - mListPadding.bottom;
    int childCount=getChildCount();
    int index=0;
    int delta=0;
    View sel;
    View oldSel=null;
    View oldFirst=null;
    View newSel=null;
    View focusLayoutRestoreView=null;
switch (mLayoutMode) {
case LAYOUT_SET_SELECTION:
      index=mNextSelectedPosition - mFirstPosition;
    if (index >= 0 && index < childCount) {
      newSel=getChildAt(index);
    }
  break;
case LAYOUT_FORCE_TOP:
case LAYOUT_FORCE_BOTTOM:
case LAYOUT_SPECIFIC:
case LAYOUT_SYNC:
break;
case LAYOUT_MOVE_SELECTION:
default :
index=mSelectedPosition - mFirstPosition;
if (index >= 0 && index < childCount) {
oldSel=getChildAt(index);
}
oldFirst=getChildAt(0);
if (mNextSelectedPosition >= 0) {
delta=mNextSelectedPosition - mSelectedPosition;
}
newSel=getChildAt(index + delta);
}
boolean dataChanged=mDataChanged;
if (dataChanged) {
handleDataChanged();
}
if (mItemCount == 0) {
resetList();
invokeOnItemScrollListener();
return;
}
 else if (mItemCount != mAdapter.getCount()) {
throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str" + getId() + "String_Node_Str"+ getClass()+ "String_Node_Str"+ mAdapter.getClass()+ "String_Node_Str");
}
setSelectedPositionInt(mNextSelectedPosition);
final int firstPosition=mFirstPosition;
final RecycleBin recycleBin=mRecycler;
View focusLayoutRestoreDirectChild=null;
if (dataChanged) {
for (int i=0; i < childCount; i++) {
recycleBin.addScrapView(getChildAt(i));
if (ViewDebug.TRACE_RECYCLER) {
ViewDebug.trace(getChildAt(i),ViewDebug.RecyclerTraceType.MOVE_TO_SCRAP_HEAP,index,i);
}
}
}
 else {
recycleBin.fillActiveViews(childCount,firstPosition);
}
final View focusedChild=getFocusedChild();
if (focusedChild != null) {
if (!dataChanged || isDirectChildHeaderOrFooter(focusedChild)) {
focusLayoutRestoreDirectChild=focusedChild;
focusLayoutRestoreView=findFocus();
if (focusLayoutRestoreView != null) {
focusLayoutRestoreView.onStartTemporaryDetach();
}
}
requestFocus();
}
detachAllViewsFromParent();
switch (mLayoutMode) {
case LAYOUT_SET_SELECTION:
if (newSel != null) {
sel=fillFromSelection(newSel.getTop(),childrenTop,childrenBottom);
}
 else {
sel=fillFromMiddle(childrenTop,childrenBottom);
}
break;
case LAYOUT_SYNC:
sel=fillSpecific(mSyncPosition,mSpecificTop);
break;
case LAYOUT_FORCE_BOTTOM:
sel=fillUp(mItemCount - 1,childrenBottom);
adjustViewsUpOrDown();
break;
case LAYOUT_FORCE_TOP:
mFirstPosition=0;
sel=fillFromTop(childrenTop);
adjustViewsUpOrDown();
break;
case LAYOUT_SPECIFIC:
sel=fillSpecific(reconcileSelectedPosition(),mSpecificTop);
break;
case LAYOUT_MOVE_SELECTION:
sel=moveSelection(oldSel,newSel,delta,childrenTop,childrenBottom);
break;
default :
if (childCount == 0) {
if (!mStackFromBottom) {
final int position=lookForSelectablePosition(0,true);
setSelectedPositionInt(position);
sel=fillFromTop(childrenTop);
}
 else {
final int position=lookForSelectablePosition(mItemCount - 1,false);
setSelectedPositionInt(position);
sel=fillUp(mItemCount - 1,childrenBottom);
}
}
 else {
if (mSelectedPosition >= 0 && mSelectedPosition < mItemCount) {
sel=fillSpecific(mSelectedPosition,oldSel == null ? childrenTop : oldSel.getTop());
}
 else if (mFirstPosition < mItemCount) {
sel=fillSpecific(mFirstPosition,oldFirst == null ? childrenTop : oldFirst.getTop());
}
 else {
sel=fillSpecific(0,childrenTop);
}
}
break;
}
recycleBin.scrapActiveViews();
if (sel != null) {
if (mItemsCanFocus && hasFocus() && !sel.hasFocus()) {
final boolean focusWasTaken=(sel == focusLayoutRestoreDirectChild && focusLayoutRestoreView.requestFocus()) || sel.requestFocus();
if (!focusWasTaken) {
final View focused=getFocusedChild();
if (focused != null) {
focused.clearFocus();
}
positionSelector(sel);
}
 else {
sel.setSelected(false);
mSelectorRect.setEmpty();
}
}
 else {
positionSelector(sel);
}
mSelectedTop=sel.getTop();
}
 else {
if (mTouchMode > TOUCH_MODE_DOWN && mTouchMode < TOUCH_MODE_SCROLL) {
View child=getChildAt(mMotionPosition - mFirstPosition);
if (child != null) positionSelector(child);
}
 else {
mSelectedTop=0;
mSelectorRect.setEmpty();
}
if (hasFocus() && focusLayoutRestoreView != null) {
focusLayoutRestoreView.requestFocus();
}
}
if (focusLayoutRestoreView != null && focusLayoutRestoreView.getWindowToken() != null) {
focusLayoutRestoreView.onFinishTemporaryDetach();
}
mLayoutMode=LAYOUT_NORMAL;
mDataChanged=false;
mNeedSync=false;
setNextSelectedPositionInt(mSelectedPosition);
updateScrollIndicators();
if (mItemCount > 0) {
checkSelectionChanged();
}
invokeOnItemScrollListener();
}
  finally {
if (!blockLayoutRequests) {
mBlockLayoutRequests=false;
}
}
}