nus-yam/ex-repair huggingface dataset:
Program: 16071
Project: 16071
Buggy source:
private void removeMetaIndex(Index index,Session session) throws SQLException {
  Row row=metaIndex.getRow(session,index.getId() + 1);
  metaIndex.remove(session,row);
}

Fixed version (ground truth):
private void removeMetaIndex(Index index,Session session) throws SQLException {
  int key=index.getId() + 1;
  Row row=metaIndex.getRow(session,key);
  if (row.getKey() != key) {
    Message.throwInternalError();
  }
  metaIndex.remove(session,row);
}
Program: 16072
Project: 16072
Buggy source:
/** 
 * Run recovery.
 */
private void recover() throws SQLException {
  trace.debug("String_Node_Str");
  recoveryRunning=true;
  log.recover(PageLog.RECOVERY_STAGE_UNDO);
  if (reservedPages != null) {
    for (    int r : reservedPages.keySet()) {
      if (trace.isDebugEnabled()) {
        trace.debug("String_Node_Str" + r);
      }
      allocatePage(r);
    }
  }
  log.recover(PageLog.RECOVERY_STAGE_ALLOCATE);
  openMetaIndex();
  readMetaData();
  log.recover(PageLog.RECOVERY_STAGE_REDO);
  boolean setReadOnly=false;
  if (!database.isReadOnly()) {
    if (log.getInDoubtTransactions().size() == 0) {
      log.recoverEnd();
      switchLog();
    }
 else {
      setReadOnly=true;
    }
  }
  PageDataIndex systemTable=(PageDataIndex)metaObjects.get(0);
  if (systemTable == null) {
    systemTableHeadPos=Index.EMPTY_HEAD;
  }
 else {
    systemTableHeadPos=systemTable.getHeadPos();
  }
  for (  Index openIndex : metaObjects.values()) {
    if (openIndex.getTable().isTemporary()) {
      openIndex.remove(systemSession);
      this.removeMetaIndex(openIndex,systemSession);
    }
    openIndex.close(systemSession);
  }
  recoveryRunning=false;
  reservedPages=null;
  writeBack();
  cache.clear();
  freeLists.clear();
  if (setReadOnly) {
    database.setReadOnly(true);
  }
  trace.debug("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Run recovery.
 */
private void recover() throws SQLException {
  trace.debug("String_Node_Str");
  recoveryRunning=true;
  log.recover(PageLog.RECOVERY_STAGE_UNDO);
  if (reservedPages != null) {
    for (    int r : reservedPages.keySet()) {
      if (trace.isDebugEnabled()) {
        trace.debug("String_Node_Str" + r);
      }
      allocatePage(r);
    }
  }
  log.recover(PageLog.RECOVERY_STAGE_ALLOCATE);
  openMetaIndex();
  readMetaData();
  log.recover(PageLog.RECOVERY_STAGE_REDO);
  boolean setReadOnly=false;
  if (!database.isReadOnly()) {
    if (log.getInDoubtTransactions().size() == 0) {
      log.recoverEnd();
      switchLog();
    }
 else {
      setReadOnly=true;
    }
  }
  PageDataIndex systemTable=(PageDataIndex)metaObjects.get(0);
  if (systemTable == null) {
    systemTableHeadPos=Index.EMPTY_HEAD;
  }
 else {
    systemTableHeadPos=systemTable.getHeadPos();
  }
  for (  Index openIndex : metaObjects.values()) {
    if (openIndex.getTable().isTemporary()) {
      openIndex.truncate(systemSession);
      openIndex.remove(systemSession);
      removeMetaIndex(openIndex,systemSession);
    }
    openIndex.close(systemSession);
  }
  recoveryRunning=false;
  reservedPages=null;
  writeBack();
  cache.clear();
  freeLists.clear();
  if (setReadOnly) {
    database.setReadOnly(true);
  }
  trace.debug("String_Node_Str");
}
Program: 16073
Project: 16073
Buggy source:
private void removeAllRows() throws SQLException {
  PageData root=getPage(rootPageId,0);
  root.freeChildren();
  root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
  lastKey=0;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageData root=getPage(rootPageId,0);
  store.logUndo(root,root.data);
  root.freeChildren();
  root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
  lastKey=0;
}
Program: 16074
Project: 16074
Buggy source:
/** 
 * Add a page to the free list.
 * @param page the page
 * @param undo if the undo record must have been written
 */
public void free(int pageId,boolean undo) throws SQLException {
  if (trace.isDebugEnabled()) {
  }
synchronized (database) {
    cache.remove(pageId);
    if (SysProperties.CHECK && !recoveryRunning && undo) {
      log.addUndo(pageId,null);
    }
    freePage(pageId);
    if (recoveryRunning) {
      writePage(pageId,createData());
    }
  }
}

Fixed version (ground truth):
/** 
 * Add a page to the free list.
 * @param pageId the page id
 * @param undo if the undo record must have been written
 */
public void free(int pageId,boolean undo) throws SQLException {
  if (trace.isDebugEnabled()) {
  }
synchronized (database) {
    cache.remove(pageId);
    if (SysProperties.CHECK && !recoveryRunning && undo) {
      log.addUndo(pageId,null);
    }
    freePage(pageId);
    if (recoveryRunning) {
      writePage(pageId,createData());
    }
  }
}
Program: 16075
Project: 16075
Buggy source:
/** 
 * Add an object to this schema.
 * @param obj the object to add
 */
public void add(SchemaObject obj){
  if (SysProperties.CHECK && obj.getSchema() != this) {
    Message.throwInternalError("String_Node_Str");
  }
  String name=obj.getName();
  HashMap<String,SchemaObject> map=getMap(obj.getType());
  if (SysProperties.CHECK && map.get(name) != null) {
    Message.throwInternalError("String_Node_Str");
  }
  map.put(name,obj);
  freeUniqueName(name);
}

Fixed version (ground truth):
/** 
 * Add an object to this schema.
 * @param obj the object to add
 */
public void add(SchemaObject obj){
  if (SysProperties.CHECK && obj.getSchema() != this) {
    Message.throwInternalError("String_Node_Str");
  }
  String name=obj.getName();
  HashMap<String,SchemaObject> map=getMap(obj.getType());
  if (SysProperties.CHECK && map.get(name) != null) {
    Message.throwInternalError("String_Node_Str" + name);
  }
  map.put(name,obj);
  freeUniqueName(name);
}
Program: 16077
Project: 16077
Buggy source:
public void add(Session session,Row row) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + row.getKey());
  }
  SearchRow newRow=getSearchRow(row);
  while (true) {
    PageBtree root=getPage(rootPageId);
    int splitPoint=root.addRowTry(newRow);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    SearchRow pivot=root.getRow(splitPoint - 1);
    store.logUndo(root,root.data);
    PageBtree page1=root;
    PageBtree page2=root.split(splitPoint);
    store.logUndo(page2,null);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageBtreeNode newRoot=PageBtreeNode.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(newRoot,null);
    newRoot.init(page1,pivot,page2);
    store.updateRecord(page1);
    store.updateRecord(page2);
    store.updateRecord(newRoot);
    root=newRoot;
  }
  rowCount++;
}

