Program: 16547
Project: 16547
Buggy source:
public boolean insertBefore(Component newChild,Component refChild){
  if (newChild instanceof Listitem) {
    final boolean isReorder=newChild.getParent() == this;
    if (newChild instanceof Listgroupfoot) {
      if (refChild == null) {
        if (isReorder) {
          final int idx=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(idx);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
        final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
        g[2]=((Listitem)getItems().get(getItems().size() - (isReorder ? 2 : 1))).getIndex();
      }
 else       if (refChild instanceof Listitem) {
        final int idx=((Listitem)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=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(nindex);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
      }
 else       if (refChild.getPreviousSibling() instanceof Listitem) {
        final int idx=((Listitem)refChild.getPreviousSibling()).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 + 1 != (g[0] + g[1]))         throw new UiException("String_Node_Str");
        g[2]=idx;
        if (isReorder) {
          final int nindex=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(nindex);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
      }
    }
    if (refChild != null && refChild.getParent() != this)     refChild=null;
    if (refChild != null && (refChild == _listhead || refChild instanceof Auxhead))     refChild=getChildren().size() > _hdcnt ? (Component)getChildren().get(_hdcnt) : null;
    refChild=fixRefChildBeforeFoot(refChild);
    final Listitem newItem=(Listitem)newChild;
    final int jfrom=newItem.getParent() == this ? newItem.getIndex() : -1;
    if (super.insertBefore(newChild,refChild)) {
      final int jto=refChild instanceof Listitem ? ((Listitem)refChild).getIndex() : -1, fixFrom=jfrom < 0 || (jto >= 0 && jfrom > jto) ? jto : jfrom;
      if (fixFrom < 0)       newItem.setIndexDirectly(_items.size() - 1);
 else       fixGroupIndex(fixFrom,jfrom >= 0 && jto >= 0 ? jfrom > jto ? jfrom : jto : -1,!isReorder);
      final int newIndex=newItem.getIndex();
      if (newItem.isSelected()) {
        if (_jsel < 0) {
          _jsel=newIndex;
          if (!inSelectMold())           smartUpdate("String_Node_Str",getSelUuid());
          _selItems.add(newItem);
        }
 else         if (_multiple) {
          if (_jsel > newIndex) {
            _jsel=newIndex;
            if (!inSelectMold())             smartUpdate("String_Node_Str",getSelUuid());
          }
          _selItems.add(newItem);
        }
 else {
          newItem.setSelectedDirectly(false);
        }
      }
 else {
        final int oldjsel=_jsel;
        if (jfrom < 0) {
          if (_jsel >= newIndex)           ++_jsel;
        }
 else         if (_jsel >= 0) {
          if (jfrom > _jsel) {
            if (jto >= 0 && jto <= _jsel)             ++_jsel;
          }
 else {
            if (jto < 0 || jto > _jsel)             --_jsel;
          }
        }
        if (oldjsel != _jsel && !inSelectMold())         smartUpdate("String_Node_Str",getSelUuid());
      }
      if (newChild instanceof Listgroup) {
        Listgroup lg=(Listgroup)newChild;
        if (_groupsInfo.isEmpty())         _groupsInfo.add(new int[]{lg.getIndex(),getItemCount() - lg.getIndex(),-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] <= lg.getIndex()) {
              prev=g;
              idx++;
            }
 else {
              next=g;
              break;
            }
          }
          if (prev != null) {
            int leng=lg.getIndex() - prev[0], size=prev[1] - leng + 1, index=lg.getIndex();
            prev[1]=leng;
            _groupsInfo.add(idx,new int[]{index,size,size > 1 && prev[2] > index ? prev[2] : -1});
            if (size > 1)             prev[2]=-1;
          }
 else           if (next != null) {
            _groupsInfo.add(idx,new int[]{lg.getIndex(),next[0] - lg.getIndex(),-1});
          }
        }
      }
 else       if (!_groupsInfo.isEmpty()) {
        int index=newItem.getIndex();
        final int[] g=getGroupsInfoAt(index);
        if (g != null) {
          g[1]++;
          if (g[2] != -1 && g[2] > index)           g[2]++;
        }
      }
      afterInsert(newChild);
      return true;
    }
  }
 else   if (newChild instanceof Listhead) {
    final boolean added=_listhead == null;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      _listhead=(Listhead)newChild;
      if (added)       ++_hdcnt;
      return true;
    }
  }
 else   if (newChild instanceof Auxhead) {
    final boolean added=newChild.getParent() != this;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      return true;
    }
  }
 else   if (newChild instanceof Frozen) {
    refChild=_paging;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _frozen=(Frozen)newChild;
      return true;
    }
  }
 else   if (newChild instanceof Listfoot) {
    if (_frozen != null)     refChild=_frozen;
 else     refChild=_paging;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _listfoot=(Listfoot)newChild;
      return true;
    }
  }
 else   if (newChild instanceof Paging) {
    refChild=null;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _pgi=_paging=(Paging)newChild;
      return true;
    }
  }
 else {
    return super.insertBefore(newChild,refChild);
  }
  return false;
}

