Program: 16455
Project: 16455
Buggy source:
public boolean insertBefore(Component child,Component refChild){
  final Grid grid=getGrid();
  final boolean isReorder=child.getParent() == this;
  if (isReorder) {
    checkInvalidateForMoved(child,true);
  }
  if (grid != null && grid.isRod() && hasGroupsModel()) {
    if (_groupsInfo.isEmpty())     _groupsInfo=((GroupsListModel)grid.getModel()).getGroupsInfo();
    if (super.insertBefore(child,refChild)) {
      if (!isReorder) {
        afterInsert(child);
      }
      return true;
    }
    return false;
  }
  Row newItem=(Row)child;
  final int jfrom=hasGroup() && newItem.getParent() == this ? newItem.getIndex() : -1;
  if (newItem instanceof Groupfoot) {
    if (refChild == null) {
      if (isReorder) {
        final int idx=newItem.getIndex();
        final int[] ginfo=getGroupsInfoAt(idx);
        if (ginfo != null) {
          ginfo[1]--;
          ginfo[2]=-1;
        }
      }
      final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
      g[2]=getChildren().size() - (isReorder ? 2 : 1);
    }
 else {
      final int idx=((Row)refChild).getIndex();
      final int[] g=getGroupsInfoAt(idx);
      if (g == null)       throw new UiException("String_Node_Str");
      if (g[2] != -1)       throw new UiException("String_Node_Str");
      if (idx != (g[0] + g[1]))       throw new UiException("String_Node_Str");
      g[2]=idx - 1;
      if (isReorder) {
        final int nindex=newItem.getIndex();
        final int[] ginfo=getGroupsInfoAt(nindex);
        if (ginfo != null) {
          ginfo[1]--;
          ginfo[2]=-1;
        }
      }
    }
  }
  if (super.insertBefore(child,refChild)) {
    if (hasGroup()) {
      final int jto=refChild instanceof Row ? ((Row)refChild).getIndex() : -1, fixFrom=jfrom < 0 || (jto >= 0 && jfrom > jto) ? jto : jfrom;
      if (fixFrom >= 0)       fixGroupIndex(fixFrom,jfrom >= 0 && jto >= 0 ? jfrom > jto ? jfrom : jto : -1,!isReorder);
    }
    if (newItem instanceof Group) {
      Group group=(Group)newItem;
      int index=group.getIndex();
      if (_groupsInfo.isEmpty())       _groupsInfo.add(new int[]{group.getIndex(),getChildren().size() - index,-1});
 else {
        int idx=0;
        int[] prev=null, next=null;
        for (Iterator it=_groupsInfo.iterator(); it.hasNext(); ) {
          int[] g=(int[])it.next();
          if (g[0] <= index) {
            prev=g;
            idx++;
          }
 else {
            next=g;
            break;
          }
        }
        if (prev != null) {
          int leng=index - prev[0], size=prev[1] - leng + 1;
          prev[1]=leng;
          _groupsInfo.add(idx,new int[]{index,size,size > 1 && prev[2] > index ? prev[2] : -1});
          if (size > 1 && prev[2] > index)           prev[2]=-1;
        }
 else         if (next != null) {
          _groupsInfo.add(idx,new int[]{index,next[0] - index,-1});
        }
      }
    }
 else     if (hasGroup()) {
      int index=newItem.getIndex();
      final int[] g=getGroupsInfoAt(index);
      if (g != null) {
        g[1]++;
        if (g[2] != -1 && (g[2] >= index || newItem instanceof Groupfoot))         g[2]=g[0] + g[1] - 1;
      }
    }
    if (!isReorder) {
      afterInsert(child);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
public boolean insertBefore(Component child,Component refChild){
  final Grid grid=getGrid();
  final boolean isReorder=child.getParent() == this;
  if (isReorder) {
    checkInvalidateForMoved(child,true);
  }
  if (grid != null && grid.isRod() && hasGroupsModel()) {
    if (_groupsInfo.isEmpty())     _groupsInfo=((GroupsListModel)grid.getModel()).getGroupsInfo();
    if (super.insertBefore(child,refChild)) {
      if (!isReorder) {
        afterInsert(child);
      }
      return true;
    }
    return false;
  }
  Row newItem=(Row)child;
  final int jfrom=hasGroup() && newItem.getParent() == this ? newItem.getIndex() : -1;
  if (newItem instanceof Groupfoot) {
    if (refChild == null) {
      if (isReorder) {
        final int idx=newItem.getIndex();
        final int[] ginfo=getGroupsInfoAt(idx);
        if (ginfo != null) {
          ginfo[1]--;
          ginfo[2]=-1;
        }
      }
      final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
      g[2]=getChildren().size() - (isReorder ? 2 : 1);
    }
 else {
      final int idx=((Row)refChild).getIndex();
      final int[] g=getGroupsInfoAt(idx);
      if (g == null)       throw new UiException("String_Node_Str");
      if (g[2] != -1)       throw new UiException("String_Node_Str");
      if (idx != (g[0] + g[1]))       throw new UiException("String_Node_Str");
      g[2]=idx - 1;
      if (isReorder) {
        final int nindex=newItem.getIndex();
        final int[] ginfo=getGroupsInfoAt(nindex);
        if (ginfo != null) {
          ginfo[1]--;
          ginfo[2]=-1;
        }
      }
    }
  }
  if (super.insertBefore(child,refChild)) {
    if (hasGroup()) {
      final int jto=refChild instanceof Row ? ((Row)refChild).getIndex() : -1, fixFrom=jfrom < 0 || (jto >= 0 && jfrom > jto) ? jto : jfrom;
      if (fixFrom >= 0)       fixGroupIndex(fixFrom,jfrom >= 0 && jto >= 0 ? jfrom > jto ? jfrom : jto : -1,!isReorder);
    }
    if (newItem instanceof Group) {
      Group group=(Group)newItem;
      int index=group.getIndex();
      if (_groupsInfo.isEmpty())       _groupsInfo.add(new int[]{group.getIndex(),getChildren().size() - index,-1});
 else {
        int idx=0;
        int[] prev=null, next=null;
        for (Iterator it=_groupsInfo.iterator(); it.hasNext(); ) {
          int[] g=(int[])it.next();
          if (g[0] <= index) {
            prev=g;
            idx++;
          }
 else {
            next=g;
            break;
          }
        }
        if (prev != null) {
          int leng=index - prev[0], size=prev[1] - leng + 1;
          prev[1]=leng;
          _groupsInfo.add(idx,new int[]{index,size,size > 1 && prev[2] > index ? prev[2] : -1});
          if (size > 1 && prev[2] > index)           prev[2]=-1;
        }
 else         if (next != null) {
          _groupsInfo.add(idx,new int[]{index,next[0] - index,-1});
        }
      }
    }
 else     if (hasGroup()) {
      int index=newItem.getIndex();
      final int[] g=getGroupsInfoAt(index);
      if (g != null) {
        g[1]++;
        if (g[2] != -1 && (g[2] >= index || newItem instanceof Groupfoot))         g[2]=g[0] + g[1] - 1;
      }
    }
 else     if (hasModelButNotROD()) {
      int index=newItem.getIndex();
      fixRowIndices(index,-1);
    }
    if (!isReorder) {
      afterInsert(child);
    }
    return true;
  }
  return false;
}