nus-yam/ex-repair huggingface dataset:
Program: 30841
Project: 30841
Buggy source:
private void bumpStructureVersion(){
  txMem.jumpTo(TableUtils.TX_OFFSET_STRUCT_VERSION);
  txMem.putLong(++structVersion);
  fencedTxnBump();
}

Fixed version (ground truth):
private void bumpStructureVersion(){
  txMem.jumpTo(TableUtils.TX_OFFSET_TXN);
  txMem.putLong(++txn);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(TableUtils.TX_OFFSET_STRUCT_VERSION);
  txMem.putLong(++structVersion);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(TableUtils.TX_OFFSET_TXN_CHECK);
  txMem.putLong(txn);
}
Program: 30842
Project: 30842
Buggy source:
@Override public void close(){
  if (isOpen()) {
    closeColumns(true);
    Misc.free(txMem);
    Misc.free(metaMem);
    Misc.free(columnSizeMem);
    Misc.free(ddlMem);
    Misc.free(path);
    Misc.free(other);
    if (lockFd != -1L) {
      ff.close(lockFd);
    }
    if (tempMem8b != 0) {
      Unsafe.free(tempMem8b,8);
      tempMem8b=0;
    }
    LOG.info().$("String_Node_Str").utf8(name).$('\'').$();
  }
}

Fixed version (ground truth):
@Override public void close(){
  if (isOpen()) {
    closeColumns(true);
    if (txMem != null) {
      txMem.jumpTo(TableUtils.TX_EOF);
      txMem.close();
    }
    Misc.free(metaMem);
    Misc.free(columnSizeMem);
    Misc.free(ddlMem);
    Misc.free(path);
    Misc.free(other);
    if (lockFd != -1L) {
      ff.close(lockFd);
    }
    if (tempMem8b != 0) {
      Unsafe.free(tempMem8b,8);
      tempMem8b=0;
    }
    LOG.info().$("String_Node_Str").utf8(name).$('\'').$();
  }
}
Program: 30843
Project: 30843
Buggy source:
private long openPartition(int partitionIndex,int columnBase,boolean last){
  try {
    Path path=partitionPathGenerator.generate(this,partitionIndex);
    final long partitionSize;
    if (ff.exists(path)) {
      path.chopZ();
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize(ff,path,tempMem8b);
      }
      LOG.info().$("String_Node_Str").$(path.$()).$("String_Node_Str").$(partitionSize).$(']').$();
      if (partitionSize > -1) {
        openPartitionColumns(path,columnBase);
      }
    }
 else {
      partitionSize=-1;
    }
    partitionRowCounts.setQuick(partitionIndex,partitionSize);
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}

Fixed version (ground truth):
private long openPartition(int partitionIndex,int columnBase,boolean last){
  try {
    Path path=partitionPathGenerator.generate(this,partitionIndex);
    final long partitionSize;
    if (ff.exists(path)) {
      path.chopZ();
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize(ff,path,tempMem8b);
      }
      LOG.info().$("String_Node_Str").$(path.$()).$("String_Node_Str").$(partitionSize).$(']').$();
      if (partitionSize > -1) {
        openPartitionColumns(path,columnBase);
        partitionRowCounts.setQuick(partitionIndex,partitionSize);
      }
    }
 else {
      partitionSize=-1;
    }
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}
Program: 30844
Project: 30844
Buggy source:
private boolean switchPartition(){
  while (partitionIndex < partitionCount) {
    final int columnBase=getColumnBase(partitionIndex);
    long partitionSize=partitionRowCounts.getQuick(partitionIndex);
    if (partitionSize == -1) {
      partitionSize=openPartition(partitionIndex++,columnBase,partitionIndex == partitionCount);
    }
 else {
      partitionIndex++;
    }
    if (partitionSize > 0) {
      record.maxRecordIndex=partitionSize - 1;
      record.recordIndex=-1;
      record.columnBase=columnBase;
      return true;
    }
  }
  return false;
}

