nus-yam/ex-repair huggingface dataset:
Program: 16032
Project: 16032
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.update(page1);
    store.update(page2);
    store.update(newRoot);
    root=newRoot;
  }
  invalidateRowCount();
  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);
  try {
    addRow(newRow);
  }
  finally {
    store.incrementChangeCount();
  }
}
Program: 16034
Project: 16034
Buggy source:
private void removeRow(int at) throws SQLException {
  readAllRows();
  index.getPageStore().logUndo(this,data);
  entryCount--;
  written=false;
  if (entryCount <= 0) {
    Message.throwInternalError();
  }
  int[] newOffsets=new int[entryCount];
  SearchRow[] newRows=new SearchRow[entryCount];
  System.arraycopy(offsets,0,newOffsets,0,at);
  System.arraycopy(rows,0,newRows,0,at);
  int startNext=at > 0 ? offsets[at - 1] : index.getPageStore().getPageSize();
  int rowLength=startNext - offsets[at];
  for (int j=at; j < entryCount; j++) {
    newOffsets[j]=offsets[j + 1] + rowLength;
  }
  System.arraycopy(rows,at + 1,newRows,at,entryCount - at);
  start-=OFFSET_LENGTH;
  offsets=newOffsets;
  rows=newRows;
}

Fixed version (ground truth):
private void removeRow(int at) throws SQLException {
  readAllRows();
  index.getPageStore().logUndo(this,data);
  entryCount--;
  written=false;
  changeCount=index.getPageStore().getChangeCount();
  if (entryCount <= 0) {
    Message.throwInternalError();
  }
  int[] newOffsets=new int[entryCount];
  SearchRow[] newRows=new SearchRow[entryCount];
  System.arraycopy(offsets,0,newOffsets,0,at);
  System.arraycopy(rows,0,newRows,0,at);
  int startNext=at > 0 ? offsets[at - 1] : index.getPageStore().getPageSize();
  int rowLength=startNext - offsets[at];
  for (int j=at; j < entryCount; j++) {
    newOffsets[j]=offsets[j + 1] + rowLength;
  }
  System.arraycopy(rows,at + 1,newRows,at,entryCount - at);
  start-=OFFSET_LENGTH;
  offsets=newOffsets;
  rows=newRows;
}
Program: 16035
Project: 16035
Buggy source:
private void removeChild(int i) throws SQLException {
  readAllRows();
  entryCount--;
  written=false;
  if (entryCount < 0) {
    Message.throwInternalError();
  }
  SearchRow[] newRows=PageStore.newSearchRows(entryCount);
  int[] newOffsets=MemoryUtils.newIntArray(entryCount);
  int[] newChildPageIds=new int[entryCount + 1];
  System.arraycopy(offsets,0,newOffsets,0,Math.min(entryCount,i));
  System.arraycopy(rows,0,newRows,0,Math.min(entryCount,i));
  System.arraycopy(childPageIds,0,newChildPageIds,0,i);
  if (entryCount > i) {
    System.arraycopy(rows,i + 1,newRows,i,entryCount - i);
    int startNext=i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize();
    int rowLength=startNext - offsets[i];
    for (int j=i; j < entryCount; j++) {
      newOffsets[j]=offsets[j + 1] + rowLength;
    }
  }
  System.arraycopy(childPageIds,i + 1,newChildPageIds,i,entryCount - i + 1);
  offsets=newOffsets;
  rows=newRows;
  childPageIds=newChildPageIds;
  start-=CHILD_OFFSET_PAIR_LENGTH;
}

