Program: 16045
Project: 16045
Buggy source:
/** 
 * Add a child at the given position.
 * @param x the position
 * @param childPageId the child
 * @param row the row smaller than the first row of the child and its children
 */
private void addChild(int x,int childPageId,SearchRow row) throws SQLException {
  int rowLength=index.getRowSize(data,row,onlyPosition);
  int pageSize=index.getPageStore().getPageSize();
  int last=entryCount == 0 ? pageSize : offsets[entryCount - 1];
  if (last - rowLength < start + CHILD_OFFSET_PAIR_LENGTH) {
    readAllRows();
    onlyPosition=true;
    int o=pageSize;
    for (int i=0; i < entryCount; i++) {
      o-=index.getRowSize(data,getRow(i),true);
      offsets[i]=o;
    }
    last=entryCount == 0 ? pageSize : offsets[entryCount - 1];
    rowLength=index.getRowSize(data,row,true);
    if (SysProperties.CHECK && last - rowLength < start + CHILD_OFFSET_PAIR_LENGTH) {
      throw Message.throwInternalError();
    }
  }
  int offset=last - rowLength;
  int[] newOffsets=new int[entryCount + 1];
  SearchRow[] newRows=new SearchRow[entryCount + 1];
  int[] newChildPageIds=new int[entryCount + 2];
  if (childPageIds != null) {
    System.arraycopy(childPageIds,0,newChildPageIds,0,x + 1);
  }
  if (entryCount > 0) {
    System.arraycopy(offsets,0,newOffsets,0,x);
    System.arraycopy(rows,0,newRows,0,x);
    if (x < entryCount) {
      for (int j=x; j < entryCount; j++) {
        newOffsets[j + 1]=offsets[j] - rowLength;
      }
      offset=(x == 0 ? pageSize : offsets[x - 1]) - rowLength;
      System.arraycopy(rows,x,newRows,x + 1,entryCount - x);
      System.arraycopy(childPageIds,x + 1,newChildPageIds,x + 2,entryCount - x);
    }
  }
  newOffsets[x]=offset;
  newRows[x]=row;
  newChildPageIds[x + 1]=childPageId;
  start+=CHILD_OFFSET_PAIR_LENGTH;
  offsets=newOffsets;
  rows=newRows;
  childPageIds=newChildPageIds;
  entryCount++;
  written=false;
}

Fixed version (ground truth):
/** 
 * Add a child at the given position.
 * @param x the position
 * @param childPageId the child
 * @param row the row smaller than the first row of the child and its children
 */
private void addChild(int x,int childPageId,SearchRow row) throws SQLException {
  int rowLength=index.getRowSize(data,row,onlyPosition);
  int pageSize=index.getPageStore().getPageSize();
  int last=entryCount == 0 ? pageSize : offsets[entryCount - 1];
  if (last - rowLength < start + CHILD_OFFSET_PAIR_LENGTH) {
    readAllRows();
    onlyPosition=true;
    int o=pageSize;
    for (int i=0; i < entryCount; i++) {
      o-=index.getRowSize(data,getRow(i),true);
      offsets[i]=o;
    }
    last=entryCount == 0 ? pageSize : offsets[entryCount - 1];
    rowLength=index.getRowSize(data,row,true);
    if (SysProperties.CHECK && last - rowLength < start + CHILD_OFFSET_PAIR_LENGTH) {
      throw Message.throwInternalError();
    }
  }
  int offset=last - rowLength;
  int[] newOffsets=new int[entryCount + 1];
  SearchRow[] newRows=new SearchRow[entryCount + 1];
  int[] newChildPageIds=new int[entryCount + 2];
  if (childPageIds != null) {
    System.arraycopy(childPageIds,0,newChildPageIds,0,x + 1);
  }
  if (entryCount > 0) {
    System.arraycopy(offsets,0,newOffsets,0,x);
    System.arraycopy(rows,0,newRows,0,x);
    if (x < entryCount) {
      for (int j=x; j < entryCount; j++) {
        newOffsets[j + 1]=offsets[j] - rowLength;
      }
      offset=(x == 0 ? pageSize : offsets[x - 1]) - rowLength;
      System.arraycopy(rows,x,newRows,x + 1,entryCount - x);
      System.arraycopy(childPageIds,x + 1,newChildPageIds,x + 2,entryCount - x);
    }
  }
  newOffsets[x]=offset;
  newRows[x]=row;
  newChildPageIds[x + 1]=childPageId;
  start+=CHILD_OFFSET_PAIR_LENGTH;
  offsets=newOffsets;
  rows=newRows;
  childPageIds=newChildPageIds;
  if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
    if (rowCount != UNKNOWN_ROWCOUNT) {
      rowCount+=offset;
    }
  }
  entryCount++;
  written=false;
  changeCount=index.getPageStore().getChangeCount();
}