nus-yam/ex-repair huggingface dataset:
Program: 30902
Project: 30902
Buggy source:
@Test public void testCancelFailureFollowedByTableClose() throws Exception {
  long used=Unsafe.getMemUsed();
  create(FF,PartitionBy.DAY);
  Rnd rnd=new Rnd();
  final int N=47;
class X extends FilesFacadeImpl {
    long fd=-1;
    @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 (this.fd == fd) {
        return -1;
      }
      return super.read(fd,buf,len,offset);
    }
  }
  X ff=new X();
  try (TableWriter writer=new TableWriter(ff,root,PRODUCT)){
    long ts=DateFormatUtils.parseDateTime("String_Node_Str");
    for (int i=0; i < N; i++) {
      ts=populateRow(writer,ts,rnd,60 * 60000);
    }
    writer.commit();
    Assert.assertEquals(N,writer.size());
    TableWriter.Row r=writer.newRow(ts + 60 * 60000);
    r.putInt(0,rnd.nextInt());
    try {
      r.cancel();
      Assert.fail();
    }
 catch (    CairoException ignore) {
    }
  }
   try (TableWriter writer=new TableWriter(FF,root,PRODUCT)){
    Assert.assertEquals(N,writer.size());
  }
   Assert.assertEquals(used,Unsafe.getMemUsed());
  Assert.assertEquals(0L,FF.getOpenFileCount());
}

Fixed version (ground truth):
@Test public void testCancelFailureFollowedByTableClose() throws Exception {
  long used=Unsafe.getMemUsed();
  create(FF,PartitionBy.DAY);
  Rnd rnd=new Rnd();
  final int N=47;
class X extends FilesFacadeImpl {
    long fd=-1;
    @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);
    }
  }
  X ff=new X();
  try (TableWriter writer=new TableWriter(ff,root,PRODUCT)){
    long ts=DateFormatUtils.parseDateTime("String_Node_Str");
    for (int i=0; i < N; i++) {
      ts=populateRow(writer,ts,rnd,60 * 60000);
    }
    writer.commit();
    Assert.assertEquals(N,writer.size());
    TableWriter.Row r=writer.newRow(ts + 60 * 60000);
    r.putInt(0,rnd.nextInt());
    try {
      r.cancel();
      Assert.fail();
    }
 catch (    CairoException ignore) {
    }
  }
   try (TableWriter writer=new TableWriter(FF,root,PRODUCT)){
    Assert.assertEquals(N,writer.size());
  }
   Assert.assertEquals(used,Unsafe.getMemUsed());
  Assert.assertEquals(0L,FF.getOpenFileCount());
}
Program: 30903
Project: 30903
Buggy source:
@Test public void testCannotMapTxFile() throws Exception {
  testConstructor(new FilesFacadeImpl(){
    int count=2;
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.TXN_FILE_NAME) && --count == 0) {
        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);
    }
  }
);
}

Fixed version (ground truth):
@Test public void testCannotMapTxFile() throws Exception {
  testConstructor(new FilesFacadeImpl(){
    int count=2;
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.TXN_FILE_NAME) && --count == 0) {
        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);
    }
  }
);
}
Program: 30904
Project: 30904
Buggy source:
@Test public void testAddColumnAndFailToReadTopFile() throws Exception {
  create(FF,PartitionBy.DAY);
  long mem=Unsafe.getMemUsed();
  try (TableWriter writer=new TableWriter(FF,root,PRODUCT)){
    long ts=DateFormatUtils.parseDateTime("String_Node_Str");
    int N=10000;
    Rnd rnd=new Rnd();
    for (int i=0; i < N; i++) {
      ts=populateRow(writer,ts,rnd,60 * 60000);
    }
    writer.addColumn("String_Node_Str",ColumnType.STRING);
    Assert.assertEquals(N,writer.size());
  }
 class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRO(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return this.fd=super.openRO(name);
      }
      return super.openRO(name);
    }
    @Override public long read(    long fd,    long buf,    int len,    long offset){
      if (this.fd == fd) {
        return -1;
      }
      return super.read(fd,buf,len,offset);
    }
  }
  try {
    new TableWriter(new X(),root,PRODUCT);
    Assert.fail();
  }
 catch (  CairoException ignore) {
  }
  Assert.assertEquals(mem,Unsafe.getMemUsed());
  Assert.assertEquals(0,Files.getOpenFileCount());
}

Fixed version (ground truth):
@Test public void testAddColumnAndFailToReadTopFile() throws Exception {
  create(FF,PartitionBy.DAY);
  long mem=Unsafe.getMemUsed();
  try (TableWriter writer=new TableWriter(FF,root,PRODUCT)){
    long ts=DateFormatUtils.parseDateTime("String_Node_Str");
    int N=10000;
    Rnd rnd=new Rnd();
    for (int i=0; i < N; i++) {
      ts=populateRow(writer,ts,rnd,60 * 60000);
    }
    writer.addColumn("String_Node_Str",ColumnType.STRING);
    Assert.assertEquals(N,writer.size());
  }
 class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRO(    LPSZ name){
      if (Chars.endsWith(name,"String_Node_Str")) {
        return this.fd=super.openRO(name);
      }
      return super.openRO(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);
    }
  }
  try {
    new TableWriter(new X(),root,PRODUCT);
    Assert.fail();
  }
 catch (  CairoException ignore) {
  }
  Assert.assertEquals(mem,Unsafe.getMemUsed());
  Assert.assertEquals(0,Files.getOpenFileCount());
}
Program: 30905
Project: 30905
Buggy source:
@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);
}