Fixed version (ground truth):
private void removeChild(int i) throws SQLException {
  readAllRows();
  entryCount--;
  if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
    updateRowCount(-index.getPage(childPageIds[i]).getRowCount());
  }
  written=false;
  changeCount=index.getPageStore().getChangeCount();
  if (entryCount < 0) {
    Message.throwInternalError();
  }
  SearchRow[] newRows=PageStore.newSearchRows(entryCount);
  int[] newOffsets=MemoryUtils.newIntArray(entryCount);
  int[] newChildPageIds=new int[entryCount + 1];
  System.arraycopy(offsets,0,newOffsets,0,Math.min(entryCount,i));
  System.arraycopy(rows,0,newRows,0,Math.min(entryCount,i));
  System.arraycopy(childPageIds,0,newChildPageIds,0,i);
  if (entryCount > i) {
    System.arraycopy(rows,i + 1,newRows,i,entryCount - i);
    int startNext=i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize();
    int rowLength=startNext - offsets[i];
    for (int j=i; j < entryCount; j++) {
      newOffsets[j]=offsets[j + 1] + rowLength;
    }
  }
  System.arraycopy(childPageIds,i + 1,newChildPageIds,i,entryCount - i + 1);
  offsets=newOffsets;
  rows=newRows;
  childPageIds=newChildPageIds;
  start-=CHILD_OFFSET_PAIR_LENGTH;
}
Program: 16036
Project: 16036
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().free(page.getPos());
    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;
}

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;
  changeCount=index.getPageStore().getChangeCount();
  if (last == null) {
    return null;
  }
 else   if (last == row) {
    index.getPageStore().free(page.getPos());
    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: 16037
Project: 16037
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().update(page);
    index.getPageStore().update(page2);
    index.getPageStore().update(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;
  changeCount=index.getPageStore().getChangeCount();
  return -1;
}
Program: 16038
Project: 16038
Buggy source:
PageBtree split(int splitPoint) throws SQLException {
  int newPageId=index.getPageStore().allocatePage();
  PageBtreeNode p2=PageBtreeNode.create(index,newPageId,parentPageId);
  index.getPageStore().logUndo(this,data);
  if (onlyPosition) {
    p2.onlyPosition=true;
  }
  int firstChild=childPageIds[splitPoint];
  readAllRows();
  for (int i=splitPoint; i < entryCount; ) {
    p2.addChild(p2.entryCount,childPageIds[splitPoint + 1],rows[splitPoint]);
    removeChild(splitPoint);
  }
  int lastChild=childPageIds[splitPoint - 1];
  removeChild(splitPoint - 1);
  childPageIds[splitPoint - 1]=lastChild;
  if (p2.childPageIds == null) {
    p2.childPageIds=new int[1];
  }
  p2.childPageIds[0]=firstChild;
  p2.remapChildren();
  return p2;
}

Fixed version (ground truth):
PageBtree split(int splitPoint) throws SQLException {
  int newPageId=index.getPageStore().allocatePage();
  PageBtreeNode p2=PageBtreeNode.create(index,newPageId,parentPageId);
  index.getPageStore().logUndo(this,data);
  if (onlyPosition) {
    p2.onlyPosition=true;
  }
  int firstChild=childPageIds[splitPoint];
  readAllRows();
  for (int i=splitPoint; i < entryCount; ) {
    p2.addChild(p2.entryCount,childPageIds[splitPoint + 1],getRow(splitPoint));
    removeChild(splitPoint);
  }
  int lastChild=childPageIds[splitPoint - 1];
  removeChild(splitPoint - 1);
  childPageIds[splitPoint - 1]=lastChild;
  if (p2.childPageIds == null) {
    p2.childPageIds=new int[1];
  }
  p2.childPageIds[0]=firstChild;
  p2.remapChildren();
  return p2;
}
Program: 16039
Project: 16039
Buggy source:
void freeRecursive() throws SQLException {
  index.getPageStore().logUndo(this,data);
  for (  int childPageId : childPageIds) {
    index.getPage(childPageId).freeRecursive();
  }
}

Fixed version (ground truth):
void freeRecursive() throws SQLException {
  index.getPageStore().logUndo(this,data);
  index.getPageStore().free(getPos());
  for (  int childPageId : childPageIds) {
    index.getPage(childPageId).freeRecursive();
  }
}
Program: 16040
Project: 16040
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().update(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;
      changeCount=index.getPageStore().getChangeCount();
      childPageIds[i]=newPos;
      index.getPageStore().update(this);
      return;
    }
  }
  throw Message.throwInternalError();
}
Program: 16041
Project: 16041
Buggy source:
/** 
 * Add a row. If it is possible this method returns -1, otherwise the split point. It is always possible to two rows.
 * @param row the now to add
 * @return the split point of this page, or -1 if no split is required
 */
