Program: 101067
Project: 101067
Buggy source:
public Node insertChild(char[] letters,int offset,CharSequence tails,TailBuilder tailBuilder){
  TailCharIterator it=new TailCharIterator(tails,tailIndex);
  int count=0;
  while (it.hasNext() && offset < letters.length) {
    if (letters[offset] != it.next())     break;
    offset++;
    count++;
  }
  if (offset == letters.length) {
    if (it.hasNext()) {
      char c=it.next();
      int idx=(it.hasNext()) ? it.getNextIndex() : -1;
      Node newChild=new Node(c,idx,this.terminate,this.children);
      this.tailIndex=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset - count,offset)) : -1;
      this.terminate=true;
      this.children=new Node[]{newChild};
      return this;
    }
 else {
      terminate=true;
      return this;
    }
  }
 else {
    if (it.current() != '\0') {
      int firstOffset=offset - count;
      char n1Fc=it.current();
      int n1Idx=(it.hasNext()) ? it.getNextIndex() : -1;
      Node n1=new Node(n1Fc,n1Idx,terminate,children);
      char n2Fc=letters[offset++];
      int n2Idx=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset,letters.length)) : -1;
      Node n2=new Node(n2Fc,n2Idx,true,null);
      if (count > 0) {
        this.tailIndex=tailBuilder.insert(letters,firstOffset,count);
      }
 else {
        this.tailIndex=-1;
      }
      this.terminate=false;
      if (n1.getFirstLetter() < n2.getFirstLetter()) {
        this.children=new Node[]{n1,n2};
      }
 else {
        this.children=new Node[]{n2,n1};
      }
      return this;
    }
 else {
      char fc=letters[offset++];
      if (children == null) {
        int idx=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset,letters.length)) : -1;
        this.children=new Node[]{new Node(fc,idx,true,null)};
      }
 else {
        Pair<Node,Integer> ret=findNode(fc);
        if (ret.getFirst() != null) {
          Node child=ret.getFirst().insertChild(letters,offset,tails,tailBuilder);
          children[ret.getSecond()]=child;
        }
 else {
          int idx=(offset < letters.length) ? tailBuilder.insert(letters,offset,letters.length - offset) : -1;
          addChild(ret.getSecond(),new Node(fc,idx,true,null));
        }
      }
      return this;
    }
  }
}

Fixed version (ground truth):
public Node insertChild(char[] letters,int offset,CharSequence tails,TailBuilder tailBuilder){
  TailCharIterator it=new TailCharIterator(tails,tailIndex);
  int count=0;
  boolean matchComplete=true;
  while (it.hasNext() && offset < letters.length) {
    if (letters[offset] != it.next()) {
      matchComplete=false;
      break;
    }
    offset++;
    count++;
  }
  if (offset == letters.length) {
    if (it.hasNext()) {
      char c=it.next();
      int idx=it.getNextIndex();
      if (!it.hasNext()) {
        idx=-1;
      }
      Node newChild=new Node(c,idx,this.terminate,this.children);
      this.tailIndex=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset - count,offset)) : -1;
      this.terminate=true;
      this.children=new Node[]{newChild};
      return this;
    }
 else {
      terminate=true;
      return this;
    }
  }
 else {
    if (!matchComplete) {
      int firstOffset=offset - count;
      char n1Fc=it.current();
      int n1Idx=it.getNextIndex();
      if (!it.hasNext()) {
        n1Idx=-1;
      }
      Node n1=new Node(n1Fc,n1Idx,terminate,children);
      char n2Fc=letters[offset++];
      int n2Idx=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset,letters.length)) : -1;
      Node n2=new Node(n2Fc,n2Idx,true,null);
      if (count > 0) {
        this.tailIndex=tailBuilder.insert(letters,firstOffset,count);
      }
 else {
        this.tailIndex=-1;
      }
      this.terminate=false;
      if (n1.getFirstLetter() < n2.getFirstLetter()) {
        this.children=new Node[]{n1,n2};
      }
 else {
        this.children=new Node[]{n2,n1};
      }
      return this;
    }
 else {
      char fc=letters[offset++];
      if (children == null) {
        int idx=(offset < letters.length) ? tailBuilder.insert(Arrays.copyOfRange(letters,offset,letters.length)) : -1;
        this.children=new Node[]{new Node(fc,idx,true,null)};
      }
 else {
        Pair<Node,Integer> ret=findNode(fc);
        Node child=ret.getFirst();
        if (child != null) {
          Node newChild=child.insertChild(letters,offset,tails,tailBuilder);
          children[ret.getSecond()]=newChild;
        }
 else {
          int idx=(offset < letters.length) ? tailBuilder.insert(letters,offset,letters.length - offset) : -1;
          addChild(ret.getSecond(),new Node(fc,idx,true,null));
        }
      }
      return this;
    }
  }
}