Fixed version (ground truth):
@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);
}
Program: 30906
Project: 30906
Buggy source:
@Test public void testAddColumnSwpFileMapFail() throws Exception {
  testAddColumnRecoverableFault(new 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);
    }
  }
);
}

Fixed version (ground truth):
@Test public void testAddColumnSwpFileMapFail() throws Exception {
  testAddColumnRecoverableFault(new 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);
    }
  }
);
}
Program: 30907
Project: 30907
Buggy source:
@Test public void testCannotSetAppendPosition() 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 testCannotSetAppendPosition() 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: 30908
Project: 30908
Buggy source:
private void testSetAppendPositionFailure(String failFile) throws NumericException {
  createAllTable();
class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,failFile)) {
        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);
    }
  }
  final X ff=new X();
  long mem=Unsafe.getMemUsed();
  testAppendNulls(new Rnd(),FF,DateFormatUtils.parseDateTime("String_Node_Str"));
  try {
    new TableWriter(ff,root,"String_Node_Str");
    Assert.fail();
  }
 catch (  CairoException ignore) {
  }
  Assert.assertEquals(mem,Unsafe.getMemUsed());
  Assert.assertEquals(0,ff.getOpenFileCount());
}

Fixed version (ground truth):
private void testSetAppendPositionFailure(String failFile) throws NumericException {
  createAllTable();
class X extends FilesFacadeImpl {
    long fd=-1;
    @Override public long openRW(    LPSZ name){
      if (Chars.endsWith(name,failFile)) {
        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);
    }
  }
  final X ff=new X();
  long mem=Unsafe.getMemUsed();
  testAppendNulls(new Rnd(),FF,DateFormatUtils.parseDateTime("String_Node_Str"));
  try {
    new TableWriter(ff,root,"String_Node_Str");
    Assert.fail();
  }
 catch (  CairoException ignore) {
  }
  Assert.assertEquals(mem,Unsafe.getMemUsed());
  Assert.assertEquals(0,ff.getOpenFileCount());
}
Program: 30909
Project: 30909
Buggy source:
@Test public void testConstructorTruncatedTodo() throws Exception {
  FilesFacade ff=new FilesFacadeImpl(){
    long fd=7686876823L;
    @Override public boolean exists(    LPSZ path){
      return Chars.endsWith(path,TableWriter.TODO_FILE_NAME) || super.exists(path);
    }
    @Override public long openRO(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.TODO_FILE_NAME)) {
        return this.fd;
      }
      return super.openRO(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);
    }
  }
;
  populateTable(ff);
}

Fixed version (ground truth):
@Test public void testConstructorTruncatedTodo() throws Exception {
  FilesFacade ff=new FilesFacadeImpl(){
    long fd=7686876823L;
    @Override public boolean exists(    LPSZ path){
      return Chars.endsWith(path,TableWriter.TODO_FILE_NAME) || super.exists(path);
    }
    @Override public long openRO(    LPSZ name){
      if (Chars.endsWith(name,TableWriter.TODO_FILE_NAME)) {
        return this.fd;
      }
      return super.openRO(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);
    }
  }
;
  populateTable(ff);
}
Program: 30910
Project: 30910
Buggy source:
@Override public long append(long fd,long buf,int len){
  if (this.fd == fd) {
    return -1;
  }
  return super.append(fd,buf,len);
}

Fixed version (ground truth):
@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);
}
Program: 30911
Project: 30911
Buggy source:
private void removePartitionDirsNewerThan(long timestamp){
  LOG.info().$("String_Node_Str").$ts(timestamp).$("String_Node_Str").$(path.$()).$();
  try {
    long p=ff.findFirst(path.$());
    if (p > 0) {
      try {
        do {
          long pName=ff.findName(p);
          path.trimTo(rootLen);
          path.concat(pName).$();
          nativeLPSZ.of(pName);
          if (!truncateIgnores.contains(nativeLPSZ)) {
            try {
              long dirTimestamp=partitionDirFmt.parse(nativeLPSZ,partitionDirLocale);
              if (dirTimestamp < timestamp) {
                continue;
              }
            }
 catch (            NumericException ignore) {
            }
            if (ff.rmdir(path)) {
              LOG.info().$("String_Node_Str").$(path).$();
            }
 else {
              throw CairoException.instance(ff.errno()).put("String_Node_Str").put(path);
            }
          }
        }
 while (ff.findNext(p));
      }
  finally {
        ff.findClose(p);
      }
    }
  }
  finally {
    path.trimTo(rootLen);
  }
}