private int addChildTry(SearchRow row) throws SQLException {
  if (entryCount < 2) {
    return -1;
  }
  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) {
    return entryCount / 2;
  }
  return -1;
}

Fixed version (ground truth):
/** 
 * Add a row. If it is possible this method returns -1, otherwise the split point. It is always possible to two rows.
 * @param row the now to add
 * @return the split point of this page, or -1 if no split is required
 */
private int addChildTry(SearchRow row) throws SQLException {
  if (entryCount < 3) {
    return -1;
  }
  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) {
    return entryCount / 2;
  }
  return -1;
}
Program: 16042
Project: 16042
Buggy source:
/** 
 * Create a new b-tree node page.
 * @param index the index
 * @param pageId the page id
 * @param parentPageId the parent page id
 * @return the page
 */
static PageBtreeNode create(PageBtreeIndex index,int pageId,int parentPageId) throws SQLException {
  PageBtreeNode p=new PageBtreeNode(index,pageId,index.getPageStore().createData());
  index.getPageStore().logUndo(p,null);
  p.parentPageId=parentPageId;
  p.writeHead();
  p.start=p.data.length() + 4;
  return p;
}

Fixed version (ground truth):
/** 
 * Create a new b-tree node page.
 * @param index the index
 * @param pageId the page id
 * @param parentPageId the parent page id
 * @return the page
 */
static PageBtreeNode create(PageBtreeIndex index,int pageId,int parentPageId) throws SQLException {
  PageBtreeNode p=new PageBtreeNode(index,pageId,index.getPageStore().createData());
  index.getPageStore().logUndo(p,null);
  p.parentPageId=parentPageId;
  p.writeHead();
  p.start=p.data.length() + 4;
  if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
    p.rowCount=0;
  }
  return p;
}
Program: 16043
Project: 16043
Buggy source:
/** 
 * Initialize the page.
 * @param page1 the first child page
 * @param pivot the pivot key
 * @param page2 the last child page
 */
void init(PageBtree page1,SearchRow pivot,PageBtree page2) throws SQLException {
  entryCount=0;
  childPageIds=new int[]{page1.getPos()};
  rows=new SearchRow[0];
  offsets=MemoryUtils.EMPTY_INT_ARRAY;
  addChild(0,page2.getPos(),pivot);
  rowCount=page1.getRowCount() + page2.getRowCount();
  check();
}

Fixed version (ground truth):
/** 
 * Initialize the page.
 * @param page1 the first child page
 * @param pivot the pivot key
 * @param page2 the last child page
 */
void init(PageBtree page1,SearchRow pivot,PageBtree page2) throws SQLException {
  entryCount=0;
  childPageIds=new int[]{page1.getPos()};
  rows=new SearchRow[0];
  offsets=MemoryUtils.EMPTY_INT_ARRAY;
  addChild(0,page2.getPos(),pivot);
  if (SysProperties.PAGE_STORE_INTERNAL_COUNT) {
    rowCount=page1.getRowCount() + page2.getRowCount();
  }
  check();
}
Program: 16044
Project: 16044
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().update(this);
  }
}

Fixed version (ground truth):
void setRowCountStored(int rowCount) throws SQLException {
  if (rowCount < 0 && SysProperties.PAGE_STORE_INTERNAL_COUNT) {
    return;
  }
  this.rowCount=rowCount;
  if (rowCountStored != rowCount) {
    rowCountStored=rowCount;
    index.getPageStore().logUndo(this,data);
    if (written) {
      changeCount=index.getPageStore().getChangeCount();
      writeHead();
    }
    index.getPageStore().update(this);
  }
}
Program: 16046
Project: 16046
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.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  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 childPageId : childPageIds) {
    PageBtree p=index.getPage(childPageId);
    p.setParentPageId(newPos);
    store.update(p);
  }
  store.free(getPos());
}

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.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  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 {
    Page p=store.getPage(parentPageId);
    if (!(p instanceof PageBtreeNode)) {
      throw Message.throwInternalError();
    }
    PageBtreeNode n=(PageBtreeNode)p;
    n.moveChild(getPos(),newPos);
  }
  for (  int childPageId : childPageIds) {
    PageBtree p=index.getPage(childPageId);
    p.setParentPageId(newPos);
    store.update(p);
  }
  store.free(getPos());
}
Program: 16047
Project: 16047
Buggy source:
/** 
 * Change the parent page id.
 * @param id the new parent page id
 */