Fixed version (ground truth):
private boolean switchPartition(){
}
Program: 30845
Project: 30845
Buggy source:
private boolean reloadInitialPartitioned(){
  if (readTxn()) {
    partitionMin=findPartitionMinimum(dateFormat);
    partitionCount=calculatePartitionCount();
    if (partitionCount > 0 && maxTimestamp != Numbers.LONG_NaN) {
      updateCapacities();
      reloadMethod=PARTITIONED_RELOAD_METHOD;
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
private boolean reloadInitialPartitioned(){
  if (readTxn()) {
    partitionMin=findPartitionMinimum(dateFormat);
    partitionCount=calculatePartitionCount();
    if (partitionCount > 0) {
      updateCapacities();
      if (maxTimestamp != Numbers.LONG_NaN) {
        reloadMethod=PARTITIONED_RELOAD_METHOD;
      }
    }
    return true;
  }
  return false;
}
Program: 30846
Project: 30846
Buggy source:
private long openPartition(int partitionIndex,int columnBase,boolean last){
  try {
    Path path=partitionPathGenerator.generate(this,partitionIndex);
    final long partitionSize;
    if (ff.exists(path)) {
      path.chopZ();
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize(ff,path,tempMem8b);
      }
      LOG.info().$("String_Node_Str").$(path.$()).$("String_Node_Str").$(partitionSize).$(']').$();
      if (partitionSize > 0) {
        openPartitionColumns(path,columnBase);
      }
    }
 else {
      partitionSize=0;
    }
    partitionRowCounts.setQuick(partitionIndex,partitionSize);
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}

Fixed version (ground truth):
private long openPartition(int partitionIndex,int columnBase,boolean last){
  try {
    Path path=partitionPathGenerator.generate(this,partitionIndex);
    final long partitionSize;
    if (ff.exists(path)) {
      path.chopZ();
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize(ff,path,tempMem8b);
      }
      LOG.info().$("String_Node_Str").$(path.$()).$("String_Node_Str").$(partitionSize).$(']').$();
      if (partitionSize > 0) {
        openPartitionColumns(path,columnBase);
      }
    }
 else {
      partitionSize=-1;
    }
    partitionRowCounts.setQuick(partitionIndex,partitionSize);
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}
Program: 30848
Project: 30848
Buggy source:
@Override protected boolean releaseAll(long deadline){
  long thread=Thread.currentThread().getId();
  boolean removed=false;
  final int reason;
  if (deadline == Long.MAX_VALUE) {
    reason=PoolConstants.CR_POOL_CLOSE;
  }
 else {
    reason=PoolConstants.CR_IDLE;
  }
  Iterator<Entry> iterator=entries.values().iterator();
  while (iterator.hasNext()) {
    Entry e=iterator.next();
    if ((deadline > e.lastReleaseTime && e.owner == UNALLOCATED)) {
      if (Unsafe.cas(e,ENTRY_OWNER,UNALLOCATED,thread)) {
        closeWriter(thread,e,PoolListener.EV_EXPIRE,reason);
        iterator.remove();
        removed=true;
        Unsafe.getUnsafe().putOrderedLong(e,ENTRY_OWNER,UNALLOCATED);
      }
    }
 else     if (e.lockFd != -1L) {
      if (ff.close(e.lockFd)) {
        e.lockFd=-1L;
        iterator.remove();
        removed=true;
      }
    }
 else     if (e.ex != null) {
      LOG.info().$("String_Node_Str").$();
      iterator.remove();
      removed=true;
    }
  }
  return removed;
}

Fixed version (ground truth):
@Override protected boolean releaseAll(long deadline){
  long thread=Thread.currentThread().getId();
  boolean removed=false;
  final int reason;
  if (deadline == Long.MAX_VALUE) {
    reason=PoolConstants.CR_POOL_CLOSE;
  }
 else {
    reason=PoolConstants.CR_IDLE;
  }
  Iterator<Entry> iterator=entries.values().iterator();
  while (iterator.hasNext()) {
    Entry e=iterator.next();
    if ((deadline > e.lastReleaseTime && e.owner == UNALLOCATED)) {
      if (Unsafe.cas(e,ENTRY_OWNER,UNALLOCATED,thread)) {
        closeWriter(thread,e,PoolListener.EV_EXPIRE,reason);
        iterator.remove();
        removed=true;
      }
    }
 else     if (e.lockFd != -1L) {
      if (ff.close(e.lockFd)) {
        e.lockFd=-1L;
        iterator.remove();
        removed=true;
      }
    }
 else     if (e.ex != null) {
      LOG.info().$("String_Node_Str").$();
      iterator.remove();
      removed=true;
    }
  }
  return removed;
}
Program: 30849
Project: 30849
Buggy source:
@Test public void testAllocateAndClear() throws Exception {
  assertWithPool(pool -> {
    int n=2;
    final CyclicBarrier barrier=new CyclicBarrier(n);
    final CountDownLatch halt=new CountDownLatch(n);
    final AtomicInteger errors1=new AtomicInteger();
    final AtomicInteger errors2=new AtomicInteger();
    final AtomicInteger writerCount=new AtomicInteger();
    new Thread(() -> {
      try {
        for (int i=0; i < 1000; i++) {
          try (TableWriter ignored=pool.get("String_Node_Str")){
            writerCount.incrementAndGet();
          }
 catch (          EntryUnavailableException ignored) {
          }
          if (i == 1) {
            barrier.await();
          }
 else {
            LockSupport.parkNanos(1L);
          }
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
        errors1.incrementAndGet();
      }
 finally {
        halt.countDown();
      }
    }
).start();
    new Thread(() -> {
      try {
        barrier.await();
        for (int i=0; i < 1000; i++) {
          pool.releaseInactive();
          LockSupport.parkNanos(1L);
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
        errors2.incrementAndGet();
      }
 finally {
        halt.countDown();
      }
    }
).start();
    halt.await();
    Assert.assertTrue(writerCount.get() > 0);
    Assert.assertEquals(0,errors1.get());
    Assert.assertEquals(0,errors2.get());
  }
);
}

Fixed version (ground truth):
@Test public void testAllocateAndClear() throws Exception {
  assertWithPool(pool -> {
    int n=2;
    final CyclicBarrier barrier=new CyclicBarrier(n);
    final CountDownLatch halt=new CountDownLatch(n);
    final AtomicInteger errors1=new AtomicInteger();
    final AtomicInteger errors2=new AtomicInteger();
    final AtomicInteger writerCount=new AtomicInteger();
    new Thread(() -> {
      try {
        for (int i=0; i < 1000000; i++) {
          try (TableWriter ignored=pool.get("String_Node_Str")){
            writerCount.incrementAndGet();
          }
 catch (          EntryUnavailableException ignored) {
          }
          if (i == 1) {
            barrier.await();
          }
 else {
            LockSupport.parkNanos(1L);
          }
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
        errors1.incrementAndGet();
      }
 finally {
        halt.countDown();
      }
    }
).start();
    new Thread(() -> {
      try {
        barrier.await();
        for (int i=0; i < 1000000; i++) {
          pool.releaseInactive();
          LockSupport.parkNanos(1L);
        }
      }
 catch (      Exception e) {
        e.printStackTrace();
        errors2.incrementAndGet();
      }
 finally {
        halt.countDown();
      }
    }
).start();
    halt.await();
    Assert.assertTrue(writerCount.get() > 0);
    Assert.assertEquals(0,errors1.get());
    Assert.assertEquals(0,errors2.get());
  }
);
}
Program: 30850
Project: 30850
Buggy source:
@Override protected boolean runSerially(){
  long t=System.currentTimeMillis();
  if (last + checkInterval < t) {
    last=t;
    return doRun();
  }
  return false;
}

Fixed version (ground truth):
@Override protected boolean runSerially(){
  long t=clock.getTicks();
  if (last + checkInterval < t) {
    last=t;
    return doRun();
  }
  return false;
}
Program: 30851
Project: 30851
Buggy source:
private void rename0(CharSequence tableName,CharSequence to){
  final FilesFacade ff=configuration.getFilesFacade();
  final CharSequence root=configuration.getRoot();
  try (Path oldName=new Path()){
    try (Path newName=new Path()){
      if (TableUtils.exists(ff,oldName,root,tableName) != TableUtils.TABLE_EXISTS) {
        LOG.error().$('\'').utf8(tableName).$("String_Node_Str").$();
        throw CairoException.instance(0).put("String_Node_Str").put(tableName).put("String_Node_Str");
      }
      if (Os.type == Os.WINDOWS) {
        oldName.of("String_Node_Str").concat(root).concat(tableName).$();
        newName.of("String_Node_Str").concat(root).concat(to).$();
      }
 else {
        oldName.of(root).concat(tableName).$();
        newName.of(root).concat(to).$();
      }
      if (ff.exists(newName)) {
        LOG.error().$("String_Node_Str").$(tableName).$("String_Node_Str").$(newName).$("String_Node_Str").$();
        throw CairoException.instance(0).put("String_Node_Str");
      }
      if (!getConfiguration().getFilesFacade().rename(oldName,newName)) {
        int error=ff.errno();
        LOG.error().$("String_Node_Str").$(oldName).$("String_Node_Str").$(newName).$("String_Node_Str").$(error).$(']').$();
        throw CairoException.instance(error).put("String_Node_Str");
      }
    }
   }
 }

Fixed version (ground truth):
private void rename0(CharSequence tableName,CharSequence to){
  final FilesFacade ff=configuration.getFilesFacade();
  final CharSequence root=configuration.getRoot();
  if (TableUtils.exists(ff,path,root,tableName) != TableUtils.TABLE_EXISTS) {
    LOG.error().$('\'').utf8(tableName).$("String_Node_Str").$();
    throw CairoException.instance(0).put("String_Node_Str").put(tableName).put("String_Node_Str");
  }
  if (Os.type == Os.WINDOWS) {
    path.of("String_Node_Str").concat(root).concat(tableName).$();
    other.of("String_Node_Str").concat(root).concat(to).$();
  }
 else {
    path.of(root).concat(tableName).$();
    other.of(root).concat(to).$();
  }
  if (ff.exists(other)) {
    LOG.error().$("String_Node_Str").$(tableName).$("String_Node_Str").$(other).$("String_Node_Str").$();
    throw CairoException.instance(0).put("String_Node_Str");
  }
  if (!ff.rename(path,other)) {
    int error=ff.errno();
    LOG.error().$("String_Node_Str").$(path).$("String_Node_Str").$(other).$("String_Node_Str").$(error).$(']').$();
    throw CairoException.instance(error).put("String_Node_Str");
  }
}
Program: 30852
Project: 30852
Buggy source:
public void remove(CharSequence tableName){
  if (lock(tableName)) {
    try {
      path.of(configuration.getRoot()).concat(tableName).$();
      if (!configuration.getFilesFacade().rmdir(path)) {
        int error=configuration.getFilesFacade().errno();
        LOG.error().$("String_Node_Str").utf8(tableName).$("String_Node_Str").$(error).$(']').$();
        throw CairoException.instance(error).put("String_Node_Str");
      }
    }
  finally {
      unlock(tableName);
    }
  }
  throw CairoException.instance(configuration.getFilesFacade().errno()).put("String_Node_Str").put(tableName);
}

Fixed version (ground truth):
public void remove(CharSequence tableName){
  if (lock(tableName)) {
    try {
      path.of(configuration.getRoot()).concat(tableName).$();
      if (!configuration.getFilesFacade().rmdir(path)) {
        int error=configuration.getFilesFacade().errno();
        LOG.error().$("String_Node_Str").utf8(tableName).$("String_Node_Str").$(error).$(']').$();
        throw CairoException.instance(error).put("String_Node_Str");
      }
      return;
    }
  finally {
      unlock(tableName);
    }
  }
  throw CairoException.instance(configuration.getFilesFacade().errno()).put("String_Node_Str").put(tableName);
}
Program: 30853
Project: 30853
Buggy source:
@Override protected boolean doRun(){
  return writerPool.releaseInactive() || readerPool.releaseInactive();
}

Fixed version (ground truth):
protected boolean doRun(){
  boolean w=writerPool.releaseInactive();
  boolean r=readerPool.releaseInactive();
  return w || r;
}
Program: 30854
Project: 30854
Buggy source:
public void rename(CharSequence tableName,String newName){
  lock(tableName);
  try {
    rename0(tableName,newName);
  }
  finally {
    unlock(tableName);
  }
}

Fixed version (ground truth):
public void rename(CharSequence tableName,String newName){
  if (lock(tableName)) {
    try {
      rename0(tableName,newName);
    }
  finally {
      unlock(tableName);
    }
  }
 else {
    LOG.error().$("String_Node_Str").$(tableName).$("String_Node_Str").$(newName).$("String_Node_Str").$();
    throw CairoException.instance(0).put("String_Node_Str").put(tableName).put(']');
  }
}
Program: 30855
Project: 30855
Buggy source:
public WriterMaintenanceJob(long checkInterval){
  super(checkInterval);
}

Fixed version (ground truth):
public WriterMaintenanceJob(CairoConfiguration configuration){
  this.clock=configuration.getClock();
  this.checkInterval=configuration.getIdleCheckInterval() * 1000;
}
Program: 30856
Project: 30856
Buggy source:
public Engine(CairoConfiguration configuration){
  this.configuration=configuration;
  this.writerPool=new WriterPool(configuration);
  this.readerPool=new ReaderPool(configuration);
  this.writerMaintenanceJob=new WriterMaintenanceJob(configuration.getIdleCheckInterval());
}

Fixed version (ground truth):
public Engine(CairoConfiguration configuration){
  this.configuration=configuration;
  this.writerPool=new WriterPool(configuration);
  this.readerPool=new ReaderPool(configuration);
  this.writerMaintenanceJob=new WriterMaintenanceJob(configuration);
}
Program: 30858
Project: 30858
Buggy source:
public void unlock(CharSequence name){
  long thread=Thread.currentThread().getId();
  Entry e=entries.get(name);
  if (e == null) {
    notifyListener(thread,name,PoolListener.EV_NOT_LOCKED);
    return;
  }
  if (e.owner == thread) {
    if (e.writer != null) {
      notifyListener(thread,name,PoolListener.EV_NOT_LOCKED);
      throw new IllegalStateException("String_Node_Str" + name + "String_Node_Str");
    }
    entries.remove(name);
  }
  if (e.lockFd != -1) {
    ff.close(e.lockFd);
  }
  notifyListener(thread,name,PoolListener.EV_UNLOCKED);
}

Fixed version (ground truth):
public void unlock(CharSequence name){
  long thread=Thread.currentThread().getId();
  Entry e=entries.get(name);
  if (e == null) {
    notifyListener(thread,name,PoolListener.EV_NOT_LOCKED);
    return;
  }
  if (e.owner == thread) {
    if (e.writer != null) {
      notifyListener(thread,name,PoolListener.EV_NOT_LOCKED);
      throw CairoException.instance(0).put("String_Node_Str").put(name).put("String_Node_Str");
    }
    entries.remove(name);
  }
  if (e.lockFd != -1) {
    ff.close(e.lockFd);
  }
  notifyListener(thread,name,PoolListener.EV_UNLOCKED);
}
Program: 30859
Project: 30859
Buggy source:
/** 
 * Locks writer. Locking operation is always non-blocking. Lock is usually successful when writer is in pool or owned by calling thread, in which case writer instance is closed. Lock will also succeed when writer does not exist. This will prevent from writer being created before it is unlocked. <p> Lock fails immediately with   {@link EntryUnavailableException} when writer is used by another thread and with{@link PoolClosedException} when pool is closed.</p> <p> Lock is beneficial before table directory is renamed or deleted. </p>
 * @param tableName table name
 */
public boolean lock(CharSequence tableName){
  checkClosed();
  long thread=Thread.currentThread().getId();
  Entry e=entries.get(tableName);
  if (e == null) {
    e=new Entry(clock.getTicks());
    Entry other=entries.putIfAbsent(tableName,e);
    if (other == null) {
      return lockAndNotify(thread,e,tableName);
    }
 else {
      e=other;
    }
  }
  if ((Unsafe.cas(e,ENTRY_OWNER,UNALLOCATED,thread) || Unsafe.cas(e,ENTRY_OWNER,thread,thread))) {
    closeWriter(thread,e,PoolListener.EV_LOCK_CLOSE,PoolConstants.CR_NAME_LOCK);
    return lockAndNotify(thread,e,tableName);
  }
  LOG.error().$("String_Node_Str").$(tableName).$("String_Node_Str").$(e.owner).$("String_Node_Str").$(thread).$();
  notifyListener(thread,tableName,PoolListener.EV_LOCK_BUSY);
  return false;
}

Fixed version (ground truth):
/** 
 * Locks writer. Locking operation is always non-blocking. Lock is usually successful when writer is in pool or owned by calling thread, in which case writer instance is closed. Lock will also succeed when writer does not exist. This will prevent from writer being created before it is unlocked. <p> Lock fails immediately with   {@link EntryUnavailableException} when writer is used by another thread and with{@link PoolClosedException} when pool is closed.</p> <p> Lock is beneficial before table directory is renamed or deleted. </p>
 * @param tableName table name
 */
public boolean lock(CharSequence tableName){
  checkClosed();
  long thread=Thread.currentThread().getId();
  Entry e=entries.get(tableName);
  if (e == null) {
    e=new Entry(clock.getTicks());
    Entry other=entries.putIfAbsent(tableName,e);
    if (other == null) {
      return lockAndNotify(thread,e,tableName);
    }
 else {
      e=other;
    }
  }
  if ((Unsafe.cas(e,ENTRY_OWNER,UNALLOCATED,thread))) {
    closeWriter(thread,e,PoolListener.EV_LOCK_CLOSE,PoolConstants.CR_NAME_LOCK);
    return lockAndNotify(thread,e,tableName);
  }
  LOG.error().$("String_Node_Str").$(tableName).$("String_Node_Str").$(e.owner).$("String_Node_Str").$(thread).$();
  notifyListener(thread,tableName,PoolListener.EV_LOCK_BUSY);
  return false;
}
Program: 30860
Project: 30860
Buggy source:
public TableReader getReader(CharSequence tableName){
  return readerPool.getReader(tableName);
}

Fixed version (ground truth):
public TableReader getReader(CharSequence tableName){
  return readerPool.get(tableName);
}
Program: 30861
Project: 30861
Buggy source:
public TableWriter getWriter(CharSequence tableName){
  return writerPool.getWriter(tableName);
}

Fixed version (ground truth):
public TableWriter getWriter(CharSequence tableName){
  return writerPool.get(tableName);
}
Program: 30862
Project: 30862
Buggy source:
@Override public int getInt(long offset){
  return 0;
}

Fixed version (ground truth):
@Override public int getInt(long offset){
  return Numbers.INT_NaN;
}
Program: 30863
Project: 30863
Buggy source:
@Override public int getInt(int col){
  long index=getIndex(col);
  if (index < 0) {
    return 0;
  }
  return colA(col).getInt(index * 4);
}

Fixed version (ground truth):
@Override public int getInt(int col){
  long index=getIndex(col);
  if (index < 0) {
    return Numbers.INT_NaN;
  }
  return colA(col).getInt(index * 4);
}
Program: 30864
Project: 30864
Buggy source:
static void resetTxn(VirtualMemory txMem){
  txMem.putLong(-1);
  txMem.putLong(0);
  txMem.putLong(0);
  txMem.putLong(Long.MIN_VALUE);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(0);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(TX_EOF);
}

Fixed version (ground truth):
public static void resetTxn(VirtualMemory txMem){
  txMem.putLong(-1);
  txMem.putLong(0);
  txMem.putLong(0);
  txMem.putLong(Long.MIN_VALUE);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(0);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(TX_EOF);
}
Program: 30867
Project: 30867
Buggy source:
public void putStr(int index,CharSequence value){
  getSecondaryColumn(index).putLong(getPrimaryColumn(index).putStr(value));
  notNull(index);
}

Fixed version (ground truth):
public void putStr(int index,CharSequence value,int pos,int len){
  getSecondaryColumn(index).putLong(getPrimaryColumn(index).putStr(value,pos,len));
  notNull(index);
}
Program: 30868
Project: 30868
Buggy source:
private LongConsumer configureTimestampSetter(){
  int index=metadata.getTimestampIndex();
  if (index == -1) {
    return value -> {
    }
;
  }
 else {
    return getPrimaryColumn(index)::putLong;
  }
}

Fixed version (ground truth):
private LongConsumer configureTimestampSetter(){
  int index=metadata.getTimestampIndex();
  if (index == -1) {
    return value -> {
    }
;
  }
 else {
    nullers.setQuick(index,NOOP);
    return getPrimaryColumn(index)::putLong;
  }
}
Program: 30869
Project: 30869
Buggy source:
private void clearPages(){
  int n=pages.size();
  if (n > 0) {
    for (int i=0; i < n; i++) {
      release(i,pages.getQuick(i));
    }
  }
  pages.clear();
}

Fixed version (ground truth):
private void clearPages(){
  int n=pages.size();
  if (n > 0) {
    for (int i=0; i < n; i++) {
      release(i,pages.getQuick(i));
    }
  }
  pages.erase();
}
Program: 30870
Project: 30870
Buggy source:
private void putStrSplit(CharSequence value,int len){
  int start=0;
  do {
    int half=(int)((pageHi - appendPointer) / 2);
    if (len <= half) {
      copyStrChars(value,start,len,appendPointer);
      appendPointer+=len * 2;
      break;
    }
    copyStrChars(value,start,half,appendPointer);
    if (half * 2 < pageHi - appendPointer) {
      putSplitChar(value.charAt(start + half++));
    }
 else {
      pageAt(getAppendOffset() + half * 2);
    }
    len-=half;
    start+=half;
  }
 while (true);
}

Fixed version (ground truth):
private void putStrSplit(CharSequence value,int pos,int len){
  int start=pos;
  do {
    int half=(int)((pageHi - appendPointer) / 2);
    if (len <= half) {
      copyStrChars(value,start,len,appendPointer);
      appendPointer+=len * 2;
      break;
    }
    copyStrChars(value,start,half,appendPointer);
    if (half * 2 < pageHi - appendPointer) {
      putSplitChar(value.charAt(start + half++));
    }
 else {
      pageAt(getAppendOffset() + half * 2);
    }
    len-=half;
    start+=half;
  }
 while (true);
}
Program: 30871
Project: 30871
Buggy source:
public final long putStr(CharSequence value){
  final long offset=getAppendOffset();
  if (value == null) {
    putInt(-1);
    return offset;
  }
  int l=value.length();
  putInt(l);
  if (pageHi - appendPointer < l * 2) {
    putStrSplit(value,l);
  }
 else {
    copyStrChars(value,0,l,appendPointer);
    appendPointer+=l * 2;
  }
  return offset;
}

Fixed version (ground truth):
public final long putStr(CharSequence value,int pos,int len){
  if (value == null) {
    return putNullStr();
  }
  final long offset=getAppendOffset();
  putInt(len);
  if (pageHi - appendPointer < len * 2) {
    putStrSplit(value,pos,len);
  }
 else {
    copyStrChars(value,pos,len,appendPointer);
    appendPointer+=len * 2;
  }
  return offset;
}
Program: 30872
Project: 30872
Buggy source:
@Override protected void release(long address){
  ff.munmap(address,pageSize);
}

Fixed version (ground truth):
@Override protected void release(int page,long address){
  ff.munmap(address,getPageSize(page));
}
Program: 30873
Project: 30873
Buggy source:
private void releaseCurrentPage(){
  if (pageAddress != 0) {
    release(pageAddress);
    pageAddress=0;
  }
}

Fixed version (ground truth):
private void releaseCurrentPage(){
  if (pageAddress != 0) {
    release(0,pageAddress);
    pageAddress=0;
  }
}
Program: 30874
Project: 30874
Buggy source:
public void truncate(){
  if (fd == -1) {
    return;
  }
  this.size=0;
  releaseCurrentPage();
  if (!ff.truncate(fd,pageSize)) {
    throw CairoException.instance(Os.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(pageSize).put("String_Node_Str");
  }
  updateLimits(0,pageAddress=mapPage(0));
}

Fixed version (ground truth):
public void truncate(){
  if (fd == -1) {
    return;
  }
  this.size=0;
  releaseCurrentPage();
  if (!ff.truncate(fd,getMapPageSize())) {
    throw CairoException.instance(Os.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(getMapPageSize()).put("String_Node_Str");
  }
  updateLimits(0,pageAddress=mapPage(0));
}
Program: 30875
Project: 30875
Buggy source:
private long mapPage(int page){
  long target=pageOffset(page + 1);
  if (ff.length(fd) < target && !ff.truncate(fd,target)) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(target);
  }
  long offset=pageOffset(page);
  long address=ff.mmap(fd,pageSize,offset,Files.MAP_RW);
  if (address == -1) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(pageSize);
  }
  return address;
}

Fixed version (ground truth):
private long mapPage(int page){
  long target=pageOffset(page + 1);
  if (ff.length(fd) < target && !ff.truncate(fd,target)) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(target);
  }
  long offset=pageOffset(page);
  long address=ff.mmap(fd,getMapPageSize(),offset,Files.MAP_RW);
  if (address == -1) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(getMapPageSize());
  }
  return address;
}
Program: 30876
Project: 30876
Buggy source:
@Override protected void release(long address){
  ff.munmap(address,pageSize);
}

Fixed version (ground truth):
@Override protected void release(int page,long address){
  if (address != 0) {
    ff.munmap(address,getPageSize(page));
    if (page == lastPageIndex) {
      lastPageSize=getMapPageSize();
    }
  }
}
Program: 30877
Project: 30877
Buggy source:
private long mapPage(int page){
  long address;
  long offset=pageOffset(page);
  long sz=size - offset;
  if (sz > 0) {
    if (sz > pageSize) {
      sz=pageSize;
    }
 else {
      this.lastPageSize=sz;
    }
    address=ff.mmap(fd,sz,offset,Files.MAP_RO);
  }
 else {
    address=-1L;
  }
  if (address == -1L) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(sz);
  }
  cachePageAddress(page,address);
  return address;
}

Fixed version (ground truth):
private long mapPage(int page){
  long address;
  long offset=pageOffset(page);
  long sz=size - offset;
  if (sz > 0) {
    if (sz >= getMapPageSize()) {
      sz=getMapPageSize();
    }
 else {
      this.lastPageSize=sz;
      this.lastPageIndex=page;
    }
    address=ff.mmap(fd,sz,offset,Files.MAP_RO);
    if (address == -1L) {
      throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(sz);
    }
    return cachePageAddress(page,address);
  }
  throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(sz);
}
Program: 30878
Project: 30878
Buggy source:
private void setInitialSize(long size){
  long targetPageSize;
  if (size > maxPageSize) {
    targetPageSize=maxPageSize;
  }
 else {
    targetPageSize=Math.max(ff.getPageSize(),(size / ff.getPageSize()) * ff.getPageSize());
  }
  if (targetPageSize != pageSize) {
    setPageSize(targetPageSize);
    pages.ensureCapacity((int)(size / this.pageSize + 1));
    this.lastPageSize=targetPageSize;
  }
  this.size=size;
}

Fixed version (ground truth):
private void setInitialSize(long size){
  long targetPageSize;
  if (size > maxPageSize) {
    targetPageSize=maxPageSize;
  }
 else {
    targetPageSize=Math.max(ff.getPageSize(),(size / ff.getPageSize()) * ff.getPageSize());
  }
  if (targetPageSize != getMapPageSize()) {
    setPageSize(targetPageSize);
    pages.ensureCapacity((int)(size / getMapPageSize() + 1));
    this.lastPageSize=targetPageSize < size ? targetPageSize : size;
  }
 else {
    this.lastPageSize=targetPageSize;
  }
  this.size=size;
}
Program: 30879
Project: 30879
Buggy source:
@Override public void trackFileSize(){
  long size=ff.length(fd);
  if (size < this.size) {
    setInitialSize(size);
  }
 else   if (size > this.size && lastPageSize < pageSize) {
    pages.ensureCapacity((int)(size / this.pageSize + 1));
    int lastIndex=pages.size() - 1;
    if (lastIndex > -1) {
      long address=pages.getQuick(lastIndex);
      if (address != 0) {
        releaseLast(address);
        pages.setQuick(lastIndex,0);
      }
      clearHotPage();
    }
    this.size=size;
  }
}

Fixed version (ground truth):
@Override public void trackFileSize(){
  long size=ff.length(fd);
  if (size < this.size) {
    setInitialSize(size);
  }
 else   if (size > this.size) {
    pages.ensureCapacity((int)(size / getMapPageSize() + 1));
    if (lastPageSize < getMapPageSize()) {
      int lastIndex=pages.size() - 1;
      if (lastIndex > -1) {
        long address=pages.getQuick(lastIndex);
        if (address != 0) {
          release(lastIndex,address);
          pages.setQuick(lastIndex,0);
        }
        clearHotPage();
      }
      this.lastPageIndex=0;
      this.lastPageSize=getMapPageSize();
    }
    this.size=size;
  }
}
Program: 30880
Project: 30880
Buggy source:
@Override protected void release(long address){
  ff.munmap(address,pageSize);
}

Fixed version (ground truth):
@Override protected void release(int page,long address){
  ff.munmap(address,getPageSize(page));
}
Program: 30881
Project: 30881
Buggy source:
@Override protected long allocateNextPage(int page){
  return mapPage(page);
}

Fixed version (ground truth):
@Override protected long allocateNextPage(int page){
  long address;
  long offset=pageOffset(page);
  final long pageSize=getMapPageSize();
  if (ff.length(fd) < offset + pageSize) {
    ff.truncate(fd,offset + pageSize);
  }
  address=ff.mmap(fd,pageSize,offset,Files.MAP_RW);
  if (address == -1) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(offset).put("String_Node_Str").put(pageSize);
  }
  return address;
}
Program: 30882
Project: 30882
Buggy source:
@Override protected long getPageAddress(int page){
  long address;
  if (page < pages.size()) {
    address=pages.getQuick(page);
    if (address != 0) {
      return address;
    }
  }
  address=mapPage(page);
  cachePageAddress(page,address);
  return address;
}

Fixed version (ground truth):
@Override protected long getPageAddress(int page){
  return mapWritePage(page);
}
Program: 30883
Project: 30883
Buggy source:
protected final void configurePageSize(long size,long defaultPageSize,long maxPageSize){
  if (size > maxPageSize) {
    setPageSize(maxPageSize);
  }
 else {
    setPageSize(Math.max(defaultPageSize,(size / ff.getPageSize()) * ff.getPageSize()));
  }
  pages.ensureCapacity((int)(size / this.pageSize + 1));
  this.size=size;
}

Fixed version (ground truth):
protected final void configurePageSize(long size,long defaultPageSize,long maxPageSize){
  if (size > maxPageSize) {
    setPageSize(maxPageSize);
  }
 else {
    setPageSize(Math.max(defaultPageSize,(size / ff.getPageSize()) * ff.getPageSize()));
  }
  pages.ensureCapacity((int)(size / getMapPageSize() + 1));
  this.size=size;
}
Program: 30884
Project: 30884
Buggy source:
static void resetTxn(VirtualMemory txMem){
  txMem.putLong(-1);
  txMem.putLong(0);
  txMem.putLong(0);
  txMem.putLong(Long.MIN_VALUE);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(0);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(32);
}

Fixed version (ground truth):
static void resetTxn(VirtualMemory txMem){
  txMem.putLong(-1);
  txMem.putLong(0);
  txMem.putLong(0);
  txMem.putLong(Long.MIN_VALUE);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(0);
  txMem.putLong(0);
  Unsafe.getUnsafe().storeFence();
  txMem.jumpTo(TX_EOF);
}
Program: 30885
Project: 30885
Buggy source:
public void of(LPSZ name){
  close();
  boolean exists=ff.exists(name);
  if (!exists) {
    throw CairoException.instance(0).put("String_Node_Str").put(name);
  }
  fd=ff.openRO(name);
  if (fd == -1) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(name);
  }
  LOG.info().$("String_Node_Str").$(name).$("String_Node_Str").$(fd).$(']').$();
  this.lastPageSize=ff.getPageSize();
}

Fixed version (ground truth):
public void of(LPSZ name){
  close();
  boolean exists=ff.exists(name);
  if (!exists) {
    throw CairoException.instance(0).put("String_Node_Str").put(name);
  }
  fd=ff.openRO(name);
  if (fd == -1) {
    throw CairoException.instance(ff.errno()).put("String_Node_Str").put(name);
  }
  LOG.info().$("String_Node_Str").$(name).$("String_Node_Str").$(fd).$(']').$();
}
Program: 30887
Project: 30887
Buggy source:
public TableReader(FilesFacade ff,CharSequence root,CharSequence name){
  this.ff=ff;
  this.path=new CompositePath().of(root).concat(name);
  this.rootLen=path.length();
  failOnPendingTodo();
  this.txMem=openTxnFile();
  this.metaMem=new ReadOnlyMemory(ff);
  openMetaFile();
  this.columnCount=metaMem.getInt(META_OFFSET_COUNT);
  this.columnBlockSize=Numbers.ceilPow2(this.columnCount);
  this.partitionBy=metaMem.getInt(META_OFFSET_PARTITION_BY);
  this.timestampIndex=metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX);
  this.metadata=new Meta(columnCount);
  this.partitionDirFmt=TableWriter.selectPartitionDirFmt(partitionBy);
  countPartitions();
  int columnListCapacity=(this.partitionCount == 1 ? columnCount : columnBlockSize * partitionCount) * 2;
  this.columns=new ObjList<>(columnListCapacity);
  columns.extendAndSet(columnListCapacity - 1,null);
  this.partitionSizes=new LongList(partitionCount);
  this.partitionSizes.seed(partitionCount,-1);
  readTx();
  this.columnTops=new long[columnCount];
}