Fixed version (ground truth):
public void add(Session session,Row row) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + row.getKey());
  }
  SearchRow newRow=getSearchRow(row);
  while (true) {
    PageBtree root=getPage(rootPageId);
    int splitPoint=root.addRowTry(newRow);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    SearchRow pivot=root.getRow(splitPoint - 1);
    store.logUndo(root,root.data);
    PageBtree page1=root;
    PageBtree page2=root.split(splitPoint);
    store.logUndo(page2,null);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageBtreeNode newRoot=PageBtreeNode.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(newRoot,null);
    newRoot.init(page1,pivot,page2);
    store.update(page1);
    store.update(page2);
    store.update(newRoot);
    root=newRoot;
  }
  rowCount++;
}
Program: 16078
Project: 16078
Buggy source:
public PageBtreeIndex(TableData table,int id,String indexName,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,indexName,columns,indexType);
  tableData=table;
  if (!database.isPersistent() || id < 0) {
    throw Message.throwInternalError("String_Node_Str" + indexName);
  }
  this.store=database.getPageStore();
  store.addIndex(this);
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    needRebuild=true;
    store.addMeta(this,session);
    PageBtreeLeaf root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(root,null);
    store.updateRecord(root);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageBtree root=getPage(rootPageId);
    rowCount=root.getRowCount();
    if (rowCount == 0 && store.isRecoveryRunning()) {
      needRebuild=true;
    }
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
}

Fixed version (ground truth):
public PageBtreeIndex(TableData table,int id,String indexName,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,indexName,columns,indexType);
  tableData=table;
  if (!database.isPersistent() || id < 0) {
    throw Message.throwInternalError("String_Node_Str" + indexName);
  }
  this.store=database.getPageStore();
  store.addIndex(this);
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    needRebuild=true;
    store.addMeta(this,session);
    PageBtreeLeaf root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(root,null);
    store.update(root);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageBtree root=getPage(rootPageId);
    rowCount=root.getRowCount();
    if (rowCount == 0 && store.isRecoveryRunning()) {
      needRebuild=true;
    }
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
}
Program: 16079
Project: 16079
Buggy source:
/** 
 * Read the given page.
 * @param id the page id
 * @return the page
 */
PageBtree getPage(int id) throws SQLException {
  PageBtree p=(PageBtree)store.getPage(id);
  if (p == null) {
    PageBtreeLeaf empty=PageBtreeLeaf.create(this,id,PageBtree.ROOT);
    store.logUndo(empty,null);
    store.updateRecord(empty);
    return empty;
  }
  return p;
}

Fixed version (ground truth):
/** 
 * Read the given page.
 * @param id the page id
 * @return the page
 */
PageBtree getPage(int id) throws SQLException {
  PageBtree p=(PageBtree)store.getPage(id);
  if (p == null) {
    PageBtreeLeaf empty=PageBtreeLeaf.create(this,id,PageBtree.ROOT);
    store.logUndo(empty,null);
    store.update(empty);
    return empty;
  }
  return p;
}
Program: 16080
Project: 16080
Buggy source:
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str");
  }
  removeAllRows();
  store.freePage(rootPageId,false,null);
  store.removeMeta(this,session);
}

Fixed version (ground truth):
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str");
  }
  removeAllRows();
  store.free(rootPageId,true);
  store.removeMeta(this,session);
}
Program: 16081
Project: 16081
Buggy source:
private void removeAllRows() throws SQLException {
  PageBtree root=getPage(rootPageId);
  store.logUndo(root,root.data);
  root.freeChildren();
  root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
  store.removeRecord(rootPageId);
  store.updateRecord(root);
  rowCount=0;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageBtree root=getPage(rootPageId);
  store.logUndo(root,root.data);
  root.freeChildren();
  root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
}
Program: 16082
Project: 16082
Buggy source:
SearchRow remove(SearchRow row) throws SQLException {
  int at=find(row,false,false,true);
  SearchRow delete=getRow(at);
  if (index.compareRows(row,delete) != 0 || delete.getKey() != row.getKey()) {
    throw Message.getSQLException(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,index.getSQL() + "String_Node_Str" + row);
  }
  if (entryCount == 1) {
    return row;
  }
  index.getPageStore().logUndo(this,data);
  removeRow(at);
  index.getPageStore().updateRecord(this);
  if (at == entryCount) {
    return getRow(at - 1);
  }
  return null;
}

