Program: 81725
Project: 81725
Buggy source:
/** 
 * Resolve the pending state and push updates to the view.
 * @param modifiedRows the modified rows that need to be updated, or null ifnone. The modified rows may be mutated.
 * @return true if the state changed, false if not
 */
private boolean resolvePendingState(JsArrayInteger modifiedRows){
  pendingStateCommand=null;
  if (isResolvingState) {
    return false;
  }
  isResolvingState=true;
  if (pendingState == null) {
    isResolvingState=false;
    pendingStateLoop=0;
    return false;
  }
  pendingStateLoop++;
  if (pendingStateLoop > LOOP_MAXIMUM) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
  }
  State<T> oldState=state;
  PendingState<T> pending=pendingState;
  state=pendingState;
  pendingState=null;
  if (modifiedRows == null) {
    modifiedRows=JavaScriptObject.createArray().cast();
  }
  int pageStart=pending.getPageStart();
  int pageSize=pending.getPageSize();
  int pageEnd=pageStart + pageSize;
  int rowDataCount=pending.getRowDataSize();
  pending.keyboardSelectedRow=Math.max(0,Math.min(pending.keyboardSelectedRow,rowDataCount - 1));
  if (KeyboardSelectionPolicy.DISABLED == keyboardSelectionPolicy) {
    pending.keyboardSelectedRow=0;
    pending.keyboardSelectedRowValue=null;
  }
 else   if (pending.keyboardSelectedRowChanged) {
    pending.keyboardSelectedRowValue=rowDataCount > 0 ? pending.getRowDataValue(pending.keyboardSelectedRow) : null;
  }
 else   if (pending.keyboardSelectedRowValue != null) {
    int bestMatchIndex=findIndexOfBestMatch(pending,pending.keyboardSelectedRowValue,pending.keyboardSelectedRow);
    if (bestMatchIndex >= 0) {
      pending.keyboardSelectedRow=bestMatchIndex;
      pending.keyboardSelectedRowValue=rowDataCount > 0 ? pending.getRowDataValue(pending.keyboardSelectedRow) : null;
    }
 else {
      pending.keyboardSelectedRow=0;
      pending.keyboardSelectedRowValue=null;
    }
  }
  try {
    if (KeyboardSelectionPolicy.BOUND_TO_SELECTION == keyboardSelectionPolicy && selectionModel != null && pending.viewTouched) {
      T oldValue=oldState.getSelectedValue();
      Object oldKey=getRowValueKey(oldValue);
      T newValue=rowDataCount > 0 ? pending.getRowDataValue(pending.getKeyboardSelectedRow()) : null;
      Object newKey=getRowValueKey(newValue);
      if (newKey != null) {
        boolean oldValueWasSelected=(oldValue == null) ? false : selectionModel.isSelected(oldValue);
        boolean newValueWasSelected=(newValue == null) ? false : selectionModel.isSelected(newValue);
        if (!newKey.equals(oldKey)) {
          if (oldValueWasSelected) {
            selectionModel.setSelected(oldValue,false);
          }
          pending.selectedValue=newValue;
          if (newValue != null && !newValueWasSelected) {
            selectionModel.setSelected(newValue,true);
          }
        }
 else         if (!newValueWasSelected) {
          pending.selectedValue=null;
        }
      }
      if (pendingState != null) {
        pendingState.selectedValue=pending.selectedValue;
      }
    }
  }
 catch (  RuntimeException e) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw e;
  }
  boolean keyboardRowChanged=pending.keyboardSelectedRowChanged || (oldState.getKeyboardSelectedRow() != pending.keyboardSelectedRow) || (oldState.getKeyboardSelectedRowValue() == null && pending.keyboardSelectedRowValue != null);
  try {
    for (int i=pageStart; i < pageStart + rowDataCount; i++) {
      T rowValue=pending.getRowDataValue(i - pageStart);
      boolean isSelected=(rowValue != null && selectionModel != null && selectionModel.isSelected(rowValue));
      boolean wasSelected=oldState.isRowSelected(i);
      if (isSelected) {
        pending.selectedRows.add(i);
        if (pendingState != null) {
          pendingState.selectedRows.add(i);
        }
        if (!wasSelected) {
          modifiedRows.push(i);
        }
      }
 else       if (wasSelected) {
        modifiedRows.push(i);
      }
    }
  }
 catch (  RuntimeException e) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw e;
  }
  if (pendingState != null) {
    isResolvingState=false;
    if (resolvePendingState(modifiedRows)) {
      return true;
    }
  }
  boolean replacedEmptyRange=false;
  for (  Range replacedRange : pending.replacedRanges) {
    int start=replacedRange.getStart();
    int length=replacedRange.getLength();
    if (length == 0) {
      replacedEmptyRange=true;
    }
    for (int i=start; i < start + length; i++) {
      modifiedRows.push(i);
    }
  }
  if (modifiedRows.length() > 0 && keyboardRowChanged) {
    modifiedRows.push(oldState.getKeyboardSelectedRow());
    modifiedRows.push(pending.keyboardSelectedRow);
  }
  List<Range> modifiedRanges=calculateModifiedRanges(modifiedRows,pageStart,pageEnd);
  Range range0=modifiedRanges.size() > 0 ? modifiedRanges.get(0) : null;
  Range range1=modifiedRanges.size() > 1 ? modifiedRanges.get(1) : null;
  int replaceDiff=0;
  for (  Range range : modifiedRanges) {
    replaceDiff+=range.getLength();
  }
  int oldPageStart=oldState.getPageStart();
  int oldPageSize=oldState.getPageSize();
  int oldRowDataCount=oldState.getRowDataSize();
  boolean redrawRequired=pending.redrawRequired;
  if (pageStart != oldPageStart) {
    redrawRequired=true;
  }
 else   if (rowDataCount < oldRowDataCount) {
    redrawRequired=true;
  }
 else   if (range1 == null && range0 != null && range0.getStart() == pageStart && (replaceDiff >= oldRowDataCount || replaceDiff > oldPageSize)) {
    redrawRequired=true;
  }
 else   if (replaceDiff >= REDRAW_MINIMUM && replaceDiff > REDRAW_THRESHOLD * oldRowDataCount) {
    redrawRequired=true;
  }
 else   if (replacedEmptyRange && oldRowDataCount == 0) {
    redrawRequired=true;
  }
  updateLoadingState();
  try {
    if (redrawRequired) {
      SafeHtmlBuilder sb=new SafeHtmlBuilder();
      view.replaceAllChildren(pending.rowData,selectionModel,pending.keyboardStealFocus);
      view.resetFocus();
    }
 else     if (range0 != null) {
{
        int absStart=range0.getStart();
        int relStart=absStart - pageStart;
        SafeHtmlBuilder sb=new SafeHtmlBuilder();
        List<T> replaceValues=pending.rowData.subList(relStart,relStart + range0.getLength());
        view.replaceChildren(replaceValues,relStart,selectionModel,pending.keyboardStealFocus);
      }
      if (range1 != null) {
        int absStart=range1.getStart();
        int relStart=absStart - pageStart;
        SafeHtmlBuilder sb=new SafeHtmlBuilder();
        List<T> replaceValues=pending.rowData.subList(relStart,relStart + range1.getLength());
        view.replaceChildren(replaceValues,relStart,selectionModel,pending.keyboardStealFocus);
      }
      view.resetFocus();
    }
 else     if (keyboardRowChanged) {
      int oldSelectedRow=oldState.getKeyboardSelectedRow();
      if (oldSelectedRow >= 0 && oldSelectedRow < rowDataCount) {
        view.setKeyboardSelected(oldSelectedRow,false,false);
      }
      int newSelectedRow=pending.getKeyboardSelectedRow();
      if (newSelectedRow >= 0 && newSelectedRow < rowDataCount) {
        view.setKeyboardSelected(newSelectedRow,true,pending.keyboardStealFocus);
      }
    }
  }
 catch (  Error e) {
    throw new RuntimeException(e);
  }
 finally {
    isResolvingState=false;
  }
  resolvePendingState(null);
  return true;
}