Fixed version (ground truth):
private void removePartitionDirsNewerThan(long timestamp){
  LOG.info().$("String_Node_Str").$ts(timestamp).$("String_Node_Str").$(path.$()).$();
  try {
    long p=ff.findFirst(path.$());
    if (p > 0) {
      try {
        do {
          long pName=ff.findName(p);
          path.trimTo(rootLen);
          path.concat(pName).$();
          nativeLPSZ.of(pName);
          if (!truncateIgnores.contains(nativeLPSZ)) {
            try {
              long dirTimestamp=partitionDirFmt.parse(nativeLPSZ,partitionDirLocale);
              if (dirTimestamp <= timestamp) {
                continue;
              }
            }
 catch (            NumericException ignore) {
            }
            if (ff.rmdir(path)) {
              LOG.info().$("String_Node_Str").$(path).$();
            }
 else {
              throw CairoException.instance(ff.errno()).put("String_Node_Str").put(path);
            }
          }
        }
 while (ff.findNext(p));
      }
  finally {
        ff.findClose(p);
      }
    }
  }
  finally {
    path.trimTo(rootLen);
  }
}
Program: 30912
Project: 30912
Buggy source:
private void indexZones(String[][] zones,TimeZoneRuleFactory timeZoneRuleFactory,CharSequenceHashSet cache){
  for (int i=0, n=zones.length; i < n; i++) {
    String[] zNames=zones[i];
    String key=zNames[0];
    int index=timeZoneRuleFactory.getTimeZoneRulesIndex(key);
    if (index == -1) {
      continue;
    }
    for (int k=1, m=zNames.length; k < m; k++) {
      String name=zNames[k];
      if (cache.add(name)) {
        defineToken(name,index,this.zones);
      }
    }
  }
}

Fixed version (ground truth):
private void indexZones(String[][] zones,TimeZoneRuleFactory timeZoneRuleFactory,CharSequenceHashSet cache){
  if (cache.add("String_Node_Str")) {
    int index=timeZoneRuleFactory.getTimeZoneRulesIndex("String_Node_Str");
    if (index != -1) {
      defineToken("String_Node_Str",index,this.zones);
    }
  }
  for (int i=0, n=zones.length; i < n; i++) {
    String[] zNames=zones[i];
    String key=zNames[0];
    int index=timeZoneRuleFactory.getTimeZoneRulesIndex(key);
    if (index == -1) {
      continue;
    }
    for (int k=1, m=zNames.length; k < m; k++) {
      String name=zNames[k];
      if (cache.add(name)) {
        defineToken(name,index,this.zones);
      }
    }
  }
}
Program: 30913
Project: 30913
Buggy source:
@Override public CharSequence getFlyweightStrB(int col){
  return colA(col).getStr2(colB(col).getLong(baseOffset * 8));
}

Fixed version (ground truth):
@Override public CharSequence getFlyweightStrB(int col){
  return colA(col).getStr2(colB(col).getLong(recordIndex * 8));
}
Program: 30914
Project: 30914
Buggy source:
@Override public long getBinLen(int col){
  return colA(col).getLong(colB(col).getLong(baseOffset * 8));
}

Fixed version (ground truth):
@Override public long getBinLen(int col){
  return colA(col).getLong(colB(col).getLong(recordIndex * 8));
}
Program: 30915
Project: 30915
Buggy source:
@Override public double getDouble(int col){
  return colA(col).getDouble(baseOffset * 8);
}

Fixed version (ground truth):
@Override public double getDouble(int col){
  return colA(col).getDouble(recordIndex * 8);
}
Program: 30916
Project: 30916
Buggy source:
@Override public float getFloat(int col){
  return colA(col).getFloat(baseOffset * 4);
}

Fixed version (ground truth):
@Override public float getFloat(int col){
  return colA(col).getFloat(recordIndex * 4);
}
Program: 30917
Project: 30917
Buggy source:
@Override public CharSequence getFlyweightStr(int col){
  return colA(col).getStr(colB(col).getLong(baseOffset * 8));
}

Fixed version (ground truth):
@Override public CharSequence getFlyweightStr(int col){
  return colA(col).getStr(colB(col).getLong(recordIndex * 8));
}
Program: 30918
Project: 30918
Buggy source:
@Override public byte get(int col){
  return colA(col).getByte(baseOffset);
}

Fixed version (ground truth):
@Override public byte get(int col){
  return colA(col).getByte(recordIndex);
}
Program: 30919
Project: 30919
Buggy source:
@Override public long getDate(int col){
  return colA(col).getLong(baseOffset * 8);
}

Fixed version (ground truth):
@Override public long getDate(int col){
  return colA(col).getLong(recordIndex * 8);
}
Program: 30920
Project: 30920
Buggy source:
@Override public void close() throws IOException {
  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();
    }
  }
}
Program: 30921
Project: 30921
Buggy source:
@Override public boolean getBool(int col){
  return colA(col).getBool(baseOffset);
}

Fixed version (ground truth):
@Override public boolean getBool(int col){
  return colA(col).getBool(recordIndex);
}
Program: 30922
Project: 30922
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();
  this.txMem=openTxnFile();
  if (readTodoTaskCode() != -1) {
    throw CairoException.instance(0).put("String_Node_Str").put(path.$()).put("String_Node_Str");
  }
  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.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];
}
Program: 30923
Project: 30923
Buggy source:
@Override public short getShort(int col){
  return colA(col).getShort(baseOffset * 2);
}