Fixed version (ground truth):
public TableReader(FilesFacade ff,CharSequence root,CharSequence name){
  this.ff=ff;
  this.path=new CompositePath().of(root).concat(name);
  this.rootLen=path.length();
  failOnPendingTodo();
  this.txMem=openTxnFile();
  this.metaMem=new ReadOnlyMemory(ff);
  openMetaFile();
  this.columnCount=metaMem.getInt(META_OFFSET_COUNT);
  this.columnCountBits=Numbers.msb(Numbers.ceilPow2(this.columnCount) * 2);
  this.partitionBy=metaMem.getInt(META_OFFSET_PARTITION_BY);
  this.timestampIndex=metaMem.getInt(META_OFFSET_TIMESTAMP_INDEX);
  this.metadata=new Meta(columnCount);
  this.partitionDirFmt=TableWriter.selectPartitionDirFmt(partitionBy);
  countPartitions();
  int columnListCapacity=(this.partitionCount == 1 ? columnCount * 2 : partitionCount << columnCountBits);
  this.columns=new ObjList<>(columnListCapacity);
  columns.extendAndSet(columnListCapacity - 1,null);
  this.partitionSizes=new LongList(partitionCount);
  this.partitionSizes.seed(partitionCount,-1);
  readTx();
  this.columnTops=new long[columnCount];
}
Program: 30888
Project: 30888
Buggy source:
@Override public void recordAt(Record record,long atRowId){
}

