Program: 16584
Project: 16584
Buggy source:
public boolean insertBefore(Component newChild,Component refChild){
  if (newChild instanceof Listitem) {
    if (newChild instanceof Listgroup && inSelectMold())     throw new UnsupportedOperationException("String_Node_Str");
    if (newChild instanceof Listgroupfoot) {
      if (!hasGroup())       throw new UiException("String_Node_Str");
      if (refChild == null) {
        if (getLastChild() instanceof Listgroupfoot)         throw new UiException("String_Node_Str");
        final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
        g[2]=((Listitem)getItems().get(getItems().size() - 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 (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,true);
      final int newIndex=newItem.getIndex();
      if (newItem.isSelected()) {
        if (_jsel < 0) {
          _jsel=newIndex;
          if (!inSelectMold())           smartUpdate("String_Node_Str",getSelectedId());
          _selItems.add(newItem);
        }
 else         if (_multiple) {
          if (_jsel > newIndex) {
            _jsel=newIndex;
            if (!inSelectMold())             smartUpdate("String_Node_Str",getSelectedId());
          }
          _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",getSelectedId());
      }
      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;
            prev[1]=leng;
            _groupsInfo.add(idx,new int[]{lg.getIndex(),size,-1});
          }
 else           if (next != null) {
            _groupsInfo.add(idx,new int[]{lg.getIndex(),next[0] - lg.getIndex(),-1});
          }
        }
      }
 else       if (!_groupsInfo.isEmpty()) {
        final int[] g=getGroupsInfoAt(newItem.getIndex());
        if (g != null) {
          g[1]++;
          if (g[2] != -1)           g[2]++;
        }
      }
      afterInsert(newChild);
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Listhead) {
    if (_listhead != null && _listhead != newChild)     throw new UiException("String_Node_Str" + this);
    final boolean added=_listhead == null;
    refChild=fixRefChildForHeader(refChild);
    _listhead=(Listhead)newChild;
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      invalidate();
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Auxhead) {
    final boolean added=newChild.getParent() != this;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Listfoot) {
    if (_listfoot != null && _listfoot != newChild)     throw new UiException("String_Node_Str" + this);
    if (inSelectMold())     log.warning("String_Node_Str");
    invalidate();
    _listfoot=(Listfoot)newChild;
    refChild=_paging;
    return super.insertBefore(newChild,refChild);
  }
 else   if (newChild instanceof Paging) {
    if (_paging != null && _paging != newChild)     throw new UiException("String_Node_Str" + this);
    if (_pgi != null)     throw new UiException("String_Node_Str");
    if (!inPagingMold())     throw new UiException("String_Node_Str");
    invalidate();
    _pgi=_paging=(Paging)newChild;
    refChild=null;
    return super.insertBefore(newChild,refChild);
  }
 else {
    throw new UiException("String_Node_Str" + newChild);
  }
}

Fixed version (ground truth):
public boolean insertBefore(Component newChild,Component refChild){
  if (newChild instanceof Listitem) {
    if (newChild instanceof Listgroup && inSelectMold())     throw new UnsupportedOperationException("String_Node_Str");
    if (newChild instanceof Listgroupfoot) {
      if (!hasGroup())       throw new UiException("String_Node_Str");
      if (refChild == null) {
        if (getLastChild() instanceof Listgroupfoot)         throw new UiException("String_Node_Str");
        final int[] g=(int[])_groupsInfo.get(getGroupCount() - 1);
        g[2]=((Listitem)getItems().get(getItems().size() - 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;
      }
 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 (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,true);
      final int newIndex=newItem.getIndex();
      if (newItem.isSelected()) {
        if (_jsel < 0) {
          _jsel=newIndex;
          if (!inSelectMold())           smartUpdate("String_Node_Str",getSelectedId());
          _selItems.add(newItem);
        }
 else         if (_multiple) {
          if (_jsel > newIndex) {
            _jsel=newIndex;
            if (!inSelectMold())             smartUpdate("String_Node_Str",getSelectedId());
          }
          _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",getSelectedId());
      }
      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;
            prev[1]=leng;
            _groupsInfo.add(idx,new int[]{lg.getIndex(),size,-1});
          }
 else           if (next != null) {
            _groupsInfo.add(idx,new int[]{lg.getIndex(),next[0] - lg.getIndex(),-1});
          }
        }
      }
 else       if (!_groupsInfo.isEmpty()) {
        final int[] g=getGroupsInfoAt(newItem.getIndex());
        if (g != null) {
          g[1]++;
          if (g[2] != -1)           g[2]++;
        }
      }
      afterInsert(newChild);
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Listhead) {
    if (_listhead != null && _listhead != newChild)     throw new UiException("String_Node_Str" + this);
    final boolean added=_listhead == null;
    refChild=fixRefChildForHeader(refChild);
    _listhead=(Listhead)newChild;
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      invalidate();
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Auxhead) {
    final boolean added=newChild.getParent() != this;
    refChild=fixRefChildForHeader(refChild);
    if (super.insertBefore(newChild,refChild)) {
      if (added)       ++_hdcnt;
      return true;
    }
    return false;
  }
 else   if (newChild instanceof Listfoot) {
    if (_listfoot != null && _listfoot != newChild)     throw new UiException("String_Node_Str" + this);
    if (inSelectMold())     log.warning("String_Node_Str");
    invalidate();
    _listfoot=(Listfoot)newChild;
    refChild=_paging;
    return super.insertBefore(newChild,refChild);
  }
 else   if (newChild instanceof Paging) {
    if (_paging != null && _paging != newChild)     throw new UiException("String_Node_Str" + this);
    if (_pgi != null)     throw new UiException("String_Node_Str");
    if (!inPagingMold())     throw new UiException("String_Node_Str");
    invalidate();
    _pgi=_paging=(Paging)newChild;
    refChild=null;
    return super.insertBefore(newChild,refChild);
  }
 else {
    throw new UiException("String_Node_Str" + newChild);
  }
}