void setParentPageId(int id) throws SQLException {
  index.getPageStore().logUndo(this,data);
  parentPageId=id;
  if (written) {
    data.setInt(START_PARENT,parentPageId);
  }
}

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);
  parentPageId=id;
  if (written) {
    changeCount=index.getPageStore().getChangeCount();
    data.setInt(START_PARENT,parentPageId);
  }
}
Program: 16048
Project: 16048
Buggy source:
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug("String_Node_Str");
  }
  removeAllRows();
  store.free(rootPageId,true);
  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);
  store.removeMeta(this,session);
}
Program: 16049
Project: 16049
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.update(root);
  rowCount=0;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageBtree root=getPage(rootPageId);
  root.freeRecursive();
  root=PageBtreeLeaf.create(this,rootPageId,PageBtree.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
}
Program: 16050
Project: 16050
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.update(p2);
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageBtreeNode p=(PageBtreeNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
  store.free(getPos(),true);
}

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());
}
Program: 16051
Project: 16051
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().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;
}

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());
    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: 16052
Project: 16052
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.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  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);
}

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.rowCountStored=rowCountStored;
  p2.rowCount=rowCount;
  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 childPageId : childPageIds) {
    PageBtree p=index.getPage(childPageId);
    p.setParentPageId(newPos);
    store.update(p);
  }
  store.free(getPos());
}
Program: 16053
Project: 16053
Buggy source:
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug(this + "String_Node_Str");
  }
  removeAllRows();
  store.free(rootPageId,true);
  store.removeMeta(this,session);
}

Fixed version (ground truth):
public void remove(Session session) throws SQLException {
  if (trace.isDebugEnabled()) {
    trace.debug(this + "String_Node_Str");
  }
  removeAllRows();
  store.free(rootPageId);
  store.removeMeta(this,session);
}
Program: 16054
Project: 16054
Buggy source:
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;
}

Fixed version (ground truth):
private void removeAllRows() throws SQLException {
  PageData root=getPage(rootPageId,0);
  root.freeRecursive();
  root=PageDataLeaf.create(this,rootPageId,PageData.ROOT);
  store.removeRecord(rootPageId);
  store.update(root);
  rowCount=0;
  lastKey=0;
}
Program: 16055
Project: 16055
Buggy source:
/** 
 * Read an overflow page page.
 * @param id the page id
 * @return the page
 */
PageDataOverflow getPageOverflow(int id) throws SQLException {
  return (PageDataOverflow)store.getPage(id);
}

Fixed version (ground truth):
/** 
 * Read an overflow page page.
 * @param id the page id
 * @return the page
 */
PageDataOverflow getPageOverflow(int id) throws SQLException {
  Page p=store.getPage(id);
  if (p instanceof PageDataOverflow) {
    return (PageDataOverflow)p;
  }
  throw Message.getSQLException(ErrorCode.FILE_CORRUPTED_1,p.toString());
}
Program: 16056
Project: 16056
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().update(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) {
    freeRecursive();
    return true;
  }
  removeRow(i);
  index.getPageStore().update(this);
  return false;
}
Program: 16058
Project: 16058
Buggy source:
private void removeRow(int i) throws SQLException {
  index.getPageStore().logUndo(this,data);
  written=false;
  readAllRows();
  Row r=rows[i];
  if (r != null) {
    memorySize+=r.getMemorySize();
  }
  entryCount--;
  if (entryCount < 0) {
    Message.throwInternalError();
  }
  freeChildren();
  firstOverflowPageId=0;
  overflowRowSize=0;
  rowRef=null;
  int keyOffsetPairLen=2 + data.getVarLongLen(keys[i]);
  int[] newOffsets=new int[entryCount];
  long[] newKeys=new long[entryCount];
  Row[] newRows=new Row[entryCount];
  System.arraycopy(offsets,0,newOffsets,0,i);
  System.arraycopy(keys,0,newKeys,0,i);
  System.arraycopy(rows,0,newRows,0,i);
  int startNext=i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize();
  int rowLength=startNext - offsets[i];
  int clearStart=offsets[entryCount];
  Arrays.fill(data.getBytes(),clearStart,clearStart + rowLength,(byte)0);
  for (int j=i; j < entryCount; j++) {
    newOffsets[j]=offsets[j + 1] + rowLength;
  }
  System.arraycopy(keys,i + 1,newKeys,i,entryCount - i);
  System.arraycopy(rows,i + 1,newRows,i,entryCount - i);
  start-=keyOffsetPairLen;
  offsets=newOffsets;
  keys=newKeys;
  rows=newRows;
}