Fixed version (ground truth):
@Override public void recordAt(Record record,long rowId){
  TableRecord rec=(TableRecord)record;
  rec.columnBase=Rows.toPartitionIndex(rowId) << columnCountBits;
  rec.recordIndex=Rows.toLocalRowID(rowId);
}
Program: 30889
Project: 30889
Buggy source:
private long openPartition(int columnIndex,long partitionTimestamp,boolean last,long[] columnTops){
  try {
    partitionDirFmt.format(partitionTimestamp,DateLocaleFactory.INSTANCE.getDefaultDateLocale(),null,path.put(Path.SEPARATOR));
    final long partitionSize;
    if (ff.exists(path.$())) {
      path.trimTo(path.length());
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize();
      }
      if (partitionSize > 0) {
        openPartitionColumns(columnIndex,partitionSize,columnTops);
      }
    }
 else {
      partitionSize=0;
    }
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}

Fixed version (ground truth):
private long openPartition(int columnBase,long partitionTimestamp,boolean last,long[] columnTops){
  try {
    partitionDirFmt.format(partitionTimestamp,DateLocaleFactory.INSTANCE.getDefaultDateLocale(),null,path.put(Path.SEPARATOR));
    final long partitionSize;
    if (ff.exists(path.$())) {
      path.trimTo(path.length());
      if (last) {
        partitionSize=transientRowCount;
      }
 else {
        partitionSize=readPartitionSize();
      }
      LOG.info().$("String_Node_Str").$(path.$()).$("String_Node_Str").$(partitionSize).$(']').$();
      if (partitionSize > 0) {
        openPartitionColumns(columnBase,partitionSize,columnTops);
      }
    }
 else {
      partitionSize=0;
    }
    return partitionSize;
  }
  finally {
    path.trimTo(rootLen);
  }
}
Program: 30890
Project: 30890
Buggy source:
@Override public Record next(TableReader reader){
  if (++reader.recordIndex < reader.maxRecordIndex) {
    return reader.record;
  }
 else {
    reader.currentRecordFunction=nextPartitionFunction;
    reader.partitionIndex++;
    return reader.record;
  }
}

