Program: 32622
Project: 32622
Buggy source:
/** 
 * {@inheritDoc} 
 */
public void listChanged(ListEvent<E> listChanges){
  if (listChanges.isReordering()) {
    int[] sourceReorder=listChanges.getReorderMap();
    int[] previousIndexToSortedIndex=new int[sorted.size()];
    int index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(sorted); i.hasNext(); index++) {
      i.next();
      Element<Element> unsortedNode=i.value();
      int unsortedIndex=unsorted.indexOfNode(unsortedNode,ALL_COLORS);
      previousIndexToSortedIndex[unsortedIndex]=index;
    }
    int[] newIndexToSortedIndex=new int[sorted.size()];
    for (int i=0; i < previousIndexToSortedIndex.length; i++) {
      newIndexToSortedIndex[i]=previousIndexToSortedIndex[sourceReorder[i]];
    }
    Element<Element>[] unsortedNodes=new Element[unsorted.size()];
    index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(unsorted); i.hasNext(); index++) {
      i.next();
      Element<Element> unsortedNode=i.node();
      unsortedNodes[index]=unsortedNode;
    }
    Arrays.sort(unsortedNodes,sorted.getComparator());
    int[] reorderMap=new int[sorted.size()];
    boolean indexChanged=false;
    index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(sorted); i.hasNext(); index++) {
      i.next();
      Element<Element> sortedNode=i.node();
      Element<Element> unsortedNode=unsortedNodes[index];
      sortedNode.set(unsortedNode);
      unsortedNode.set(sortedNode);
      int unsortedIndex=unsorted.indexOfNode(unsortedNode,ALL_COLORS);
      reorderMap[index]=newIndexToSortedIndex[unsortedIndex];
      indexChanged=indexChanged || (index != reorderMap[index]);
    }
    if (indexChanged) {
      updates.beginEvent();
      updates.reorder(reorderMap);
      updates.commitEvent();
    }
    return;
  }
  updates.beginEvent();
  LinkedList<Element> insertNodes=new LinkedList<Element>();
  List<Element<Element>> updateNodes=new ArrayList<Element<Element>>();
  while (listChanges.next()) {
    int unsortedIndex=listChanges.getIndex();
    int changeType=listChanges.getType();
    if (changeType == ListEvent.INSERT) {
      Element<Element> unsortedNode=unsorted.add(unsortedIndex,EMPTY_ELEMENT,1);
      insertNodes.addLast(unsortedNode);
    }
 else     if (changeType == ListEvent.UPDATE) {
      Element<Element> unsortedNode=unsorted.get(unsortedIndex);
      Element sortedNode=unsortedNode.get();
      sortedNode.setSorted(false);
      updateNodes.add(sortedNode);
    }
 else     if (changeType == ListEvent.DELETE) {
      Element<Element> unsortedNode=unsorted.get(unsortedIndex);
      unsorted.remove(unsortedNode);
      int deleteSortedIndex=deleteByUnsortedNode(unsortedNode);
      updates.addDelete(deleteSortedIndex);
    }
  }
  for (Iterator<Element<Element>> i=updateNodes.iterator(); i.hasNext(); ) {
    Element<Element> sortedNode=i.next();
    int originalIndex=sorted.indexOfNode(sortedNode,ALL_COLORS);
    if (isNodeInSortedOrder(sortedNode)) {
      sortedNode.setSorted(true);
      updates.addUpdate(originalIndex);
    }
 else     if (mode == AVOID_MOVING_ELEMENTS) {
      updates.addUpdate(originalIndex);
    }
 else {
      sorted.remove(sortedNode);
      updates.addDelete(originalIndex);
      int insertedIndex=insertByUnsortedNode(sortedNode.get());
      updates.addInsert(insertedIndex);
    }
  }
  while (!insertNodes.isEmpty()) {
    Element insertNode=insertNodes.removeFirst();
    int insertedIndex=insertByUnsortedNode(insertNode);
    updates.addInsert(insertedIndex);
  }
  updates.commitEvent();
}

Fixed version (ground truth):
/** 
 * {@inheritDoc} 
 */