Fixed version (ground truth):
@Override public short getShort(int col){
  return colA(col).getShort(recordIndex * 2);
}
Program: 30924
Project: 30924
Buggy source:
private void countPartitions(){
  if (partitionDirFmt == null) {
    partitionCount=1;
    return;
  }
  partitionMin=Long.MAX_VALUE;
  long partitionMax=Long.MIN_VALUE;
  try {
    long p=ff.findFirst(path.$());
    if (p > 0) {
      try {
        do {
          int type=ff.findType(p);
          if (type == Files.DT_DIR || type == Files.DT_LNK) {
            try {
              long time=partitionDirFmt.parse(nativeLPSZ.of(ff.findName(p)),DateLocaleFactory.INSTANCE.getDefaultDateLocale());
              if (time < partitionMin) {
                partitionMin=time;
              }
              if (time > partitionMax) {
                partitionMax=time;
              }
            }
 catch (            NumericException e) {
              e.printStackTrace();
            }
          }
        }
 while (ff.findNext(p));
      }
  finally {
        ff.findClose(p);
      }
    }
  }
  finally {
    path.trimTo(rootLen);
  }
  if (partitionMin == Long.MAX_VALUE) {
    partitionCount=1;
    return;
  }
switch (partitionBy) {
case PartitionBy.YEAR:
    partitionCount=(int)Dates.getYearsBetween(partitionMin,partitionMax) + 1;
  break;
case PartitionBy.MONTH:
partitionCount=(int)Dates.getMonthsBetween(partitionMin,partitionMax) + 1;
break;
case PartitionBy.DAY:
partitionCount=(int)Dates.getDaysBetween(partitionMin,partitionMax) + 1;
break;
default :
break;
}
}

Fixed version (ground truth):
private void countPartitions(){
  if (partitionDirFmt == null) {
    partitionCount=1;
    return;
  }
  partitionMin=Long.MAX_VALUE;
  long partitionMax=Long.MIN_VALUE;
  try {
    long p=ff.findFirst(path.$());
    if (p > 0) {
      try {
        do {
          int type=ff.findType(p);
          if (type == Files.DT_DIR || type == Files.DT_LNK) {
            try {
              long time=partitionDirFmt.parse(nativeLPSZ.of(ff.findName(p)),DateLocaleFactory.INSTANCE.getDefaultDateLocale());
              if (time < partitionMin) {
                partitionMin=time;
              }
              if (time > partitionMax) {
                partitionMax=time;
              }
            }
 catch (            NumericException ignore) {
            }
          }
        }
 while (ff.findNext(p));
      }
  finally {
        ff.findClose(p);
      }
    }
  }
  finally {
    path.trimTo(rootLen);
  }
  if (partitionMin == Long.MAX_VALUE) {
    partitionCount=1;
    return;
  }
switch (partitionBy) {
case PartitionBy.YEAR:
    partitionCount=(int)Dates.getYearsBetween(partitionMin,partitionMax) + 1;
  break;
case PartitionBy.MONTH:
partitionCount=(int)Dates.getMonthsBetween(partitionMin,partitionMax) + 1;
break;
case PartitionBy.DAY:
partitionCount=(int)Dates.getDaysBetween(partitionMin,partitionMax) + 1;
break;
default :
break;
}
}
Program: 30925
Project: 30925
Buggy source:
@Override public long getLong(int col){
  return colA(col).getLong(baseOffset * 8);
}

Fixed version (ground truth):
@Override public long getLong(int col){
  return colA(col).getLong(recordIndex * 8);
}
Program: 30926
Project: 30926
Buggy source:
@Override public int getInt(int col){
  return colA(col).getInt(baseOffset * 4);
}

Fixed version (ground truth):
@Override public int getInt(int col){
  return colA(col).getInt(recordIndex * 4);
}
Program: 30927
Project: 30927
Buggy source:
@Override public int getStrLen(int col){
  return colA(col).getInt(colB(col).getLong(baseOffset * 8));
}

Fixed version (ground truth):
@Override public int getStrLen(int col){
  return colA(col).getInt(colB(col).getLong(recordIndex * 8));
}
Program: 30928
Project: 30928
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;
      this.maxTimestamp=maxTimestamp;
      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);
    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);
  }
}
Program: 30930
Project: 30930
Buggy source:
private void commitPendingPartitions(){
  long offset=8;
  for (int i=0; i < txPartitionCount - 1; i++) {
    try {
      long partitionTimestamp=columnSizeMem.getLong(offset);
      offset+=8;
      setStateForTimestamp(partitionTimestamp,false);
      long fd=openAppend(path.concat(ARCHIVE_FILE_NAME).$());
      try {
        int len=8;
        while (len > 0) {
          long l=Math.min(len,columnSizeMem.pageRemaining(offset));
          if (ff.write(fd,columnSizeMem.addressOf(offset),l,0) == -1) {
            throw CairoException.instance(ff.errno()).put("String_Node_Str").put(path);
          }
          len-=l;
          offset+=l;
        }
      }
  finally {
        ff.close(fd);
      }
    }
  finally {
      path.trimTo(rootLen);
    }
  }
}

Fixed version (ground truth):
private void commitPendingPartitions(){
  long offset=0;
  for (int i=0; i < txPartitionCount - 1; i++) {
    try {
      long partitionTimestamp=columnSizeMem.getLong(offset + 8);
      setStateForTimestamp(partitionTimestamp,false);
      long fd=openAppend(path.concat(ARCHIVE_FILE_NAME).$());
      try {
        int len=8;
        long o=offset;
        while (len > 0) {
          long l=Math.min(len,columnSizeMem.pageRemaining(o));
          if (ff.write(fd,columnSizeMem.addressOf(o),l,0) != l) {
            throw CairoException.instance(ff.errno()).put("String_Node_Str").put(path);
          }
          len-=l;
          o+=l;
        }
      }
  finally {
        ff.close(fd);
      }
      offset+=16;
    }
  finally {
      path.trimTo(rootLen);
    }
  }
}
Program: 30931
Project: 30931
Buggy source:
/** 
 * path member variable has to be set to location of "top" file.
 * @return number of rows column doesn't have when column was added to table that already had data.
 */