Fixed version (ground truth):
@Override public Record next(TableReader reader){
  TableReader.TableRecord rec=reader.record;
  if (++rec.recordIndex < rec.maxRecordIndex) {
    return rec;
  }
 else {
    reader.currentRecordFunction=nextPartitionFunction;
    reader.partitionIndex++;
    return rec;
  }
}
Program: 30891
Project: 30891
Buggy source:
@Override public long getRowId(){
  return 0;
}

Fixed version (ground truth):
@Override public long getRowId(){
  return Rows.toRowID(columnBase >>> columnCountBits,recordIndex);
}
Program: 30892
Project: 30892
Buggy source:
@Override public void close(){
  Misc.free(path);
  Misc.free(metaMem);
  Misc.free(txMem);
  for (int i=0, n=columns.size(); i < n; i++) {
    VirtualMemory mem=columns.getQuick(i);
    if (mem != null) {
      mem.close();
    }
  }
}

Fixed version (ground truth):
@Override public void close(){
  Misc.free(path);
  Misc.free(metaMem);
  Misc.free(txMem);
  for (int i=0, n=columns.size(); i < n; i++) {
    VirtualMemory mem=columns.getQuick(i);
    if (mem != null) {
      mem.close();
    }
  }
  if (tempMem8b != 0) {
    Unsafe.free(tempMem8b,8);
    tempMem8b=0;
  }
}
Program: 30893
Project: 30893
Buggy source:
private ReadOnlyMemory colB(int col){
  return columns.getQuick(baseColumnIndex + col * 2 + 1);
}