public void listChanged(ListEvent<E> listChanges){
  if (listChanges.isReordering()) {
    int[] sourceReorder=listChanges.getReorderMap();
    int[] previousIndexToSortedIndex=new int[sorted.size()];
    int index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(sorted); i.hasNext(); index++) {
      i.next();
      Element<Element> unsortedNode=i.value();
      int unsortedIndex=unsorted.indexOfNode(unsortedNode,ALL_COLORS);
      previousIndexToSortedIndex[unsortedIndex]=index;
    }
    int[] newIndexToSortedIndex=new int[sorted.size()];
    for (int i=0; i < previousIndexToSortedIndex.length; i++) {
      newIndexToSortedIndex[i]=previousIndexToSortedIndex[sourceReorder[i]];
    }
    Element<Element>[] unsortedNodes=new Element[unsorted.size()];
    index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(unsorted); i.hasNext(); index++) {
      i.next();
      Element<Element> unsortedNode=i.node();
      unsortedNodes[index]=unsortedNode;
    }
    Arrays.sort(unsortedNodes,sorted.getComparator());
    int[] reorderMap=new int[sorted.size()];
    boolean indexChanged=false;
    index=0;
    for (SimpleTreeIterator<Element> i=new SimpleTreeIterator<Element>(sorted); i.hasNext(); index++) {
      i.next();
      Element<Element> sortedNode=i.node();
      Element<Element> unsortedNode=unsortedNodes[index];
      sortedNode.set(unsortedNode);
      unsortedNode.set(sortedNode);
      int unsortedIndex=unsorted.indexOfNode(unsortedNode,ALL_COLORS);
      reorderMap[index]=newIndexToSortedIndex[unsortedIndex];
      indexChanged=indexChanged || (index != reorderMap[index]);
    }
    if (indexChanged) {
      updates.beginEvent();
      updates.reorder(reorderMap);
      updates.commitEvent();
    }
    return;
  }
  updates.beginEvent();
  LinkedList<Element> insertNodes=new LinkedList<Element>();
  List<Element<Element>> updateNodes=new ArrayList<Element<Element>>();
  while (listChanges.next()) {
    int unsortedIndex=listChanges.getIndex();
    int changeType=listChanges.getType();
    if (changeType == ListEvent.INSERT) {
      Element<Element> unsortedNode=unsorted.add(unsortedIndex,EMPTY_ELEMENT,1);
      insertNodes.addLast(unsortedNode);
    }
 else     if (changeType == ListEvent.UPDATE) {
      Element<Element> unsortedNode=unsorted.get(unsortedIndex);
      Element sortedNode=unsortedNode.get();
      sortedNode.setSorted(Element.PENDING);
      updateNodes.add(sortedNode);
    }
 else     if (changeType == ListEvent.DELETE) {
      Element<Element> unsortedNode=unsorted.get(unsortedIndex);
      unsorted.remove(unsortedNode);
      int deleteSortedIndex=deleteByUnsortedNode(unsortedNode);
      updates.addDelete(deleteSortedIndex);
    }
  }
  for (Iterator<Element<Element>> i=updateNodes.iterator(); i.hasNext(); ) {
    Element<Element> sortedNode=i.next();
    if (sortedNode.getSorted() != Element.PENDING)     continue;
    Element lowerBound=null;
    Element upperBound=null;
    Element firstUnsortedNode=sortedNode;
    for (Element leftNeighbour=sortedNode.previous(); leftNeighbour != null; leftNeighbour=leftNeighbour.previous()) {
      if (leftNeighbour.getSorted() != Element.SORTED) {
        firstUnsortedNode=leftNeighbour;
        continue;
      }
      lowerBound=leftNeighbour;
      break;
    }
    for (Element rightNeighbour=sortedNode.next(); rightNeighbour != null; rightNeighbour=rightNeighbour.next()) {
      if (rightNeighbour.getSorted() != Element.SORTED)       continue;
      upperBound=rightNeighbour;
      break;
    }
    Comparator nodeComparator=sorted.getComparator();
    for (Element current=firstUnsortedNode; current != upperBound; current=current.next()) {
      if (upperBound != null && nodeComparator.compare(current.get(),upperBound.get()) > 0) {
        current.setSorted(Element.UNSORTED);
        continue;
      }
      if (lowerBound != null && nodeComparator.compare(current.get(),lowerBound.get()) < 0) {
        current.setSorted(Element.UNSORTED);
        continue;
      }
      current.setSorted(Element.SORTED);
      lowerBound=current;
    }
  }
  for (Iterator<Element<Element>> i=updateNodes.iterator(); i.hasNext(); ) {
    Element<Element> sortedNode=i.next();
    assert(sortedNode.getSorted() != Element.PENDING);
    int originalIndex=sorted.indexOfNode(sortedNode,ALL_COLORS);
    if (sortedNode.getSorted() == Element.SORTED) {
      updates.addUpdate(originalIndex);
    }
 else     if (mode == AVOID_MOVING_ELEMENTS) {
      updates.addUpdate(originalIndex);
    }
 else {
      sorted.remove(sortedNode);
      updates.addDelete(originalIndex);
      int insertedIndex=insertByUnsortedNode(sortedNode.get());
      updates.addInsert(insertedIndex);
    }
  }
  while (!insertNodes.isEmpty()) {
    Element insertNode=insertNodes.removeFirst();
    int insertedIndex=insertByUnsortedNode(insertNode);
    updates.addInsert(insertedIndex);
  }
  updates.commitEvent();
}