Program: 16591
Project: 16591
Buggy source:
/** 
 * Synchronizes the grid to be consistent with the specified model.
 * @param min the lower index that a range of invalidated rows
 * @param max the higher index that a range of invalidated rows
 */
private void syncModel(int min,int max){
  final int newsz=_model.getSize();
  final int oldsz=_rows != null ? _rows.getChildren().size() : 0;
  int newcnt=newsz - oldsz;
  RowRenderer renderer=null;
  Component next=null;
  if (oldsz > 0) {
    if (min < 0)     min=0;
 else     if (min > oldsz - 1)     min=oldsz - 1;
    if (max < 0)     max=oldsz - 1;
 else     if (max > oldsz - 1)     max=oldsz - 1;
    if (min > max) {
      int t=min;
      min=max;
      max=t;
    }
    int cnt=max - min + 1;
    if (_model instanceof GroupsListModel) {
      newcnt+=cnt;
      if (newcnt > 50 && !inPagingMold())       invalidate();
      Component comp=(Component)_rows.getChildren().get(max);
      next=comp.getNextSibling();
      while (--cnt >= 0) {
        Component p=comp.getPreviousSibling();
        comp.detach();
        comp=p;
      }
    }
 else {
      int addcnt=0;
      Row row=(Row)_rows.getChildren().get(min);
      while (--cnt >= 0) {
        next=row.getNextSibling();
        if (cnt < -newcnt) {
          row.detach();
        }
 else         if (row.isLoaded()) {
          if (renderer == null)           renderer=getRealRenderer();
          row.detach();
          _rows.insertBefore(newUnloadedRow(renderer,min++),next);
          ++addcnt;
        }
        row=(Row)next;
      }
      if ((addcnt > 50 || addcnt + newcnt > 50) && !inPagingMold())       invalidate();
    }
  }
 else {
    min=0;
    if (_rows == null)     new Rows().setParent(this);
  }
  for (; --newcnt >= 0; ++min) {
    if (renderer == null)     renderer=getRealRenderer();
    _rows.insertBefore(newUnloadedRow(renderer,min),next);
  }
}

Fixed version (ground truth):
/** 
 * Synchronizes the grid to be consistent with the specified model.
 * @param min the lower index that a range of invalidated rows
 * @param max the higher index that a range of invalidated rows
 */
private void syncModel(int min,int max){
  final int newsz=_model.getSize();
  final int oldsz=_rows != null ? _rows.getChildren().size() : 0;
  int newcnt=newsz - oldsz;
  RowRenderer renderer=null;
  Component next=null;
  if (oldsz > 0) {
    if (min < 0)     min=0;
 else     if (min > oldsz - 1)     min=oldsz - 1;
    if (max < 0)     max=oldsz - 1;
 else     if (max > oldsz - 1)     max=oldsz - 1;
    if (min > max) {
      int t=min;
      min=max;
      max=t;
    }
    int cnt=max - min + 1;
    if (_model instanceof GroupsListModel) {
      newcnt+=cnt;
      if (newcnt > 50 && !inPagingMold())       invalidate();
      Component comp=(Component)_rows.getChildren().get(max);
      next=comp.getNextSibling();
      while (--cnt >= 0) {
        Component p=comp.getPreviousSibling();
        comp.detach();
        comp=p;
      }
    }
 else {
      int addcnt=0;
      Component row=(Row)_rows.getChildren().get(min);
      while (--cnt >= 0) {
        next=row.getNextSibling();
        if (cnt < -newcnt) {
          row.detach();
        }
 else         if (((Row)row).isLoaded()) {
          if (renderer == null)           renderer=getRealRenderer();
          row.detach();
          _rows.insertBefore(newUnloadedRow(renderer,min++),next);
          ++addcnt;
        }
        row=next;
      }
      if ((addcnt > 50 || addcnt + newcnt > 50) && !inPagingMold())       invalidate();
    }
  }
 else {
    min=0;
    if (_rows == null)     new Rows().setParent(this);
  }
  for (; --newcnt >= 0; ++min) {
    if (renderer == null)     renderer=getRealRenderer();
    _rows.insertBefore(newUnloadedRow(renderer,min),next);
  }
}