Fixed version (ground truth):
private void removeRow(int i) throws SQLException {
  index.getPageStore().logUndo(this,data);
  written=false;
  readAllRows();
  Row r=rows[i];
  if (r != null) {
    memorySize+=r.getMemorySize();
  }
  entryCount--;
  if (entryCount < 0) {
    Message.throwInternalError();
  }
  freeOverflow();
  firstOverflowPageId=0;
  overflowRowSize=0;
  rowRef=null;
  int keyOffsetPairLen=2 + data.getVarLongLen(keys[i]);
  int[] newOffsets=new int[entryCount];
  long[] newKeys=new long[entryCount];
  Row[] newRows=new Row[entryCount];
  System.arraycopy(offsets,0,newOffsets,0,i);
  System.arraycopy(keys,0,newKeys,0,i);
  System.arraycopy(rows,0,newRows,0,i);
  int startNext=i > 0 ? offsets[i - 1] : index.getPageStore().getPageSize();
  int rowLength=startNext - offsets[i];
  int clearStart=offsets[entryCount];
  Arrays.fill(data.getBytes(),clearStart,clearStart + rowLength,(byte)0);
  for (int j=i; j < entryCount; j++) {
    newOffsets[j]=offsets[j + 1] + rowLength;
  }
  System.arraycopy(keys,i + 1,newKeys,i,entryCount - i);
  System.arraycopy(rows,i + 1,newRows,i,entryCount - i);
  start-=keyOffsetPairLen;
  offsets=newOffsets;
  keys=newKeys;
  rows=newRows;
}
Program: 16059
Project: 16059
Buggy source:
/** 
 * Get the row at the given index.
 * @param at the index
 * @return the row
 */
Row getRowAt(int at) throws SQLException {
  Row r=rows[at];
  if (r == null) {
    if (firstOverflowPageId == 0) {
      data.setPos(offsets[at]);
      r=index.readRow(data,columnCount);
    }
 else {
      if (rowRef != null) {
        r=rowRef.get();
        if (r != null) {
          return r;
        }
      }
      PageStore store=index.getPageStore();
      Data buff=store.createData();
      int pageSize=store.getPageSize();
      int offset=offsets[at];
      buff.write(data.getBytes(),offset,pageSize - offset);
      int next=firstOverflowPageId;
      do {
        PageDataOverflow page=index.getPageOverflow(next);
        if (page == null) {
          page=index.getPageOverflow(next);
          System.out.println("String_Node_Str");
        }
        next=page.readInto(buff);
      }
 while (next != 0);
      overflowRowSize=pageSize + buff.length();
      buff.setPos(0);
      r=index.readRow(buff,columnCount);
    }
    r.setKey(keys[at]);
    if (firstOverflowPageId != 0) {
      rowRef=new SoftReference<Row>(r);
    }
 else {
      rows[at]=r;
      memorySize+=r.getMemorySize();
    }
  }
  return r;
}

Fixed version (ground truth):
/** 
 * Get the row at the given index.
 * @param at the index
 * @return the row
 */