Fixed version (ground truth):
private ReadOnlyMemory colB(int col){
  return columns.getQuick(columnBase + col * 2 + 1);
}
Program: 30894
Project: 30894
Buggy source:
private ReadOnlyMemory colA(int col){
  return columns.getQuick(baseColumnIndex + col * 2);
}

Fixed version (ground truth):
private ReadOnlyMemory colA(int col){
  return columns.getQuick(columnBase + col * 2);
}
Program: 30895
Project: 30895
Buggy source:
@Override public Record newRecord(){
  return null;
}

Fixed version (ground truth):
@Override public Record newRecord(){
  return new TableRecord();
}
Program: 30896
Project: 30896
Buggy source:
private void readTx(){
  while (true) {
    long txn=txMem.getLong(TableWriter.TX_OFFSET_TXN);
    if (txn == this.txn) {
      break;
    }
    Unsafe.getUnsafe().loadFence();
    long transientRowCount=txMem.getLong(TableWriter.TX_OFFSET_TRANSIENT_ROW_COUNT);
    long fixedRowCount=txMem.getLong(TableWriter.TX_OFFSET_FIXED_ROW_COUNT);
    long maxTimestamp=txMem.getLong(TableWriter.TX_OFFSET_MAX_TIMESTAMP);
    Unsafe.getUnsafe().loadFence();
    if (txn == txMem.getLong(TableWriter.TX_OFFSET_TXN)) {
      this.txn=txn;
      this.transientRowCount=transientRowCount;
      this.size=fixedRowCount + transientRowCount;
      break;
    }
    LockSupport.parkNanos(1);
  }
}

