Program: 32587
Project: 32587
Buggy source:
/** 
 * Handle a source insert at the specified index by adding the corresponding real node, or converting a virtual node to a real node. The real node is inserted, marked as real and hidden, and returned.
 * @param sourceIndex the index of the element in the source list that hasbeen inserted
 * @return the new node, prior to any events fired
 */
private Node<E> findOrInsertNode(int sourceIndex){
  Node<E> inserted=source.get(sourceIndex);
  int predecessorIndex=sourceIndex > 0 ? data.convertIndexColor(sourceIndex - 1,REAL_NODES,ALL_NODES) : -1;
  int followerIndex=data.size(REAL_NODES) > sourceIndex ? data.convertIndexColor(sourceIndex,REAL_NODES,ALL_NODES) : data.size(ALL_NODES);
  int indexOfNearestAncestorByValue=predecessorIndex;
  int lengthOfLongestAncestorCommonPath;
  if (predecessorIndex >= 0) {
    Node<E> predecessor=data.get(predecessorIndex,ALL_NODES).get();
    lengthOfLongestAncestorCommonPath=commonPathLength(inserted,predecessor);
  }
 else {
    lengthOfLongestAncestorCommonPath=0;
  }
  for (int i=predecessorIndex + 1; i < followerIndex; i++) {
    Node<E> possibleAncestor=data.get(i,ALL_NODES).get();
    assert(possibleAncestor.virtual);
    if (possibleAncestor.pathLength() > inserted.pathLength())     continue;
    int commonPathLength=commonPathLength(inserted,possibleAncestor);
    if (commonPathLength == inserted.pathLength()) {
      assert(inserted.pathLength() == possibleAncestor.pathLength());
      inserted.updateFrom(possibleAncestor);
      possibleAncestor.element.set(inserted);
      setVirtual(possibleAncestor,false);
      for (Node<E> child=possibleAncestor.firstChild(); child != null; child=child.siblingAfter) {
        child.parent=inserted;
      }
      possibleAncestor.element=null;
      return inserted;
    }
 else     if (commonPathLength > lengthOfLongestAncestorCommonPath) {
      lengthOfLongestAncestorCommonPath=commonPathLength;
      indexOfNearestAncestorByValue=i;
    }
  }
  inserted.element=data.add(indexOfNearestAncestorByValue + 1,ALL_NODES,HIDDEN_REAL,inserted,1);
  return inserted;
}

Fixed version (ground truth):
/** 
 * Handle a source insert at the specified index by adding the corresponding real node, or converting a virtual node to a real node. The real node is inserted, marked as real and hidden, and returned.
 * @param sourceIndex the index of the element in the source list that hasbeen inserted
 * @return the new node, prior to any events fired
 */
private Node<E> findOrInsertNode(int sourceIndex){
  Node<E> inserted=source.get(sourceIndex);
  inserted.reset();
  int predecessorIndex=sourceIndex > 0 ? data.convertIndexColor(sourceIndex - 1,REAL_NODES,ALL_NODES) : -1;
  int followerIndex=data.size(REAL_NODES) > sourceIndex ? data.convertIndexColor(sourceIndex,REAL_NODES,ALL_NODES) : data.size(ALL_NODES);
  int indexOfNearestAncestorByValue=predecessorIndex;
  int lengthOfLongestAncestorCommonPath;
  if (predecessorIndex >= 0) {
    Node<E> predecessor=data.get(predecessorIndex,ALL_NODES).get();
    lengthOfLongestAncestorCommonPath=commonPathLength(inserted,predecessor);
  }
 else {
    lengthOfLongestAncestorCommonPath=0;
  }
  for (int i=predecessorIndex + 1; i < followerIndex; i++) {
    Node<E> possibleAncestor=data.get(i,ALL_NODES).get();
    assert(possibleAncestor.virtual);
    if (possibleAncestor.pathLength() > inserted.pathLength())     continue;
    int commonPathLength=commonPathLength(inserted,possibleAncestor);
    if (commonPathLength == inserted.pathLength()) {
      assert(inserted.pathLength() == possibleAncestor.pathLength());
      inserted.updateFrom(possibleAncestor);
      possibleAncestor.element.set(inserted);
      setVirtual(possibleAncestor,false);
      for (Node<E> child=possibleAncestor.firstChild(); child != null; child=child.siblingAfter) {
        child.parent=inserted;
      }
      possibleAncestor.element=null;
      return inserted;
    }
 else     if (commonPathLength > lengthOfLongestAncestorCommonPath) {
      lengthOfLongestAncestorCommonPath=commonPathLength;
      indexOfNearestAncestorByValue=i;
    }
  }
  inserted.element=data.add(indexOfNearestAncestorByValue + 1,ALL_NODES,HIDDEN_REAL,inserted,1);
  return inserted;
}