Program: 4240
Project: 4240
Buggy source:
/** 
 * Scans for the next node, starting at the specified point, and using 'previous' as a hint that the last node we returned was 'previous' (so we know not to return it again).  If 'tree' is non-null, this will limit the search to the given tree. The basic premise is that each iteration can follow the following steps: 1) Scan all the way to the left. a) If we already started from this node last time, proceed to Step 2. b) If a valid uplink is found, use it. c) If the result is an empty node (root not set), break the scan. d) If we already returned the left node, break the scan. 2) Check the right. a) If we already returned the right node, proceed to Step 3. b) If it is a valid uplink, use it. c) Do Step 1 from the right node. 3) Back up through the parents until we encounter find a parent that we're not the right child of. 4) If there's no right child of that parent, the iteration is finished. Otherwise continue to Step 5. 5) Check to see if the right child is a valid uplink. a) If we already returned that child, proceed to Step 6. Otherwise, use it. 6) If the right child of the parent is the parent itself, we've already found & returned the end of the Trie, so exit. 7) Do Step 1 on the parent's right child.
 */
private TrieEntry<K,V> nextEntryImpl(TrieEntry<K,V> start,TrieEntry<K,V> previous,TrieEntry<K,V> tree){
  TrieEntry<K,V> current=start;
  if (previous == null || start != previous.predecessor) {
    while (!current.left.isEmpty()) {
      if (previous == current.left) {
        break;
      }
      if (isValidUplink(current.left,current)) {
        return current.left;
      }
      current=current.left;
    }
  }
  if (current == null || current.isEmpty()) {
    return null;
  }
  if (previous != current.right) {
    if (isValidUplink(current.right,current)) {
      return current.right;
    }
    return nextEntryImpl(current.right,previous,tree);
  }
  while (current == current.parent.right) {
    if (current == tree)     return null;
    current=current.parent;
  }
  if (current == tree)   return null;
  if (current.parent.right == null) {
    return null;
  }
  if (previous != current.parent.right && isValidUplink(current.parent.right,current.parent)) {
    return current.parent.right;
  }
  if (current.parent.right == current.parent) {
    return null;
  }
  return nextEntryImpl(current.parent.right,previous,tree);
}

Fixed version (ground truth):
/** 
 * Scans for the next node, starting at the specified point, and using 'previous' as a hint that the last node we returned was 'previous' (so we know not to return it again).  If 'tree' is non-null, this will limit the search to the given tree. The basic premise is that each iteration can follow the following steps: 1) Scan all the way to the left. a) If we already started from this node last time, proceed to Step 2. b) If a valid uplink is found, use it. c) If the result is an empty node (root not set), break the scan. d) If we already returned the left node, break the scan. 2) Check the right. a) If we already returned the right node, proceed to Step 3. b) If it is a valid uplink, use it. c) Do Step 1 from the right node. 3) Back up through the parents until we encounter find a parent that we're not the right child of. 4) If there's no right child of that parent, the iteration is finished. Otherwise continue to Step 5. 5) Check to see if the right child is a valid uplink. a) If we already returned that child, proceed to Step 6. Otherwise, use it. 6) If the right child of the parent is the parent itself, we've already found & returned the end of the Trie, so exit. 7) Do Step 1 on the parent's right child.
 */
private TrieEntry<K,V> nextEntryImpl(TrieEntry<K,V> start,TrieEntry<K,V> previous,TrieEntry<K,V> tree){
  TrieEntry<K,V> current=start;
  if (previous == null || start != previous.predecessor) {
    while (!current.left.isEmpty()) {
      if (previous == current.left) {
        break;
      }
      if (isValidUplink(current.left,current)) {
        return current.left;
      }
      current=current.left;
    }
  }
  if (current.isEmpty()) {
    return null;
  }
  if (current.right == null)   return null;
  if (previous != current.right) {
    if (isValidUplink(current.right,current)) {
      return current.right;
    }
    return nextEntryImpl(current.right,previous,tree);
  }
  while (current == current.parent.right) {
    if (current == tree)     return null;
    current=current.parent;
  }
  if (current == tree)   return null;
  if (current.parent.right == null) {
    return null;
  }
  if (previous != current.parent.right && isValidUplink(current.parent.right,current.parent)) {
    return current.parent.right;
  }
  if (current.parent.right == current.parent) {
    return null;
  }
  return nextEntryImpl(current.parent.right,previous,tree);
}