Row getRowAt(int at) throws SQLException {
  Row r=rows[at];
  if (r == null) {
    if (firstOverflowPageId == 0) {
      data.setPos(offsets[at]);
      r=index.readRow(data,columnCount);
    }
 else {
      if (rowRef != null) {
        r=rowRef.get();
        if (r != null) {
          return r;
        }
      }
      PageStore store=index.getPageStore();
      Data buff=store.createData();
      int pageSize=store.getPageSize();
      int offset=offsets[at];
      buff.write(data.getBytes(),offset,pageSize - offset);
      int next=firstOverflowPageId;
      do {
        PageDataOverflow page=index.getPageOverflow(next);
        next=page.readInto(buff);
      }
 while (next != 0);
      overflowRowSize=pageSize + buff.length();
      buff.setPos(0);
      r=index.readRow(buff,columnCount);
    }
    r.setKey(keys[at]);
    if (firstOverflowPageId != 0) {
      rowRef=new SoftReference<Row>(r);
    }
 else {
      rows[at]=r;
      memorySize+=r.getMemorySize();
    }
  }
  return r;
}
Program: 16060
Project: 16060
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.start=start;
  p2.remapChildren(getPos());
  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);
  }
}

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.start=start;
  p2.remapChildren(getPos());
  p2.write();
  p2.data.truncate(index.getPageStore().getPageSize());
  store.update(p2);
  store.free(getPos());
  if (parentPageId == ROOT) {
    index.setRootPageId(session,newPos);
  }
 else {
    PageDataNode p=(PageDataNode)store.getPage(parentPageId);
    p.moveChild(getPos(),newPos);
  }
}
Program: 16061
Project: 16061
Buggy source:
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;
}

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());
  if (entryCount < 1) {
    return true;
  }
  removeChild(at);
  index.getPageStore().update(this);
  return false;
}
Program: 16062
Project: 16062
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.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);
}

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());
}
Program: 16063
Project: 16063
Buggy source:
public void moveTo(Session session,int newPos) throws SQLException {
  store.logUndo(this,data);
  PageDataOverflow p2=PageDataOverflow.create(store,newPos,type,parentPageId,nextPage,data,start,size);
  store.update(p2);
  if (nextPage != 0) {
    PageDataOverflow p3=(PageDataOverflow)store.getPage(nextPage);
    p3.setParentPageId(newPos);
    store.update(p3);
  }
  Page p=store.getPage(parentPageId);
  if (p == null) {
    throw Message.throwInternalError();
  }
  if (p instanceof PageDataOverflow) {
    PageDataOverflow p1=(PageDataOverflow)p;
    p1.setNext(getPos(),newPos);
  }
 else {
    PageDataLeaf p1=(PageDataLeaf)p;
    p1.setOverflow(getPos(),newPos);
  }
  store.update(p);
  store.free(getPos(),true);
}

Fixed version (ground truth):
public void moveTo(Session session,int newPos) throws SQLException {
  store.logUndo(this,data);
  PageDataOverflow p2=PageDataOverflow.create(store,newPos,type,parentPageId,nextPage,data,start,size);
  store.update(p2);
  if (nextPage != 0) {
    PageDataOverflow p3=(PageDataOverflow)store.getPage(nextPage);
    p3.setParentPageId(newPos);
    store.update(p3);
  }
  Page p=store.getPage(parentPageId);
  if (p == null) {
    throw Message.throwInternalError();
  }
  if (p instanceof PageDataOverflow) {
    PageDataOverflow p1=(PageDataOverflow)p;
    p1.setNext(getPos(),newPos);
  }
 else {
    PageDataLeaf p1=(PageDataLeaf)p;
    p1.setOverflow(getPos(),newPos);
  }
  store.update(p);
  store.free(getPos());
}
Program: 16064
Project: 16064
Buggy source:
/** 
 * 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());
    }
  }
}

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
 */
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: 16065
Project: 16065
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.truncate(systemSession);
      openIndex.remove(systemSession);
      removeMetaIndex(openIndex,systemSession);
    }
    openIndex.close(systemSession);
  }
  allocatePage(PAGE_ID_META_ROOT);
  recoveryRunning=false;
  reservedPages=null;
  writeIndexRowCounts();
  writeBack();
  cache.clear();
  freeLists.clear();
  metaObjects.clear();
  metaObjects.put(-1,metaIndex);
  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);
  }
  allocatePage(PAGE_ID_META_ROOT);
  writeIndexRowCounts();
  recoveryRunning=false;
  reservedPages=null;
  writeBack();
  cache.clear();
  freeLists.clear();
  metaObjects.clear();
  metaObjects.put(-1,metaIndex);
  if (setReadOnly) {
    database.setReadOnly(true);
  }
  trace.debug("String_Node_Str");
}
Program: 16066
Project: 16066
Buggy source:
/** 
 * Open a database connection with the given connection information.
 * @param ci the connection information
 * @return the session
 */