static long readColumnTop(FilesFacade ff,CompositePath path,CharSequence name,int plen){
  try {
    if (ff.exists(topFile(path,name))) {
      long fd=ff.openRO(path);
      try {
        long buf=Unsafe.malloc(8);
        try {
          if (ff.read(fd,buf,8,0) != 8) {
            throw CairoException.instance(Os.errno()).put("String_Node_Str").put(path);
          }
          return Unsafe.getUnsafe().getLong(buf);
        }
  finally {
          Unsafe.free(buf,8);
        }
      }
  finally {
        ff.close(fd);
      }
    }
    return 0L;
  }
  finally {
    path.trimTo(plen);
  }
}

Fixed version (ground truth):
/** 
 * path member variable has to be set to location of "top" file.
 * @return number of rows column doesn't have when column was added to table that already had data.
 */
static long readColumnTop(FilesFacade ff,CompositePath path,CharSequence name,int plen){
  try {
    path.trimTo(path.length());
    if (ff.exists(topFile(path,name))) {
      long fd=ff.openRO(path);
      try {
        long buf=Unsafe.malloc(8);
        try {
          if (ff.read(fd,buf,8,0) != 8) {
            throw CairoException.instance(Os.errno()).put("String_Node_Str").put(path);
          }
          return Unsafe.getUnsafe().getLong(buf);
        }
  finally {
          Unsafe.free(buf,8);
        }
      }
  finally {
        ff.close(fd);
      }
    }
    return 0L;
  }
  finally {
    path.trimTo(plen);
  }
}
Program: 30932
Project: 30932
Buggy source:
private void cancelRow(){
  if ((masterRef & 1) == 0) {
    return;
  }
  if (transientRowCount == 0) {
    if (partitionBy != PartitionBy.NONE) {
      closeColumns(false);
      if (removeDirOnCancelRow) {
        try {
          setStateForTimestamp(maxTimestamp,false);
          if (!ff.rmdir(path.$())) {
            throw CairoException.instance(Os.errno()).put("String_Node_Str").put(path);
          }
          removeDirOnCancelRow=false;
        }
  finally {
          path.trimTo(rootLen);
        }
      }
      if (prevTimestamp > Long.MIN_VALUE) {
        columnSizeMem.jumpTo((txPartitionCount - 2) * 16);
        openPartition(prevTimestamp);
        setAppendPosition(prevTransientRowCount);
        txPartitionCount--;
      }
 else {
        rowFunction=openPartitionFunction;
      }
      transientRowCount=prevTransientRowCount;
      fixedRowCount-=prevTransientRowCount;
      maxTimestamp=prevTimestamp;
      removeDirOnCancelRow=true;
    }
 else {
      for (int i=0; i < columnCount; i++) {
        getPrimaryColumn(i).jumpTo(0);
        AppendMemory mem=getSecondaryColumn(i);
        if (mem != null) {
          mem.jumpTo(0);
        }
      }
    }
  }
 else {
    maxTimestamp=prevTimestamp;
    boolean rowChanged=false;
    for (int i=0; i < columnCount; i++) {
      if (refs.getQuick(i) == masterRef) {
        rowChanged=true;
        break;
      }
    }
    if (rowChanged) {
      setAppendPosition(transientRowCount);
    }
  }
  masterRef--;
}

Fixed version (ground truth):
private void cancelRow(){
  if ((masterRef & 1) == 0) {
    return;
  }
  if (transientRowCount == 0) {
    if (partitionBy != PartitionBy.NONE) {
      closeColumns(false);
      if (removeDirOnCancelRow) {
        try {
          setStateForTimestamp(maxTimestamp,false);
          if (!ff.rmdir(path.$())) {
            throw CairoException.instance(Os.errno()).put("String_Node_Str").put(path);
          }
          removeDirOnCancelRow=false;
        }
  finally {
          path.trimTo(rootLen);
        }
      }
      if (prevTimestamp > Long.MIN_VALUE) {
        try {
          columnSizeMem.jumpTo((txPartitionCount - 2) * 16);
          openPartition(prevTimestamp);
          setAppendPosition(prevTransientRowCount);
          txPartitionCount--;
        }
 catch (        CairoException e) {
          closeColumns(false);
          throw e;
        }
      }
 else {
        rowFunction=openPartitionFunction;
      }
      transientRowCount=prevTransientRowCount;
      fixedRowCount-=prevTransientRowCount;
      maxTimestamp=prevTimestamp;
      removeDirOnCancelRow=true;
    }
 else {
      for (int i=0; i < columnCount; i++) {
        getPrimaryColumn(i).jumpTo(0);
        AppendMemory mem=getSecondaryColumn(i);
        if (mem != null) {
          mem.jumpTo(0);
        }
      }
    }
  }
 else {
    maxTimestamp=prevTimestamp;
    boolean rowChanged=false;
    for (int i=0; i < columnCount; i++) {
      if (refs.getQuick(i) == masterRef) {
        rowChanged=true;
        break;
      }
    }
    if (rowChanged) {
      setAppendPosition(transientRowCount);
    }
  }
  masterRef--;
}
Program: 30933
Project: 30933
Buggy source:
private long mapPage(int page){
  long target=pageOffset(page + 1);
  if (Files.length(fd) < target && !Files.truncate(fd,target)) {
    throw new RuntimeException("String_Node_Str");
  }
  return Files.mmap(fd,pageSize,pageOffset(page),Files.MAP_RW);
}

