Program: 16117
Project: 16117
Buggy source:
int addRowTry(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 + OFFSET_LENGTH) {
    if (entryCount > 1) {
      int x=find(row,false,true,true);
      if (entryCount < 5) {
        return entryCount / 2;
      }
      int third=entryCount / 3;
      return x < third ? third : x >= 2 * third ? 2 * third : x;
    }
    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 + OFFSET_LENGTH) {
      throw Message.throwInternalError();
    }
  }
  written=false;
  int offset=last - rowLength;
  int[] newOffsets=new int[entryCount + 1];
  SearchRow[] newRows=new SearchRow[entryCount + 1];
  int x;
  if (entryCount == 0) {
    x=0;
  }
 else {
    readAllRows();
    x=find(row,false,true,true);
    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);
    }
  }
  entryCount++;
  start+=OFFSET_LENGTH;
  newOffsets[x]=offset;
  newRows[x]=row;
  offsets=newOffsets;
  rows=newRows;
  index.getPageStore().updateRecord(this,true,data);
  return -1;
}

Fixed version (ground truth):
int addRowTry(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 + OFFSET_LENGTH) {
    if (entryCount > 1) {
      int x=find(row,false,true,true);
      if (entryCount < 5) {
        return entryCount / 2;
      }
      int third=entryCount / 3;
      return x < third ? third : x >= 2 * third ? 2 * third : x;
    }
    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 + OFFSET_LENGTH) {
      throw Message.throwInternalError();
    }
  }
  index.getPageStore().logUndo(this,data);
  written=false;
  int offset=last - rowLength;
  int[] newOffsets=new int[entryCount + 1];
  SearchRow[] newRows=new SearchRow[entryCount + 1];
  int x;
  if (entryCount == 0) {
    x=0;
  }
 else {
    readAllRows();
    x=find(row,false,true,true);
    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);
    }
  }
  entryCount++;
  start+=OFFSET_LENGTH;
  newOffsets[x]=offset;
  newRows[x]=row;
  offsets=newOffsets;
  rows=newRows;
  index.getPageStore().updateRecord(this);
  return -1;
}