Fixed version (ground truth):
SearchRow remove(SearchRow row) throws SQLException {
  int at=find(row,false,false,true);
  SearchRow delete=getRow(at);
  if (index.compareRows(row,delete) != 0 || delete.getKey() != row.getKey()) {
    throw Message.getSQLException(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,index.getSQL() + "String_Node_Str" + row);
  }
  index.getPageStore().logUndo(this,data);
  if (entryCount == 1) {
    return row;
  }
  removeRow(at);
  index.getPageStore().update(this);
  if (at == entryCount) {
    return getRow(at - 1);
  }
  return null;
}
Program: 16084
Project: 16084
Buggy source:
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  readAllRows();
  PageBtreeLeaf p2=PageBtreeLeaf.create(index,newPos,parentPageId);
  store.logUndo(this,data);
  store.logUndo(p2,null);
  p2.rows=rows;
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.onlyPosition=onlyPosition;
  p2.parentPageId=parentPageId;
  p2.start=start;
  store.updateRecord(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageBtreeNode p=(PageBtreeNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  store.freePage(getPos(),true,data);
}

Fixed version (ground truth):
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  readAllRows();
  PageBtreeLeaf p2=PageBtreeLeaf.create(index,newPos,parentPageId);
  store.logUndo(this,data);
  store.logUndo(p2,null);
  p2.rows=rows;
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.onlyPosition=onlyPosition;
  p2.parentPageId=parentPageId;
  p2.start=start;
  store.update(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageBtreeNode p=(PageBtreeNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  store.free(getPos(),true);
}
Program: 16085
Project: 16085
Buggy source:
SearchRow remove(SearchRow row) throws SQLException {
  int at=find(row,false,false,true);
  PageBtree page=index.getPage(childPageIds[at]);
  SearchRow last=page.remove(row);
  index.getPageStore().logUndo(this,data);
  updateRowCount(-1);
  written=false;
  if (last == null) {
    return null;
  }
 else   if (last == row) {
    index.getPageStore().freePage(page.getPos(),true,page.data);
    if (entryCount < 1) {
      return row;
    }
    if (at == entryCount) {
      last=getRow(at - 1);
    }
 else {
      last=null;
    }
    removeChild(at);
    index.getPageStore().updateRecord(this);
    return last;
  }
  if (at == entryCount) {
    return last;
  }
  int child=childPageIds[at];
  removeChild(at);
  addChild(at,child,last);
  int temp=childPageIds[at];
  childPageIds[at]=childPageIds[at + 1];
  childPageIds[at + 1]=temp;
  index.getPageStore().updateRecord(this);
  return null;
}

Fixed version (ground truth):
SearchRow remove(SearchRow row) throws SQLException {
  int at=find(row,false,false,true);
  PageBtree page=index.getPage(childPageIds[at]);
  SearchRow last=page.remove(row);
  index.getPageStore().logUndo(this,data);
  updateRowCount(-1);
  written=false;
  if (last == null) {
    return null;
  }
 else   if (last == row) {
    index.getPageStore().free(page.getPos(),true);
    if (entryCount < 1) {
      return row;
    }
    if (at == entryCount) {
      last=getRow(at - 1);
    }
 else {
      last=null;
    }
    removeChild(at);
    index.getPageStore().update(this);
    return last;
  }
  if (at == entryCount) {
    return last;
  }
  int child=childPageIds[at];
  removeChild(at);
  addChild(at,child,last);
  int temp=childPageIds[at];
  childPageIds[at]=childPageIds[at + 1];
  childPageIds[at + 1]=temp;
  index.getPageStore().update(this);
  return null;
}
Program: 16086
Project: 16086
Buggy source:
int addRowTry(SearchRow row) throws SQLException {
  while (true) {
    int x=find(row,false,true,true);
    PageBtree page=index.getPage(childPageIds[x]);
    int splitPoint=page.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    SearchRow pivot=page.getRow(splitPoint - 1);
    index.getPageStore().logUndo(this,data);
    int splitPoint2=addChildTry(pivot);
    if (splitPoint2 != -1) {
      return splitPoint2;
    }
    PageBtree page2=page.split(splitPoint);
    readAllRows();
    addChild(x,page2.getPos(),pivot);
    index.getPageStore().updateRecord(page);
    index.getPageStore().updateRecord(page2);
    index.getPageStore().updateRecord(this);
  }
  updateRowCount(1);
  written=false;
  return -1;
}

Fixed version (ground truth):
int addRowTry(SearchRow row) throws SQLException {
  while (true) {
    int x=find(row,false,true,true);
    PageBtree page=index.getPage(childPageIds[x]);
    int splitPoint=page.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    SearchRow pivot=page.getRow(splitPoint - 1);
    index.getPageStore().logUndo(this,data);
    int splitPoint2=addChildTry(pivot);
    if (splitPoint2 != -1) {
      return splitPoint2;
    }
    PageBtree page2=page.split(splitPoint);
    readAllRows();
    addChild(x,page2.getPos(),pivot);
    index.getPageStore().update(page);
    index.getPageStore().update(page2);
    index.getPageStore().update(this);
  }
  updateRowCount(1);
  written=false;
  return -1;
}
Program: 16087
Project: 16087
Buggy source:
/** 
 * One of the children has moved to a new page.
 * @param oldPos the old position
 * @param newPos the new position
 */
void moveChild(int oldPos,int newPos) throws SQLException {
  for (int i=0; i < childPageIds.length; i++) {
    if (childPageIds[i] == oldPos) {
      index.getPageStore().logUndo(this,data);
      written=false;
      childPageIds[i]=newPos;
      index.getPageStore().updateRecord(this);
      return;
    }
  }
  throw Message.throwInternalError();
}

Fixed version (ground truth):
/** 
 * One of the children has moved to a new page.
 * @param oldPos the old position
 * @param newPos the new position
 */
void moveChild(int oldPos,int newPos) throws SQLException {
  for (int i=0; i < childPageIds.length; i++) {
    if (childPageIds[i] == oldPos) {
      index.getPageStore().logUndo(this,data);
      written=false;
      childPageIds[i]=newPos;
      index.getPageStore().update(this);
      return;
    }
  }
  throw Message.throwInternalError();
}
Program: 16088
Project: 16088
Buggy source:
void freeChildren() throws SQLException {
  for (int i=0; i <= entryCount; i++) {
    int childPageId=childPageIds[i];
    PageBtree child=index.getPage(childPageId);
    index.getPageStore().freePage(childPageId,false,null);
    child.freeChildren();
  }
}

Fixed version (ground truth):
void freeChildren() throws SQLException {
  for (int i=0; i <= entryCount; i++) {
    int childPageId=childPageIds[i];
    PageBtree child=index.getPage(childPageId);
    index.getPageStore().free(childPageId,false);
    child.freeChildren();
  }
}
Program: 16089
Project: 16089
Buggy source:
protected void remapChildren() throws SQLException {
  for (  int child : childPageIds) {
    PageBtree p=index.getPage(child);
    p.setParentPageId(getPos());
    index.getPageStore().updateRecord(p);
  }
}

Fixed version (ground truth):
protected void remapChildren() throws SQLException {
  for (  int child : childPageIds) {
    PageBtree p=index.getPage(child);
    p.setParentPageId(getPos());
    index.getPageStore().update(p);
  }
}
Program: 16090
Project: 16090
Buggy source:
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageBtreeNode p2=PageBtreeNode.create(index,newPos,parentPageId);
  readAllRows();
  p2.childPageIds=childPageIds;
  p2.rows=rows;
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.onlyPosition=onlyPosition;
  p2.parentPageId=parentPageId;
  p2.start=start;
  store.updateRecord(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageBtreeNode p=(PageBtreeNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  for (int i=0; i < childPageIds.length; i++) {
    PageBtree p=(PageBtree)store.getPage(childPageIds[i]);
    p.setParentPageId(newPos);
    store.updateRecord(p);
  }
  store.freePage(getPos(),true,data);
}

Fixed version (ground truth):
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageBtreeNode p2=PageBtreeNode.create(index,newPos,parentPageId);
  readAllRows();
  p2.childPageIds=childPageIds;
  p2.rows=rows;
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.onlyPosition=onlyPosition;
  p2.parentPageId=parentPageId;
  p2.start=start;
  store.update(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageBtreeNode p=(PageBtreeNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  for (int i=0; i < childPageIds.length; i++) {
    PageBtree p=(PageBtree)store.getPage(childPageIds[i]);
    p.setParentPageId(newPos);
    store.update(p);
  }
  store.free(getPos(),true);
}
Program: 16091
Project: 16091
Buggy source:
/** 
 * Read the given page.
 * @param id the page id
 * @param parent the parent, or -1 if unknown
 * @return the page
 */
PageData getPage(int id,int parent) throws SQLException {
  PageData p=(PageData)store.getPage(id);
  if (p == null) {
    PageDataLeaf empty=PageDataLeaf.create(this,id,parent);
    store.logUndo(empty,null);
    store.updateRecord(empty);
    return empty;
  }
  if (p.index.rootPageId != rootPageId) {
    throw Message.throwInternalError("String_Node_Str" + p.index.getName() + "String_Node_Str"+ p.index.rootPageId+ "String_Node_Str"+ getName()+ "String_Node_Str"+ rootPageId);
  }
  if (parent != -1) {
    if (p.getParentPageId() != parent) {
      throw Message.throwInternalError(p + "String_Node_Str" + p.getParentPageId()+ "String_Node_Str"+ parent);
    }
  }
  return p;
}

Fixed version (ground truth):
/** 
 * Read the given page.
 * @param id the page id
 * @param parent the parent, or -1 if unknown
 * @return the page
 */
PageData getPage(int id,int parent) throws SQLException {
  PageData p=(PageData)store.getPage(id);
  if (p == null) {
    PageDataLeaf empty=PageDataLeaf.create(this,id,parent);
    store.logUndo(empty,null);
    store.update(empty);
    return empty;
  }
  if (p.index.rootPageId != rootPageId) {
    throw Message.throwInternalError("String_Node_Str" + p.index.getName() + "String_Node_Str"+ p.index.rootPageId+ "String_Node_Str"+ getName()+ "String_Node_Str"+ rootPageId);
  }
  if (parent != -1) {
    if (p.getParentPageId() != parent) {
      throw Message.throwInternalError(p + "String_Node_Str" + p.getParentPageId()+ "String_Node_Str"+ parent);
    }
  }
  return p;
}
Program: 16092
Project: 16092
Buggy source:
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str");
  }
  removeAllRows();
  store.freePage(rootPageId,false,null);
  store.removeMeta(this,session);
}

Fixed version (ground truth):
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str");
  }
  removeAllRows();
  store.free(rootPageId,true);
  store.removeMeta(this,session);
}
Program: 16093
Project: 16093
Buggy source:
private void removeAllRows() throws SQLException {
  PageData root=getPage(rootPageId,0);
  root.freeChildren();
  root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
  store.removeRecord(rootPageId);
  store.updateRecord(root);
  rowCount=0;
  lastKey=0;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageData root=getPage(rootPageId,0);
  root.freeChildren();
  root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
  lastKey=0;
}
Program: 16094
Project: 16094
Buggy source:
public PageDataIndex(TableData table,int id,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,table.getName() + "String_Node_Str",columns,indexType);
  if (database.isMultiVersion()) {
    sessionRowCount=New.hashMap();
    isMultiVersion=true;
  }
  tableData=table;
  this.store=database.getPageStore();
  store.addIndex(this);
  if (!database.isPersistent()) {
    throw Message.throwInternalError(table.getName());
  }
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    store.addMeta(this,session);
    PageDataLeaf root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
    store.updateRecord(root);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageData root=getPage(rootPageId,0);
    lastKey=root.getLastKey();
    rowCount=root.getRowCount();
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
  table.setRowCount(rowCount);
  fastDuplicateKeyException=super.getDuplicateKeyException();
  memorySizePerPage=store.getPageSize();
  int estimatedRowsPerPage=store.getPageSize() / ((1 + columns.length) * 8);
  memorySizePerPage+=estimatedRowsPerPage * 64;
}