Fixed version (ground truth):
private void readTx(){
  while (true) {
    long txn=txMem.getLong(TableWriter.TX_OFFSET_TXN);
    if (txn == this.txn) {
      break;
    }
    Unsafe.getUnsafe().loadFence();
    long transientRowCount=txMem.getLong(TableWriter.TX_OFFSET_TRANSIENT_ROW_COUNT);
    long fixedRowCount=txMem.getLong(TableWriter.TX_OFFSET_FIXED_ROW_COUNT);
    Unsafe.getUnsafe().loadFence();
    if (txn == txMem.getLong(TableWriter.TX_OFFSET_TXN)) {
      this.txn=txn;
      this.transientRowCount=transientRowCount;
      this.size=fixedRowCount + transientRowCount;
      break;
    }
    LockSupport.parkNanos(1);
  }
}
Program: 30897
Project: 30897
Buggy source:
@Test public void testStringHash() throws Exception {
  Rnd rnd=new Rnd();
  IntHashSet hashes=new IntHashSet(100000);
  final int LEN=30;
  long address=Unsafe.malloc(LEN);
  for (int i=0; i < 100000; i++) {
    rnd.nextChars(address,LEN);
    hashes.add(Hash.hashMem(address,LEN));
  }
  Assert.assertTrue("String_Node_Str",hashes.size() > 99990);
}