Fixed version (ground truth):
public boolean insertBefore(Component newChild,Component refChild){
  if (newChild instanceof Listitem) {
    final boolean isReorder=newChild.getParent() == this;
    if (newChild instanceof Listgroupfoot) {
      if (refChild == null) {
        if (isReorder) {
          final int idx=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(idx);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
        final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
        g[2]=((Listitem)getItems().get(getItems().size() - (isReorder ? 2 : 1))).getIndex();
      }
 else       if (refChild instanceof Listitem) {
        final int idx=((Listitem)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=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(nindex);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
      }
 else       if (refChild.getPreviousSibling() instanceof Listitem) {
        final int idx=((Listitem)refChild.getPreviousSibling()).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 + 1 != (g[0] + g[1]))         throw new UiException("String_Node_Str");
        g[2]=idx;
        if (isReorder) {
          final int nindex=((Listgroupfoot)newChild).getIndex();
          final int[] ginfo=getGroupsInfoAt(nindex);
          if (ginfo != null) {
            ginfo[1]--;
            ginfo[2]=-1;
          }
        }
      }
    }
    if (refChild != null && refChild.getParent() != this)     refChild=null;
    if (refChild != null && (refChild == _listhead || refChild instanceof Auxhead))     refChild=getChildren().size() > _hdcnt ? (Component)getChildren().get(_hdcnt) : null;
    refChild=fixRefChildBeforeFoot(refChild);
    final Listitem newItem=(Listitem)newChild;
    final int jfrom=newItem.getParent() == this ? newItem.getIndex() : -1;
    if (super.insertBefore(newChild,refChild)) {
      final int jto=refChild instanceof Listitem ? ((Listitem)refChild).getIndex() : -1, fixFrom=jfrom < 0 || (jto >= 0 && jfrom > jto) ? jto : jfrom;
      if (fixFrom < 0)       newItem.setIndexDirectly(_items.size() - 1);
 else       fixGroupIndex(fixFrom,jfrom >= 0 && jto >= 0 ? jfrom > jto ? jfrom : jto : -1,!isReorder);
      final int newIndex=newItem.getIndex();
      if (newItem.isSelected()) {
        if (_jsel < 0) {
          _jsel=newIndex;
          if (!inSelectMold())           smartUpdate("String_Node_Str",getSelUuid());
          _selItems.add(newItem);
        }
 else         if (_multiple) {
          if (_jsel > newIndex) {
            _jsel=newIndex;
            if (!inSelectMold())             smartUpdate("String_Node_Str",getSelUuid());
          }
          _selItems.add(newItem);
        }
 else {
          newItem.setSelectedDirectly(false);
        }
      }
 else {
        final int oldjsel=_jsel;
        if (jfrom < 0) {
          if (_jsel >= newIndex)           ++_jsel;
        }
 else         if (_jsel >= 0) {
          if (jfrom > _jsel) {
            if (jto >= 0 && jto <= _jsel)             ++_jsel;
          }
 else {
            if (jto < 0 || jto > _jsel)             --_jsel;
          }
        }
        if (oldjsel != _jsel && !inSelectMold())         smartUpdate("String_Node_Str",getSelUuid());
      }
      if (newChild instanceof Listgroup) {
        Listgroup lg=(Listgroup)newChild;
        if (_groupsInfo.isEmpty())         _groupsInfo.add(new int[]{lg.getIndex(),getItemCount() - lg.getIndex(),-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] <= lg.getIndex()) {
              prev=g;
              idx++;
            }
 else {
              next=g;
              break;
            }
          }
          if (prev != null) {
            int index=lg.getIndex(), 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[]{lg.getIndex(),next[0] - lg.getIndex(),-1});
          }
        }
      }
 else       if (!_groupsInfo.isEmpty()) {
        int index=newItem.getIndex();
        final int[] g=getGroupsInfoAt(index);
        if (g != null) {
          g[1]++;
          if (g[2] != -1 && g[2] > index)           g[2]++;
        }
      }
      afterInsert(newChild);
      return true;
    }
  }
 else   if (newChild instanceof Listhead) {
    final boolean added=_listhead == null;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      _listhead=(Listhead)newChild;
      if (added)       ++_hdcnt;
      return true;
    }
  }
 else   if (newChild instanceof Auxhead) {
    final boolean added=newChild.getParent() != this;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      return true;
    }
  }
 else   if (newChild instanceof Frozen) {
    refChild=_paging;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _frozen=(Frozen)newChild;
      return true;
    }
  }
 else   if (newChild instanceof Listfoot) {
    if (_frozen != null)     refChild=_frozen;
 else     refChild=_paging;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _listfoot=(Listfoot)newChild;
      return true;
    }
  }
 else   if (newChild instanceof Paging) {
    refChild=null;
    if (super.insertBefore(newChild,refChild)) {
      invalidate();
      _pgi=_paging=(Paging)newChild;
      return true;
    }
  }
 else {
    return super.insertBefore(newChild,refChild);
  }
  return false;
}