Fixed version (ground truth):
public PageDataIndex(TableData table,int id,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,table.getName() + "String_Node_Str",columns,indexType);
  if (database.isMultiVersion()) {
    sessionRowCount=New.hashMap();
    isMultiVersion=true;
  }
  tableData=table;
  this.store=database.getPageStore();
  store.addIndex(this);
  if (!database.isPersistent()) {
    throw Message.throwInternalError(table.getName());
  }
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    store.addMeta(this,session);
    PageDataLeaf root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
    store.update(root);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageData root=getPage(rootPageId,0);
    lastKey=root.getLastKey();
    rowCount=root.getRowCount();
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
  table.setRowCount(rowCount);
  fastDuplicateKeyException=super.getDuplicateKeyException();
  memorySizePerPage=store.getPageSize();
  int estimatedRowsPerPage=store.getPageSize() / ((1 + columns.length) * 8);
  memorySizePerPage+=estimatedRowsPerPage * 64;
}
Program: 16095
Project: 16095
Buggy source:
private void addTry(Session session,Row row) throws SQLException {
  while (true) {
    PageData root=getPage(rootPageId,0);
    int splitPoint=root.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    long pivot=splitPoint == 0 ? row.getKey() : root.getKey(splitPoint - 1);
    PageData page1=root;
    PageData page2=root.split(splitPoint);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageDataNode newRoot=PageDataNode.create(this,rootPageId,PageData.ROOT);
    newRoot.init(page1,pivot,page2);
    store.updateRecord(page1);
    store.updateRecord(page2);
    store.updateRecord(newRoot);
    root=newRoot;
  }
  row.setDeleted(false);
  if (database.isMultiVersion()) {
    if (delta == null) {
      delta=New.hashSet();
    }
    boolean wasDeleted=delta.remove(row);
    if (!wasDeleted) {
      delta.add(row);
    }
    incrementRowCount(session.getId(),1);
  }
  invalidateRowCount();
  rowCount++;
  store.logAddOrRemoveRow(session,tableData.getId(),row,true);
}