public Session getSession(ConnectionInfo ci) throws SQLException {
  try {
    ConnectionInfo backup=null;
    String lockMethodName=ci.getProperty("String_Node_Str",null);
    int fileLockMethod=FileLock.getFileLockMethod(lockMethodName);
    if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
      try {
        backup=(ConnectionInfo)ci.clone();
      }
 catch (      CloneNotSupportedException e) {
        throw Message.getInternalError("String_Node_Str",e);
      }
    }
    Session session=openSession(ci);
    validateUserAndPassword(true);
    if (backup != null) {
      session.setConnectionInfo(backup);
    }
    return session;
  }
 catch (  SQLException e) {
    if (e.getErrorCode() == ErrorCode.WRONG_USER_OR_PASSWORD) {
      validateUserAndPassword(false);
    }
    throw e;
  }
}

Fixed version (ground truth):
/** 
 * Open a database connection with the given connection information.
 * @param ci the connection information
 * @return the session
 */
public Session getSession(ConnectionInfo ci) throws SQLException {
  try {
    ConnectionInfo backup=null;
    String lockMethodName=ci.getProperty("String_Node_Str",null);
    int fileLockMethod=FileLock.getFileLockMethod(lockMethodName);
    if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
      ci.setProperty("String_Node_Str","String_Node_Str");
      try {
        backup=(ConnectionInfo)ci.clone();
      }
 catch (      CloneNotSupportedException e) {
        throw Message.getInternalError("String_Node_Str",e);
      }
    }
    Session session=openSession(ci);
    validateUserAndPassword(true);
    if (backup != null) {
      session.setConnectionInfo(backup);
    }
    return session;
  }
 catch (  SQLException e) {
    if (e.getErrorCode() == ErrorCode.WRONG_USER_OR_PASSWORD) {
      validateUserAndPassword(false);
    }
    throw e;
  }
}
Program: 16067
Project: 16067
Buggy source:
public SessionInterface reconnect(boolean write) throws SQLException {
  readSessionState();
  close();
  Session newSession=Engine.getInstance().getSession(connectionInfo);
  newSession.sessionState=sessionState;
  newSession.recreateSessionState();
  database.clearCaches();
  if (write) {
    while (!database.beforeWriting()) {
    }
  }
  return newSession;
}

Fixed version (ground truth):
public SessionInterface reconnect(boolean write) throws SQLException {
  readSessionState();
  close();
  Session newSession=Engine.getInstance().getSession(connectionInfo);
  newSession.sessionState=sessionState;
  newSession.recreateSessionState();
  if (write) {
    while (!database.beforeWriting()) {
    }
  }
  return newSession;
}
Program: 16068
Project: 16068
Buggy source:
public void test() throws Exception {
  println("String_Node_Str");
  testCache();
  println("String_Node_Str");
  testBigDatabase(false);
  println("String_Node_Str");
  testBigDatabase(true);
  println("String_Node_Str");
  testCheckpointInUpdateRaceCondition();
  println("String_Node_Str");
  testConcurrentUpdates();
  println("String_Node_Str");
  testThreeMostlyReaders(true);
  println("String_Node_Str");
  testThreeMostlyReaders(false);
  println("String_Node_Str");
  testTwoReaders();
  println("String_Node_Str");
  testTwoWriters();
  println("String_Node_Str");
  testPendingWrite();
  println("String_Node_Str");
  testKillWriter();
  println("String_Node_Str");
  testConcurrentReadWrite();
}