Fixed version (ground truth):
private long mapPage(int page){
  long target=pageOffset(page + 1);
  if (Files.length(fd) < target && !Files.truncate(fd,target)) {
    throw CairoException.instance(Os.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(target);
  }
  return Files.mmap(fd,pageSize,pageOffset(page),Files.MAP_RW);
}
Program: 30934
Project: 30934
Buggy source:
public final void of(LPSZ name,long pageSize){
  close();
  setPageSize(pageSize);
  fd=Files.openRW(name);
  if (fd == -1) {
    throw new RuntimeException("String_Node_Str");
  }
}

Fixed version (ground truth):
public final void of(LPSZ name,long pageSize){
  close();
  setPageSize(pageSize);
  fd=Files.openRW(name);
  if (fd == -1) {
    throw CairoException.instance(Os.errno()).put("String_Node_Str").put(name);
  }
  LOG.info().$("String_Node_Str").$(name).$("String_Node_Str").$(fd).$(']').$();
}
Program: 30935
Project: 30935
Buggy source:
@Override protected long mapWritePage(int page){
  releaseCurrentPage();
  long address=mapPage(page);
  if (address == -1) {
    throw new RuntimeException("String_Node_Str");
  }
  return pageAddress=address;
}

Fixed version (ground truth):
@Override protected long mapWritePage(int page){
  releaseCurrentPage();
  long address=mapPage(page);
  if (address == -1) {
    throw CairoException.instance(Os.errno()).put("String_Node_Str").put(fd).put("String_Node_Str").put(pageOffset(page));
  }
  return pageAddress=address;
}
Program: 30936
Project: 30936
Buggy source:
public void of(LPSZ name,long maxPageSize,long size){
  close();
  this.size=size;
  this.lastPageSize=Files.PAGE_SIZE;
  boolean exists=Files.exists(name);
  if (!exists) {
    throw new RuntimeException("String_Node_Str");
  }
  fd=Files.openRO(name);
  if (fd == -1) {
    throw new RuntimeException("String_Node_Str");
  }
  if (size > maxPageSize) {
    setPageSize(maxPageSize);
  }
 else {
    setPageSize(Math.max(Files.PAGE_SIZE,(size / Files.PAGE_SIZE) * Files.PAGE_SIZE));
  }
  pages.ensureCapacity((int)(size / this.pageSize + 1));
}

Fixed version (ground truth):
public void of(LPSZ name,long maxPageSize,long size){
}
Program: 30937
Project: 30937
Buggy source:
public TableWriter(CharSequence root,CharSequence name){
  this.path=new CompositePath().of(root).concat(name);
  this.rootLen=path.length();
  metaMem.of(path.concat("String_Node_Str").$(),Files.PAGE_SIZE,0);
  this.columnCount=metaMem.getInt(0);
  this.partitionBy=metaMem.getInt(4);
  this.refs.extendAndSet(columnCount,0);
  this.nullers=new Runnable[columnCount];
  path.trimTo(rootLen);
  configureColumnMemory();
  configureAppendPosition();
}

Fixed version (ground truth):
public TableWriter(CharSequence root,CharSequence name){
  this.path=new CompositePath().of(root).concat(name);
  this.rootLen=path.length();
  path.concat("String_Node_Str").$();
  metaMem.of(path,Files.PAGE_SIZE,Files.length(path));
  this.columnCount=metaMem.getInt(0);
  this.partitionBy=metaMem.getInt(4);
  this.refs.extendAndSet(columnCount,0);
  this.nullers=new Runnable[columnCount];
  path.trimTo(rootLen);
  configureColumnMemory();
  configureAppendPosition();
}
Program: 30938
Project: 30938
Buggy source:
@Test public void testParseLargeFile() throws Exception {
  Path p=new Path(JsonLexerTest.class.getResource("String_Node_Str").getPath());
  long l=Files.length(p);
  long fd=Files.openRO(p);
  JsonListener listener=new NoOpListener();
  try {
    long buf=Unsafe.malloc(l);
    try {
      Files.read(fd,buf,(int)l,0);
      JsonLexer lexer=new JsonLexer(1024);
      long t=System.nanoTime();
      for (int i=0; i < l; i++) {
        try {
          lexer.clear();
          lexer.parse(buf,i,listener);
          lexer.parse(buf + i,l - i,listener);
          lexer.parseLast();
        }
 catch (        JsonException e) {
          System.out.println(i);
          throw e;
        }
      }
      System.out.println((System.nanoTime() - t) / l);
    }
  finally {
      Unsafe.free(buf,l);
    }
  }
  finally {
    Files.close(fd);
  }
}

Fixed version (ground truth):
@Test public void testParseLargeFile() throws Exception {
  Path p=new Path(JsonLexerTest.class.getResource("String_Node_Str").getPath());
  long l=Files.length(p);
  long fd=Files.openRO(p);
  JsonListener listener=new NoOpListener();
  try {
    long buf=Unsafe.malloc(l);
    try {
      Assert.assertEquals(l,Files.read(fd,buf,(int)l,0));
      JsonLexer lexer=new JsonLexer(1024);
      long t=System.nanoTime();
      for (int i=0; i < l; i++) {
        try {
          lexer.clear();
          lexer.parse(buf,i,listener);
          lexer.parse(buf + i,l - i,listener);
          lexer.parseLast();
        }
 catch (        JsonException e) {
          System.out.println(i);
          throw e;
        }
      }
      System.out.println((System.nanoTime() - t) / l);
    }
  finally {
      Unsafe.free(buf,l);
    }
  }
  finally {
    Files.close(fd);
  }
}
Program: 30939
Project: 30939
Buggy source:
@Override public void clear(){
  objDepthStack.clear();
  arrayDepthStack.clear();
  state=S_START;
  objDepth=0;
  arrayDepth=0;
}

Fixed version (ground truth):
@Override public void clear(){
  objDepthStack.clear();
  arrayDepthStack.clear();
  state=S_START;
  objDepth=0;
  arrayDepth=0;
  ignoreNext=false;
  quoted=false;
  cacheSize=0;
  useCache=false;
}
Program: 30941
Project: 30941
Buggy source:
@Override public CharSequence getFlyweightStrB(Record rec){
  csB.init(lhs.getFlyweightStrB(rec),rhs.getFlyweightStrB(rec));
  return csB;
}

Fixed version (ground truth):
@Override public CharSequence getFlyweightStrB(Record rec){
  return csB.of(lhs.getFlyweightStrB(rec),rhs.getFlyweightStrB(rec));
}
Program: 30942
Project: 30942
Buggy source:
@Override public CharSequence getFlyweightStr(Record rec){
  csA.init(lhs.getFlyweightStr(rec),rhs.getFlyweightStr(rec));
  return csA;
}

Fixed version (ground truth):
@Override public CharSequence getFlyweightStr(Record rec){
  return csA.of(lhs.getFlyweightStr(rec),rhs.getFlyweightStr(rec));
}
Program: 30943
Project: 30943
Buggy source:
private void assertError(String expected,int expectedPosition,String input) throws JsonException {
  int len=input.length();
  long address=Unsafe.malloc(len);
  try {
    Chars.strcpy(input,len,address);
    try {
      parser.parse(address,len,listener);
      Assert.fail();
    }
 catch (    JsonException e) {
      Assert.assertEquals(expected,e.getMessage());
      Assert.assertEquals(expectedPosition,e.getPosition());
    }
  }
  finally {
    Unsafe.free(address,len);
  }
}

Fixed version (ground truth):
private void assertError(String expected,int expectedPosition,String input) throws JsonException {
  int len=input.length();
  long address=Unsafe.malloc(len);
  try {
    Chars.strcpy(input,len,address);
    try {
      parser.parse(address,len,listener);
      parser.parseLast();
      Assert.fail();
    }
 catch (    JsonException e) {
      Assert.assertEquals(expected,e.getMessage());
      Assert.assertEquals(expectedPosition,e.getPosition());
    }
  }
  finally {
    Unsafe.free(address,len);
  }
}
Program: 30944
Project: 30944
Buggy source:
private void assertThat(String expected,String input) throws JsonException {
  int len=input.length();
  long address=Unsafe.malloc(len);
  try {
    Chars.strcpy(input,len,address);
    parser.parse(address,len,listener);
    TestUtils.assertEquals(expected,listener.value());
  }
  finally {
    Unsafe.free(address,len);
  }
}

Fixed version (ground truth):
private void assertThat(String expected,String input) throws JsonException {
  int len=input.length();
  long address=Unsafe.malloc(len);
  try {
    Chars.strcpy(input,len,address);
    parser.parse(address,len,listener);
    parser.parseLast();
    TestUtils.assertEquals(expected,listener.value());
  }
  finally {
    Unsafe.free(address,len);
  }
}
Program: 30945
Project: 30945
Buggy source:
private void sendVanilla(IOContext context,LPSZ path,CharSequence contentType,boolean asAttachment) throws IOException {
  long fd=Files.openRO(path);
  if (fd == -1) {
    LOG.info().$("String_Node_Str").$(path).$('(').$(Os.errno()).$(')').$();
    context.simpleResponse().send(404);
  }
 else {
    FileDescriptorHolder h=lvFd.get(context);
    if (h == null) {
      lvFd.set(context,h=new FileDescriptorHolder());
    }
    h.fd=fd;
    h.bytesSent=0;
    final long length=Files.length(path);
    h.sendMax=Long.MAX_VALUE;
    final FixedSizeResponse r=context.fixedSizeResponse();
    r.status(200,contentType,length);
    if (asAttachment) {
      r.headers().put("String_Node_Str").put(path).put("String_Node_Str").put(Misc.EOL);
    }
    r.headers().put("String_Node_Str").put('"').put(Files.getLastModified(path)).put('"').put(Misc.EOL);
    r.sendHeader();
    resume(context);
  }
}

Fixed version (ground truth):
private void sendVanilla(IOContext context,LPSZ path,CharSequence contentType,boolean asAttachment) throws IOException {
  long fd=Files.openRO(path);
  if (fd == -1) {
    LOG.info().$("String_Node_Str").$(path).$('(').$(Os.errno()).$(')').$();
    context.simpleResponse().send(404);
  }
 else {
    FileDescriptorHolder h=lvFd.get(context);
    if (h == null) {
      lvFd.set(context,h=new FileDescriptorHolder());
    }
    h.fd=fd;
    h.bytesSent=0;
    final long length=Files.length(path);
    h.sendMax=Long.MAX_VALUE;
    final FixedSizeResponse r=context.fixedSizeResponse();
    r.status(200,contentType,length);
    if (asAttachment) {
      r.headers().put("String_Node_Str").put(FileNameExtractorCharSequence.get(path)).put("String_Node_Str").put(Misc.EOL);
    }
    r.headers().put("String_Node_Str").put('"').put(Files.getLastModified(path)).put('"').put(Misc.EOL);
    r.sendHeader();
    resume(context);
  }
}
Program: 30946
Project: 30946
Buggy source:
private void writeNullString(long headerAddress){
  long addr=mem.allocate(4);
  Unsafe.getUnsafe().putLong(headerAddress,addr);
  Unsafe.getUnsafe().putInt(addr,-1);
}

Fixed version (ground truth):
private void writeNullString(long headerAddress){
  long addr=mem.allocate(4);
  Unsafe.getUnsafe().putLong(headerAddress,addr);
  Unsafe.getUnsafe().putInt(addr,VariableColumn.NULL_LEN);
}
Program: 30947
Project: 30947
Buggy source:
private void writeRec0(long addr,Record record){
  int varOffset=this.varOffset;
  for (int i=0, n=slaveValueIndexes.size(); i < n; i++) {
    int idx=slaveValueIndexes.getQuick(i);
    long address=addr + fixedOffsets.getQuick(i);
switch (slaveValueTypes.getQuick(i)) {
case ColumnType.INT:
case ColumnType.SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(idx));
    break;
case ColumnType.LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(idx));
break;
case ColumnType.FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(idx));
break;
case ColumnType.DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(idx));
break;
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
Unsafe.getUnsafe().putByte(address,record.get(idx));
break;
case ColumnType.SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(idx));
break;
case ColumnType.DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(idx));
break;
case ColumnType.STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
varOffset+=Chars.strcpyw(record.getFlyweightStr(idx),addr + varOffset);
break;
default :
break;
}
}
}