Fixed version (ground truth):
private void addTry(Session session,Row row) throws SQLException {
  while (true) {
    PageData root=getPage(rootPageId,0);
    int splitPoint=root.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    long pivot=splitPoint == 0 ? row.getKey() : root.getKey(splitPoint - 1);
    PageData page1=root;
    PageData page2=root.split(splitPoint);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageDataNode newRoot=PageDataNode.create(this,rootPageId,PageData.ROOT);
    newRoot.init(page1,pivot,page2);
    store.update(page1);
    store.update(page2);
    store.update(newRoot);
    root=newRoot;
  }
  row.setDeleted(false);
  if (database.isMultiVersion()) {
    if (delta == null) {
      delta=New.hashSet();
    }
    boolean wasDeleted=delta.remove(row);
    if (!wasDeleted) {
      delta.add(row);
    }
    incrementRowCount(session.getId(),1);
  }
  invalidateRowCount();
  rowCount++;
  store.logAddOrRemoveRow(session,tableData.getId(),row,true);
}
Program: 16096
Project: 16096
Buggy source:
boolean remove(long key) throws SQLException {
  int i=find(key);
  if (keys[i] != key) {
    throw Message.getSQLException(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,index.getSQL() + "String_Node_Str" + key);
  }
  index.getPageStore().logUndo(this,data);
  if (entryCount == 1) {
    freeChildren();
    return true;
  }
  removeRow(i);
  index.getPageStore().updateRecord(this);
  return false;
}

Fixed version (ground truth):
boolean remove(long key) throws SQLException {
  int i=find(key);
  if (keys[i] != key) {
    throw Message.getSQLException(ErrorCode.ROW_NOT_FOUND_WHEN_DELETING_1,index.getSQL() + "String_Node_Str" + key);
  }
  index.getPageStore().logUndo(this,data);
  if (entryCount == 1) {
    freeChildren();
    return true;
  }
  removeRow(i);
  index.getPageStore().update(this);
  return false;
}
Program: 16098
Project: 16098
Buggy source:
void freeChildren() throws SQLException {
  if (firstOverflowPageId != 0) {
    PageStore store=index.getPageStore();
    int next=firstOverflowPageId;
    do {
      PageDataOverflow page=index.getPageOverflow(next);
      store.freePage(next,false,null);
      next=page.getNextOverflow();
    }
 while (next != 0);
  }
}