Fixed version (ground truth):
/** 
 * Resolve the pending state and push updates to the view.
 * @param modifiedRows the modified rows that need to be updated, or null ifnone. The modified rows may be mutated.
 * @return true if the state changed, false if not
 */
private boolean resolvePendingState(JsArrayInteger modifiedRows){
  pendingStateCommand=null;
  if (isResolvingState) {
    return false;
  }
  isResolvingState=true;
  if (pendingState == null) {
    isResolvingState=false;
    pendingStateLoop=0;
    return false;
  }
  pendingStateLoop++;
  if (pendingStateLoop > LOOP_MAXIMUM) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw new IllegalStateException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
  }
  State<T> oldState=state;
  PendingState<T> pending=pendingState;
  state=pendingState;
  pendingState=null;
  if (modifiedRows == null) {
    modifiedRows=JavaScriptObject.createArray().cast();
  }
  int pageStart=pending.getPageStart();
  int pageSize=pending.getPageSize();
  int pageEnd=pageStart + pageSize;
  int rowDataCount=pending.getRowDataSize();
  pending.keyboardSelectedRow=Math.max(0,Math.min(pending.keyboardSelectedRow,rowDataCount - 1));
  if (KeyboardSelectionPolicy.DISABLED == keyboardSelectionPolicy) {
    pending.keyboardSelectedRow=0;
    pending.keyboardSelectedRowValue=null;
  }
 else   if (pending.keyboardSelectedRowChanged) {
    pending.keyboardSelectedRowValue=rowDataCount > 0 ? pending.getRowDataValue(pending.keyboardSelectedRow) : null;
  }
 else   if (pending.keyboardSelectedRowValue != null) {
    int bestMatchIndex=findIndexOfBestMatch(pending,pending.keyboardSelectedRowValue,pending.keyboardSelectedRow);
    if (bestMatchIndex >= 0) {
      pending.keyboardSelectedRow=bestMatchIndex;
      pending.keyboardSelectedRowValue=rowDataCount > 0 ? pending.getRowDataValue(pending.keyboardSelectedRow) : null;
    }
 else {
      pending.keyboardSelectedRow=0;
      pending.keyboardSelectedRowValue=null;
    }
  }
  try {
    if (KeyboardSelectionPolicy.BOUND_TO_SELECTION == keyboardSelectionPolicy && selectionModel != null && pending.viewTouched) {
      T oldValue=oldState.getSelectedValue();
      Object oldKey=getRowValueKey(oldValue);
      T newValue=rowDataCount > 0 ? pending.getRowDataValue(pending.getKeyboardSelectedRow()) : null;
      Object newKey=getRowValueKey(newValue);
      if (newKey != null) {
        boolean oldValueWasSelected=(oldValue == null) ? false : selectionModel.isSelected(oldValue);
        boolean newValueWasSelected=(newValue == null) ? false : selectionModel.isSelected(newValue);
        if (!newKey.equals(oldKey)) {
          if (oldValueWasSelected) {
            selectionModel.setSelected(oldValue,false);
          }
          pending.selectedValue=newValue;
          if (newValue != null && !newValueWasSelected) {
            selectionModel.setSelected(newValue,true);
          }
        }
 else         if (!newValueWasSelected) {
          pending.selectedValue=null;
        }
      }
      if (pendingState != null) {
        pendingState.selectedValue=pending.selectedValue;
      }
    }
  }
 catch (  RuntimeException e) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw e;
  }
  boolean keyboardRowChanged=pending.keyboardSelectedRowChanged || (oldState.getKeyboardSelectedRow() != pending.keyboardSelectedRow) || (oldState.getKeyboardSelectedRowValue() == null && pending.keyboardSelectedRowValue != null);
  try {
    for (int i=pageStart; i < pageStart + rowDataCount; i++) {
      T rowValue=pending.getRowDataValue(i - pageStart);
      boolean isSelected=(rowValue != null && selectionModel != null && selectionModel.isSelected(rowValue));
      boolean wasSelected=oldState.isRowSelected(i);
      if (isSelected) {
        pending.selectedRows.add(i);
        if (pendingState != null) {
          pendingState.selectedRows.add(i);
        }
        if (!wasSelected) {
          modifiedRows.push(i);
        }
      }
 else       if (wasSelected) {
        modifiedRows.push(i);
      }
    }
  }
 catch (  RuntimeException e) {
    isResolvingState=false;
    pendingStateLoop=0;
    throw e;
  }
  boolean replacedEmptyRange=false;
  for (  Range replacedRange : pending.replacedRanges) {
    int start=replacedRange.getStart();
    int length=replacedRange.getLength();
    if (length == 0) {
      replacedEmptyRange=true;
    }
    for (int i=start; i < start + length; i++) {
      modifiedRows.push(i);
    }
  }
  if (modifiedRows.length() > 0 && keyboardRowChanged) {
    modifiedRows.push(oldState.getKeyboardSelectedRow());
    modifiedRows.push(pending.keyboardSelectedRow);
  }
  if (pendingState != null) {
    isResolvingState=false;
    modifiedRows.push(oldState.getKeyboardSelectedRow());
    modifiedRows.push(pending.keyboardSelectedRow);
    if (resolvePendingState(modifiedRows)) {
      return true;
    }
  }
  List<Range> modifiedRanges=calculateModifiedRanges(modifiedRows,pageStart,pageEnd);
  Range range0=modifiedRanges.size() > 0 ? modifiedRanges.get(0) : null;
  Range range1=modifiedRanges.size() > 1 ? modifiedRanges.get(1) : null;
  int replaceDiff=0;
  for (  Range range : modifiedRanges) {
    replaceDiff+=range.getLength();
  }
  int oldPageStart=oldState.getPageStart();
  int oldPageSize=oldState.getPageSize();
  int oldRowDataCount=oldState.getRowDataSize();
  boolean redrawRequired=pending.redrawRequired;
  if (pageStart != oldPageStart) {
    redrawRequired=true;
  }
 else   if (rowDataCount < oldRowDataCount) {
    redrawRequired=true;
  }
 else   if (range1 == null && range0 != null && range0.getStart() == pageStart && (replaceDiff >= oldRowDataCount || replaceDiff > oldPageSize)) {
    redrawRequired=true;
  }
 else   if (replaceDiff >= REDRAW_MINIMUM && replaceDiff > REDRAW_THRESHOLD * oldRowDataCount) {
    redrawRequired=true;
  }
 else   if (replacedEmptyRange && oldRowDataCount == 0) {
    redrawRequired=true;
  }
  updateLoadingState();
  try {
    if (redrawRequired) {
      SafeHtmlBuilder sb=new SafeHtmlBuilder();
      view.replaceAllChildren(pending.rowData,selectionModel,pending.keyboardStealFocus);
      view.resetFocus();
    }
 else     if (range0 != null) {
{
        int absStart=range0.getStart();
        int relStart=absStart - pageStart;
        SafeHtmlBuilder sb=new SafeHtmlBuilder();
        List<T> replaceValues=pending.rowData.subList(relStart,relStart + range0.getLength());
        view.replaceChildren(replaceValues,relStart,selectionModel,pending.keyboardStealFocus);
      }
      if (range1 != null) {
        int absStart=range1.getStart();
        int relStart=absStart - pageStart;
        SafeHtmlBuilder sb=new SafeHtmlBuilder();
        List<T> replaceValues=pending.rowData.subList(relStart,relStart + range1.getLength());
        view.replaceChildren(replaceValues,relStart,selectionModel,pending.keyboardStealFocus);
      }
      view.resetFocus();
    }
 else     if (keyboardRowChanged) {
      int oldSelectedRow=oldState.getKeyboardSelectedRow();
      if (oldSelectedRow >= 0 && oldSelectedRow < rowDataCount) {
        view.setKeyboardSelected(oldSelectedRow,false,false);
      }
      int newSelectedRow=pending.getKeyboardSelectedRow();
      if (newSelectedRow >= 0 && newSelectedRow < rowDataCount) {
        view.setKeyboardSelected(newSelectedRow,true,pending.keyboardStealFocus);
      }
    }
  }
 catch (  Error e) {
    throw new RuntimeException(e);
  }
 finally {
    isResolvingState=false;
  }
  resolvePendingState(null);
  return true;
}