Fixed version (ground truth):
@Test public void testStringHash() throws Exception {
  Rnd rnd=new Rnd();
  IntHashSet hashes=new IntHashSet(100000);
  final int LEN=64;
  long address=Unsafe.malloc(LEN);
  for (int i=0; i < 100000; i++) {
    rnd.nextChars(address,LEN / 2);
    hashes.add(Hash.hashMem(address,LEN));
  }
  Assert.assertTrue("String_Node_Str",hashes.size() > 99990);
}
Program: 30898
Project: 30898
Buggy source:
@Test public void testAddColumnTopFileWriteFail() throws Exception {
  testAddColumnRecoverableFault(new FilesFacadeImpl(){
    long fd=-1;
    @Override public long append(    long fd,    long buf,    int len){
      if (this.fd == fd) {
        return -1;
      }
      return super.append(fd,buf,len);
    }
    @Override public long openAppend(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return fd=super.openAppend(name);
      }
      return super.openAppend(name);
    }
  }
);
}

Fixed version (ground truth):
@Test public void testAddColumnTopFileWriteFail() throws Exception {
  testAddColumnRecoverableFault(new FilesFacadeImpl(){
    long fd=-1;
    @Override public long append(    long fd,    long buf,    int len){
      if (fd == this.fd) {
        this.fd=-1;
        return -1;
      }
      return super.append(fd,buf,len);
    }
    @Override public long openAppend(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return fd=super.openAppend(name);
      }
      return super.openAppend(name);
    }
  }
);
}
Program: 30899
Project: 30899
Buggy source:
@Test public void testRemoveColumnCannotMMapSwap() throws Exception {
class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.META_SWAP_FILE_NAME)) {
        return fd=super.openRW(name);
      }
      return super.openRW(name);
    }
    @Override public long mmap(    long fd,    long len,    long offset,    int mode){
      if (fd == this.fd) {
        return -1;
      }
      return super.mmap(fd,len,offset,mode);
    }
  }
  testRemoveColumn(new X());
}

Fixed version (ground truth):
@Test public void testRemoveColumnCannotMMapSwap() throws Exception {
class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.META_SWAP_FILE_NAME)) {
        return fd=super.openRW(name);
      }
      return super.openRW(name);
    }
    @Override public long mmap(    long fd,    long len,    long offset,    int mode){
      if (fd == this.fd) {
        this.fd=-1;
        return -1;
      }
      return super.mmap(fd,len,offset,mode);
    }
  }
  testRemoveColumn(new X());
}
Program: 30900
Project: 30900
Buggy source:
@Test public void testCannotSetAppendPositionOnIndexFile() throws Exception {
  create(FF,PartitionBy.NONE);
  populateTable0(FF);
  testConstructor(new FilesFacadeImpl(){
    long fd;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return fd=super.openRW(name);
      }
      return super.openRW(name);
    }
    @Override public long read(    long fd,    long buf,    int len,    long offset){
      if (fd == this.fd) {
        return -1;
      }
      return super.read(fd,buf,len,offset);
    }
  }
,false);
}

Fixed version (ground truth):
@Test public void testCannotSetAppendPositionOnIndexFile() throws Exception {
  create(FF,PartitionBy.NONE);
  populateTable0(FF);
  testConstructor(new FilesFacadeImpl(){
    long fd;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return fd=super.openRW(name);
      }
      return super.openRW(name);
    }
    @Override public long read(    long fd,    long buf,    int len,    long offset){
      if (fd == this.fd) {
        this.fd=-1;
        return -1;
      }
      return super.read(fd,buf,len,offset);
    }
  }
,false);
}
Program: 30901
Project: 30901
Buggy source:
@Test public void testRemoveColumnUnrecoverableRemoveTodoFailure() throws Exception {
class X extends FilesFacadeImpl {
    int count=1;
    @Override public boolean remove(    LPSZ name){
      return !Chars.endsWith(name,TableWriter.TODO_FILE_NAME) || --count != 0 && super.remove(name);
    }
  }
  testUnrecoverableRemoveColumn(new X());
}

Fixed version (ground truth):
@Test public void testRemoveColumnUnrecoverableRemoveTodoFailure() throws Exception {
class X extends FilesFacadeImpl {
    int count=1;
    @Override public boolean remove(    LPSZ name){
      return (!Chars.endsWith(name,TableWriter.TODO_FILE_NAME) || --count != 0) && super.remove(name);
    }
  }
  testUnrecoverableRemoveColumn(new X());
}