Program: 54541
Project: 54541
Buggy source:
private boolean removeWithState(K key,State<V> state){
  if (root == null) {
    return false;
  }
  Node<K,V> node;
  Node<K,V> found=null;
  Node<K,V> parent=null;
  Node<K,V> grandparent=null;
  Node<K,V> head=new Node<K,V>(null,null);
  int dir=1;
  head.child[RIGHT]=root;
  node=head;
  while (node.child[dir] != null) {
    int last=dir;
    grandparent=parent;
    parent=node;
    node=node.child[dir];
    int c=cmp.compare(node.key,key);
    dir=c < 0 ? RIGHT : LEFT;
    if (c == 0 && (!state.matchValue || node.value.equals(state.value))) {
      found=node;
    }
    if (!isRed(node) && !isRed(node.child[dir])) {
      if (isRed(node.child[otherChild(dir)])) {
        parent=parent.child[last]=rotateSingle(node,dir);
      }
 else       if (!isRed(node.child[otherChild(dir)])) {
        Node<K,V> sibling=parent.child[otherChild(last)];
        if (sibling != null) {
          if (!isRed(sibling.child[otherChild(last)]) && !isRed(sibling.child[last])) {
            parent.isRed=false;
            sibling.isRed=true;
            node.isRed=true;
          }
 else {
            int dir2=grandparent.child[RIGHT] == parent ? RIGHT : LEFT;
            if (isRed(sibling.child[last])) {
              grandparent.child[dir2]=rotateDouble(parent,last);
            }
 else             if (isRed(sibling.child[otherChild(last)])) {
              grandparent.child[dir2]=rotateSingle(parent,last);
            }
            node.isRed=grandparent.child[dir2].isRed=true;
            grandparent.child[dir2].child[LEFT].isRed=false;
            grandparent.child[dir2].child[RIGHT].isRed=false;
          }
        }
      }
    }
  }
  if (found != null) {
    if (state != null) {
      state.found=true;
      state.value=found.value;
    }
    found.key=node.key;
    found.value=node.value;
    parent.child[parent.child[RIGHT] == node ? RIGHT : LEFT]=node.child[node.child[LEFT] == null ? RIGHT : LEFT];
    size--;
  }
  root=head.child[RIGHT];
  if (root != null) {
    root.isRed=false;
  }
  return state.found;
}

Fixed version (ground truth):
private boolean removeWithState(K key,State<V> state){
  if (root == null) {
    return false;
  }
  Node<K,V> node;
  Node<K,V> found=null;
  Node<K,V> parent=null;
  Node<K,V> grandparent=null;
  Node<K,V> head=new Node<K,V>(null,null);
  int dir=1;
  head.child[RIGHT]=root;
  node=head;
  while (node.child[dir] != null) {
    int last=dir;
    grandparent=parent;
    parent=node;
    node=node.child[dir];
    int c=cmp.compare(node.key,key);
    dir=c < 0 ? RIGHT : LEFT;
    if (c == 0 && (!state.matchValue || node.value.equals(state.value))) {
      found=node;
    }
    if (!isRed(node) && !isRed(node.child[dir])) {
      if (isRed(node.child[otherChild(dir)])) {
        parent=parent.child[last]=rotateSingle(node,dir);
      }
 else       if (!isRed(node.child[otherChild(dir)])) {
        Node<K,V> sibling=parent.child[otherChild(last)];
        if (sibling != null) {
          if (!isRed(sibling.child[otherChild(last)]) && !isRed(sibling.child[last])) {
            parent.isRed=false;
            sibling.isRed=true;
            node.isRed=true;
          }
 else {
            int dir2=grandparent.child[RIGHT] == parent ? RIGHT : LEFT;
            if (isRed(sibling.child[last])) {
              grandparent.child[dir2]=rotateDouble(parent,last);
            }
 else             if (isRed(sibling.child[otherChild(last)])) {
              grandparent.child[dir2]=rotateSingle(parent,last);
            }
            node.isRed=grandparent.child[dir2].isRed=true;
            grandparent.child[dir2].child[LEFT].isRed=false;
            grandparent.child[dir2].child[RIGHT].isRed=false;
          }
        }
      }
    }
  }
  if (found != null) {
    if (state != null) {
      state.found=true;
      state.value=found.value;
    }
    if (node != found) {
      Node<K,V> newNode=new Node<K,V>(node.key,node.value);
      replaceNode(head,found,newNode);
      if (parent == found) {
        parent=newNode;
      }
    }
    parent.child[parent.child[RIGHT] == node ? RIGHT : LEFT]=node.child[node.child[LEFT] == null ? RIGHT : LEFT];
    size--;
  }
  root=head.child[RIGHT];
  if (root != null) {
    root.isRed=false;
  }
  return state.found;
}