Fixed version (ground truth):
public void test() throws Exception {
  println("String_Node_Str");
  testWrongDatabaseInstanceOnReconnect();
  println("String_Node_Str");
  testCache(false);
  println("String_Node_Str");
  testCache(true);
  println("String_Node_Str");
  testBigDatabase(false);
  println("String_Node_Str");
  testBigDatabase(true);
  println("String_Node_Str");
  testCheckpointInUpdateRaceCondition();
  println("String_Node_Str");
  testConcurrentUpdates();
  println("String_Node_Str");
  testThreeMostlyReaders(true);
  println("String_Node_Str");
  testThreeMostlyReaders(false);
  println("String_Node_Str");
  testTwoReaders();
  println("String_Node_Str");
  testTwoWriters();
  println("String_Node_Str");
  testPendingWrite();
  println("String_Node_Str");
  testKillWriter();
  println("String_Node_Str");
  testConcurrentReadWrite();
}
Program: 16069
Project: 16069
Buggy source:
/** 
 * Caches must be cleared. Session.reconnect only closes the DiskFile (which is associated with the cache) if there is one session
 * @throws Exception
 */
private void testCache() throws Exception {
  deleteDb("String_Node_Str");
  String urlShared="String_Node_Str" + baseDir + "String_Node_Str";
  String urlForNew=urlShared + "String_Node_Str";
  Connection connShared1=DriverManager.getConnection(urlShared);
  Connection connShared2=DriverManager.getConnection(urlShared);
  Connection connNew=DriverManager.getConnection(urlForNew);
  connShared1.createStatement().execute("String_Node_Str");
  connShared1.createStatement().execute("String_Node_Str");
  ResultSet rs=connShared1.createStatement().executeQuery("String_Node_Str");
  rs.close();
  connNew.createStatement().execute("String_Node_Str");
  Thread.sleep(500);
  rs=connShared1.createStatement().executeQuery("String_Node_Str");
  assertTrue(rs.next());
  assertEquals(2,rs.getInt(1));
  rs.close();
  connShared1.close();
  connShared2.close();
  connNew.close();
  deleteDb("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Caches must be cleared. Session.reconnect only closes the DiskFile (which is associated with the cache) if there is one session
 * @throws Exception
 */
private void testCache(boolean reconnectClearCache) throws Exception {
  deleteDb("String_Node_Str");
  String urlShared="String_Node_Str" + baseDir + "String_Node_Str";
  Connection connShared1=DriverManager.getConnection(urlShared);
  Statement statement1=connShared1.createStatement();
  Connection connShared2=DriverManager.getConnection(urlShared);
  Statement statement2=connShared2.createStatement();
  statement1.execute("String_Node_Str");
  statement1.execute("String_Node_Str");
  ResultSet rs=statement1.executeQuery("String_Node_Str");
  rs.close();
  rs=statement2.executeQuery("String_Node_Str");
  rs.close();
  statement1.execute("String_Node_Str");
  Thread.sleep(500);
  rs=statement2.executeQuery("String_Node_Str");
  assertTrue(rs.next());
  assertEquals(2,rs.getInt(1));
  rs.close();
  connShared1.close();
  connShared2.close();
  deleteDb("String_Node_Str");
}
Program: 16070
Project: 16070
Buggy source:
/** 
 * Mark a page as used.
 * @param pageId the page id
 * @return the page id, or -1
 */
int allocate(int pageId) throws SQLException {
  int idx=pageId - getPos();
  if (idx >= 0 && !used.get(idx)) {
    store.logUndo(this,data);
    used.set(idx);
    store.update(this);
  }
  return pageId;
}

Fixed version (ground truth):
/** 
 * Mark a page as used.
 * @param pageId the page id
 * @return the page id, or -1
 */
int allocate(int pageId) throws SQLException {
  int idx=pageId - getPos();
  if (idx >= 0 && !used.get(idx)) {
    used.set(idx);
    store.logUndo(this,data);
    store.update(this);
  }
  return pageId;
}