Fixed version (ground truth):
private void writeRec0(long addr,Record record){
  int varOffset=this.varOffset;
  for (int i=0, n=slaveValueIndexes.size(); i < n; i++) {
    int idx=slaveValueIndexes.getQuick(i);
    long address=addr + fixedOffsets.getQuick(i);
switch (slaveValueTypes.getQuick(i)) {
case ColumnType.INT:
case ColumnType.SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(idx));
    break;
case ColumnType.LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(idx));
break;
case ColumnType.FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(idx));
break;
case ColumnType.DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(idx));
break;
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
Unsafe.getUnsafe().putByte(address,record.get(idx));
break;
case ColumnType.SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(idx));
break;
case ColumnType.DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(idx));
break;
case ColumnType.STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
CharSequence cs=record.getFlyweightStr(idx);
if (cs == null) {
Unsafe.getUnsafe().putInt(addr + varOffset,VariableColumn.NULL_LEN);
varOffset+=4;
}
 else {
varOffset+=Chars.strcpyw(record.getFlyweightStr(idx),addr + varOffset);
}
break;
default :
break;
}
}
}
Program: 30948
Project: 30948
Buggy source:
public void write(Record record){
  this.held=true;
  int sz=varOffset;
  for (int i=0, n=strCols.size(); i < n; i++) {
    sz+=record.getStrLen(strCols.getQuick(i)) * 2 + 4;
  }
  if (sz > size) {
    alloc(sz);
  }
  int varOffset=this.varOffset;
  for (int i=0, n=types.size(); i < n; i++) {
    long address=this.address + offsets.getQuick(i);
switch (types.getQuick(i)) {
case ColumnType.INT:
case ColumnType.SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(i));
    break;
case ColumnType.LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(i));
break;
case ColumnType.FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(i));
break;
case ColumnType.DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(i));
break;
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
Unsafe.getUnsafe().putByte(address,record.get(i));
break;
case ColumnType.SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(i));
break;
case ColumnType.DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(i));
break;
case ColumnType.STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
varOffset+=Chars.strcpyw(record.getFlyweightStr(i),this.address + varOffset);
break;
default :
break;
}
}
}

Fixed version (ground truth):
public void write(Record record){
  this.held=true;
  int sz=varOffset;
  for (int i=0, n=strCols.size(); i < n; i++) {
    sz+=record.getStrLen(strCols.getQuick(i)) * 2 + 4;
  }
  if (sz > size) {
    alloc(sz);
  }
  int varOffset=this.varOffset;
  for (int i=0, n=types.size(); i < n; i++) {
    long address=this.address + offsets.getQuick(i);
switch (types.getQuick(i)) {
case ColumnType.INT:
case ColumnType.SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(i));
    break;
case ColumnType.LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(i));
break;
case ColumnType.FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(i));
break;
case ColumnType.DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(i));
break;
case ColumnType.BOOLEAN:
case ColumnType.BYTE:
Unsafe.getUnsafe().putByte(address,record.get(i));
break;
case ColumnType.SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(i));
break;
case ColumnType.DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(i));
break;
case ColumnType.STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
CharSequence cs=record.getFlyweightStr(i);
if (cs == null) {
Unsafe.getUnsafe().putInt(this.address + varOffset,VariableColumn.NULL_LEN);
varOffset+=4;
}
 else {
varOffset+=Chars.strcpyw(cs,this.address + varOffset);
}
break;
default :
break;
}
}
}