Fixed version (ground truth):
void freeChildren() throws SQLException {
  if (firstOverflowPageId != 0) {
    PageStore store=index.getPageStore();
    int next=firstOverflowPageId;
    do {
      PageDataOverflow page=index.getPageOverflow(next);
      store.free(next,false);
      next=page.getNextOverflow();
    }
 while (next != 0);
  }
}
Program: 16099
Project: 16099
Buggy source:
void setOverflow(int overflow) throws SQLException {
  index.getPageStore().logUndo(this,data);
  firstOverflowPageId=overflow;
  if (written) {
    writeHead();
    data.writeInt(firstOverflowPageId);
  }
  index.getPageStore().updateRecord(this);
}

Fixed version (ground truth):
void setOverflow(int overflow) throws SQLException {
  index.getPageStore().logUndo(this,data);
  firstOverflowPageId=overflow;
  if (written) {
    writeHead();
    data.writeInt(firstOverflowPageId);
  }
  index.getPageStore().update(this);
}
Program: 16100
Project: 16100
Buggy source:
protected void remapChildren() throws SQLException {
  if (firstOverflowPageId == 0) {
    return;
  }
  PageDataOverflow overflow=index.getPageOverflow(firstOverflowPageId);
  overflow.setParentPageId(getPos());
  index.getPageStore().updateRecord(overflow);
}

Fixed version (ground truth):
protected void remapChildren() throws SQLException {
  if (firstOverflowPageId == 0) {
    return;
  }
  PageDataOverflow overflow=index.getPageOverflow(firstOverflowPageId);
  overflow.setParentPageId(getPos());
  index.getPageStore().update(overflow);
}
Program: 16101
Project: 16101
Buggy source:
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageDataLeaf p2=PageDataLeaf.create(index,newPos,parentPageId);
  readAllRows();
  p2.keys=keys;
  p2.overflowRowSize=overflowRowSize;
  p2.firstOverflowPageId=firstOverflowPageId;
  p2.rowRef=rowRef;
  p2.rows=rows;
  if (firstOverflowPageId != 0) {
    p2.rows[0]=getRowAt(0);
  }
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.parentPageId=parentPageId;
  p2.start=start;
  p2.remapChildren();
  p2.write();
  p2.data.truncate(index.getPageStore().getPageSize());
  store.updateRecord(p2);
  store.freePage(getPos(),true,data);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageDataNode p=(PageDataNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
}

Fixed version (ground truth):
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageDataLeaf p2=PageDataLeaf.create(index,newPos,parentPageId);
  readAllRows();
  p2.keys=keys;
  p2.overflowRowSize=overflowRowSize;
  p2.firstOverflowPageId=firstOverflowPageId;
  p2.rowRef=rowRef;
  p2.rows=rows;
  if (firstOverflowPageId != 0) {
    p2.rows[0]=getRowAt(0);
  }
  p2.entryCount=entryCount;
  p2.offsets=offsets;
  p2.parentPageId=parentPageId;
  p2.start=start;
  p2.remapChildren();
  p2.write();
  p2.data.truncate(index.getPageStore().getPageSize());
  store.update(p2);
  store.free(getPos(),true);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageDataNode p=(PageDataNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
}
Program: 16102
Project: 16102
Buggy source:
boolean remove(long key) throws SQLException {
  int at=find(key);
  PageData page=index.getPage(childPageIds[at],getPos());
  boolean empty=page.remove(key);
  updateRowCount(-1);
  if (!empty) {
    return false;
  }
  index.getPageStore().freePage(page.getPos(),true,page.data);
  if (entryCount < 1) {
    return true;
  }
  removeChild(at);
  index.getPageStore().updateRecord(this);
  return false;
}

Fixed version (ground truth):
boolean remove(long key) throws SQLException {
  int at=find(key);
  PageData page=index.getPage(childPageIds[at],getPos());
  boolean empty=page.remove(key);
  index.getPageStore().logUndo(this,data);
  updateRowCount(-1);
  if (!empty) {
    return false;
  }
  index.getPageStore().free(page.getPos(),true);
  if (entryCount < 1) {
    return true;
  }
  removeChild(at);
  index.getPageStore().update(this);
  return false;
}
Program: 16103
Project: 16103
Buggy source:
int addRowTry(Row row) throws SQLException {
  index.getPageStore().logUndo(this,data);
  int keyOffsetPairLen=4 + data.getVarLongLen(row.getKey());
  while (true) {
    int x=find(row.getKey());
    PageData page=index.getPage(childPageIds[x],getPos());
    int splitPoint=page.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    if (length + keyOffsetPairLen > index.getPageStore().getPageSize()) {
      return entryCount / 2;
    }
    long pivot=splitPoint == 0 ? row.getKey() : page.getKey(splitPoint - 1);
    PageData page2=page.split(splitPoint);
    index.getPageStore().updateRecord(page);
    index.getPageStore().updateRecord(page2);
    addChild(x,page2.getPos(),pivot);
    index.getPageStore().updateRecord(this);
  }
  updateRowCount(1);
  return -1;
}

Fixed version (ground truth):
int addRowTry(Row row) throws SQLException {
  index.getPageStore().logUndo(this,data);
  int keyOffsetPairLen=4 + data.getVarLongLen(row.getKey());
  while (true) {
    int x=find(row.getKey());
    PageData page=index.getPage(childPageIds[x],getPos());
    int splitPoint=page.addRowTry(row);
    if (splitPoint == -1) {
      break;
    }
    if (length + keyOffsetPairLen > index.getPageStore().getPageSize()) {
      return entryCount / 2;
    }
    long pivot=splitPoint == 0 ? row.getKey() : page.getKey(splitPoint - 1);
    PageData page2=page.split(splitPoint);
    index.getPageStore().update(page);
    index.getPageStore().update(page2);
    addChild(x,page2.getPos(),pivot);
    index.getPageStore().update(this);
  }
  updateRowCount(1);
  return -1;
}
Program: 16104
Project: 16104
Buggy source:
private void updateRowCount(int offset) throws SQLException {
  if (rowCount != UNKNOWN_ROWCOUNT) {
    rowCount+=offset;
  }
  if (rowCountStored != UNKNOWN_ROWCOUNT) {
    rowCountStored=UNKNOWN_ROWCOUNT;
    index.getPageStore().logUndo(this,data);
    if (written) {
      writeHead();
    }
    index.getPageStore().updateRecord(this);
  }
}

Fixed version (ground truth):
private void updateRowCount(int offset) throws SQLException {
  if (rowCount != UNKNOWN_ROWCOUNT) {
    rowCount+=offset;
  }
  if (rowCountStored != UNKNOWN_ROWCOUNT) {
    rowCountStored=UNKNOWN_ROWCOUNT;
    index.getPageStore().logUndo(this,data);
    if (written) {
      writeHead();
    }
    index.getPageStore().update(this);
  }
}
Program: 16105
Project: 16105
Buggy source:
/** 
 * One of the children has moved to another page.
 * @param oldPos the old position
 * @param newPos the new position
 */
void moveChild(int oldPos,int newPos) throws SQLException {
  for (int i=0; i < childPageIds.length; i++) {
    if (childPageIds[i] == oldPos) {
      index.getPageStore().logUndo(this,data);
      written=false;
      childPageIds[i]=newPos;
      index.getPageStore().updateRecord(this);
      return;
    }
  }
  throw Message.throwInternalError();
}

Fixed version (ground truth):
/** 
 * One of the children has moved to another page.
 * @param oldPos the old position
 * @param newPos the new position
 */
void moveChild(int oldPos,int newPos) throws SQLException {
  for (int i=0; i < childPageIds.length; i++) {
    if (childPageIds[i] == oldPos) {
      index.getPageStore().logUndo(this,data);
      written=false;
      childPageIds[i]=newPos;
      index.getPageStore().update(this);
      return;
    }
  }
  throw Message.throwInternalError();
}
Program: 16106
Project: 16106
Buggy source:
void freeChildren() throws SQLException {
  for (int i=0; i <= entryCount; i++) {
    int childPageId=childPageIds[i];
    PageData child=index.getPage(childPageId,getPos());
    index.getPageStore().freePage(childPageId,false,null);
    child.freeChildren();
  }
}

Fixed version (ground truth):
void freeChildren() throws SQLException {
  for (int i=0; i <= entryCount; i++) {
    int childPageId=childPageIds[i];
    PageData child=index.getPage(childPageId,getPos());
    index.getPageStore().free(childPageId,false);
    child.freeChildren();
  }
}
Program: 16107
Project: 16107
Buggy source:
void setRowCountStored(int rowCount) throws SQLException {
  this.rowCount=rowCount;
  if (rowCountStored != rowCount) {
    rowCountStored=rowCount;
    index.getPageStore().logUndo(this,data);
    if (written) {
      writeHead();
    }
    index.getPageStore().updateRecord(this);
  }
}

Fixed version (ground truth):
void setRowCountStored(int rowCount) throws SQLException {
  this.rowCount=rowCount;
  if (rowCountStored != rowCount) {
    rowCountStored=rowCount;
    index.getPageStore().logUndo(this,data);
    if (written) {
      writeHead();
    }
    index.getPageStore().update(this);
  }
}
Program: 16108
Project: 16108
Buggy source:
protected void remapChildren() throws SQLException {
  for (  int child : childPageIds) {
    PageData p=index.getPage(child,-1);
    p.setParentPageId(getPos());
    index.getPageStore().updateRecord(p);
  }
}

Fixed version (ground truth):
protected void remapChildren() throws SQLException {
  for (  int child : childPageIds) {
    PageData p=index.getPage(child,-1);
    p.setParentPageId(getPos());
    index.getPageStore().update(p);
  }
}
Program: 16109
Project: 16109
Buggy source:
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageDataNode p2=PageDataNode.create(index,newPos,parentPageId);
  p2.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  p2.childPageIds=childPageIds;
  p2.keys=keys;
  p2.entryCount=entryCount;
  p2.length=length;
  store.updateRecord(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageDataNode p=(PageDataNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  for (int i=0; i < childPageIds.length; i++) {
    PageData p=(PageData)store.getPage(childPageIds[i]);
    p.setParentPageId(newPos);
    store.updateRecord(p);
  }
  store.freePage(getPos(),true,data);
}

Fixed version (ground truth):
public void moveTo(Session session,int newPos) throws SQLException {
  PageStore store=index.getPageStore();
  store.logUndo(this,data);
  PageDataNode p2=PageDataNode.create(index,newPos,parentPageId);
  p2.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  p2.childPageIds=childPageIds;
  p2.keys=keys;
  p2.entryCount=entryCount;
  p2.length=length;
  store.update(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageDataNode p=(PageDataNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  for (int i=0; i < childPageIds.length; i++) {
    PageData p=(PageData)store.getPage(childPageIds[i]);
    p.setParentPageId(newPos);
    store.update(p);
  }
  store.free(getPos(),true);
}
Program: 16110
Project: 16110
Buggy source:
/** 
 * Change the parent page id.
 * @param id the new parent page id
 */
void setParentPageId(int id){
  written=false;
  parentPageId=id;
}

Fixed version (ground truth):
/** 
 * Change the parent page id.
 * @param id the new parent page id
 */
void setParentPageId(int id) throws SQLException {
  index.getPageStore().logUndo(this,data);
  written=false;
  parentPageId=id;
}
Program: 16111
Project: 16111
Buggy source:
public void add(Session session,Row row) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + row.getKey());
  }
  SearchRow newRow=getSearchRow(row);
  while (true) {
    PageBtree root=getPage(rootPageId);
    int splitPoint=root.addRowTry(newRow);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    SearchRow pivot=root.getRow(splitPoint - 1);
    PageBtree page1=root;
    PageBtree page2=root.split(splitPoint);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageBtreeNode newRoot=PageBtreeNode.create(this,rootPageId,PageBtree.ROOT);
    newRoot.init(page1,pivot,page2);
    store.updateRecord(page1,true,page1.data);
    store.updateRecord(page2,true,page2.data);
    store.updateRecord(newRoot,true,null);
    root=newRoot;
  }
  rowCount++;
}

Fixed version (ground truth):
public void add(Session session,Row row) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + row.getKey());
  }
  SearchRow newRow=getSearchRow(row);
  while (true) {
    PageBtree root=getPage(rootPageId);
    int splitPoint=root.addRowTry(newRow);
    if (splitPoint == -1) {
      break;
    }
    if (trace.isDebugEnabled()) {
      trace.debug("String_Node_Str" + splitPoint);
    }
    SearchRow pivot=root.getRow(splitPoint - 1);
    store.logUndo(root,root.data);
    PageBtree page1=root;
    PageBtree page2=root.split(splitPoint);
    store.logUndo(page2,null);
    int rootPageId=root.getPos();
    int id=store.allocatePage();
    page1.setPageId(id);
    page1.setParentPageId(rootPageId);
    page2.setParentPageId(rootPageId);
    PageBtreeNode newRoot=PageBtreeNode.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(newRoot,null);
    newRoot.init(page1,pivot,page2);
    store.updateRecord(page1);
    store.updateRecord(page2);
    store.updateRecord(newRoot);
    root=newRoot;
  }
  rowCount++;
}
Program: 16112
Project: 16112
Buggy source:
public PageBtreeIndex(TableData table,int id,String indexName,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,indexName,columns,indexType);
  tableData=table;
  if (!database.isPersistent() || id < 0) {
    throw Message.throwInternalError("String_Node_Str" + indexName);
  }
  this.store=database.getPageStore();
  store.addIndex(this);
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    needRebuild=true;
    store.addMeta(this,session);
    PageBtreeLeaf root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
    store.updateRecord(root,true,root.data);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageBtree root=getPage(rootPageId);
    rowCount=root.getRowCount();
    if (rowCount == 0 && store.isRecoveryRunning()) {
      needRebuild=true;
    }
    if (!database.isReadOnly()) {
      store.updateRecord(root,false,null);
    }
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
}

Fixed version (ground truth):
public PageBtreeIndex(TableData table,int id,String indexName,IndexColumn[] columns,IndexType indexType,int headPos,Session session) throws SQLException {
  initBaseIndex(table,id,indexName,columns,indexType);
  tableData=table;
  if (!database.isPersistent() || id < 0) {
    throw Message.throwInternalError("String_Node_Str" + indexName);
  }
  this.store=database.getPageStore();
  store.addIndex(this);
  if (headPos == Index.EMPTY_HEAD) {
    rootPageId=store.allocatePage();
    needRebuild=true;
    store.addMeta(this,session);
    PageBtreeLeaf root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
    store.logUndo(root,null);
    store.updateRecord(root);
  }
 else {
    rootPageId=store.getRootPageId(id);
    PageBtree root=getPage(rootPageId);
    rowCount=root.getRowCount();
    if (rowCount == 0 && store.isRecoveryRunning()) {
      needRebuild=true;
    }
  }
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str" + getName() + "String_Node_Str"+ rowCount);
  }
}
Program: 16113
Project: 16113
Buggy source:
/** 
 * Read the given page.
 * @param id the page id
 * @return the page
 */
PageBtree getPage(int id) throws SQLException {
  PageBtree p=(PageBtree)store.getPage(id);
  if (p == null) {
    PageBtreeLeaf empty=PageBtreeLeaf.create(this,id,PageBtree.ROOT);
    return empty;
  }
  return p;
}

Fixed version (ground truth):
/** 
 * Read the given page.
 * @param id the page id
 * @return the page
 */
PageBtree getPage(int id) throws SQLException {
  PageBtree p=(PageBtree)store.getPage(id);
  if (p == null) {
    PageBtreeLeaf empty=PageBtreeLeaf.create(this,id,PageBtree.ROOT);
    store.logUndo(empty,null);
    store.updateRecord(empty);
    return empty;
  }
  return p;
}
Program: 16114
Project: 16114
Buggy source:
private void removeAllRows() throws SQLException {
  PageBtree root=getPage(rootPageId);
  root.freeChildren();
  root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
  store.removeRecord(rootPageId);
  store.updateRecord(root,true,null);
  rowCount=0;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageBtree root=getPage(rootPageId);
  store.logUndo(root,root.data);
  root.freeChildren();
  root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
  store.removeRecord(rootPageId);
  store.updateRecord(root);
  rowCount=0;
}