nus-yam/ex-repair huggingface dataset:
Program: 31520
Project: 31520
Buggy source:
@SuppressWarnings("String_Node_Str") private void process(SocketChannel channel,IOContext context,int op){
  Request r=context.request;
  Request.ChannelStatus status;
  try {
    while ((status=r.read(channel)) == Request.ChannelStatus.NEED_REQUEST) {
    }
    final Response response=context.response;
    response.setChannel(channel);
    if (status == Request.ChannelStatus.READY) {
      ContextHandler handler=handlers.get(r.getUrl());
      if (handler != null) {
        if (r.isMultipart()) {
          if (handler instanceof MultipartListener) {
            handler.onHeaders(r,response);
            feedMultipartContent((MultipartListener)handler,r,channel);
            handler.onComplete(r,response);
          }
 else {
          }
        }
      }
 else {
      }
    }
  }
 catch (  HeadersTooLargeException|InvalidMultipartHeader e) {
    status=Request.ChannelStatus.DISCONNECTED;
  }
catch (  SlowChannelException e) {
    status=Request.ChannelStatus.READY;
  }
catch (  IOException e) {
    status=Request.ChannelStatus.DISCONNECTED;
    e.printStackTrace();
  }
catch (  UnsupportedContentTypeException e) {
    context.clear();
    status=Request.ChannelStatus.READY;
  }
  if (status != Request.ChannelStatus.DISCONNECTED) {
    loop.registerChannel(channel,SelectionKey.OP_READ,context);
  }
 else {
    try {
      channel.close();
      context.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}

Fixed version (ground truth):
@SuppressWarnings("String_Node_Str") private void process(SocketChannel channel,IOContext context,int op){
  Request r=context.request;
  Request.ChannelStatus status;
  try {
    while ((status=r.read(channel)) == Request.ChannelStatus.NEED_REQUEST) {
    }
    final Response response=context.response;
    response.setChannel(channel);
    if (status == Request.ChannelStatus.READY) {
      ContextHandler handler=handlers.get(r.getUrl());
      if (handler != null) {
        if (r.isMultipart()) {
          if (handler instanceof MultipartListener) {
            handler.onHeaders(r,response);
            feedMultipartContent((MultipartListener)handler,r,channel);
            handler.onComplete(r,response);
            r.clear();
          }
 else {
          }
        }
      }
 else {
      }
    }
  }
 catch (  HeadersTooLargeException|InvalidMultipartHeader e) {
    status=Request.ChannelStatus.DISCONNECTED;
  }
catch (  SlowChannelException e) {
    status=Request.ChannelStatus.READY;
  }
catch (  IOException e) {
    status=Request.ChannelStatus.DISCONNECTED;
    e.printStackTrace();
  }
catch (  UnsupportedContentTypeException e) {
    context.clear();
    status=Request.ChannelStatus.READY;
  }
  if (status != Request.ChannelStatus.DISCONNECTED) {
    loop.registerChannel(channel,SelectionKey.OP_READ,context);
  }
 else {
    try {
      channel.close();
      context.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}
Program: 31521
Project: 31521
Buggy source:
private void configure(SocketChannel channel) throws IOException {
  channel.configureBlocking(false);
  channel.setOption(StandardSocketOptions.TCP_NODELAY,Boolean.TRUE);
  channel.setOption(StandardSocketOptions.SO_RCVBUF,ZERO);
  channel.register(selector,SelectionKey.OP_READ).attach(new IOContext());
}

Fixed version (ground truth):
private void configure(SocketChannel channel) throws IOException {
  channel.configureBlocking(false);
  channel.setOption(StandardSocketOptions.TCP_NODELAY,Boolean.TRUE);
  channel.setOption(StandardSocketOptions.SO_RCVBUF,1024 * 1024);
  channel.register(selector,SelectionKey.OP_READ).attach(new IOContext());
}
Program: 31523
Project: 31523
Buggy source:
@Override public void clear(){
  this.needMethod=true;
  this._wptr=this._lo=this.headerPtr;
  pool.clear();
  this.incomplete=true;
  this.headers.clear();
  this.method=null;
  this.url=null;
  this.n=null;
}

Fixed version (ground truth):
@Override public void clear(){
  this.needMethod=true;
  this._wptr=this._lo=this.headerPtr;
  this.incomplete=true;
  this.headers.clear();
  this.method=null;
  this.url=null;
  this.n=null;
}
Program: 31524
Project: 31524
Buggy source:
public Response(int headerBufferSize,int contentBufferSize){
  if (headerBufferSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (contentBufferSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  int sz=Numbers.ceilPow2(contentBufferSize);
  this.out=ByteBuffer.allocateDirect(sz);
  this.hb=new ResponseHeaderBuffer(headerBufferSize);
  this.chunkHeader=ByteBuffer.allocateDirect((int)Math.log10(sz) + 5);
  this.outPtr=this._wptr=((DirectBuffer)out).address();
  this.limit=outPtr + sz;
}

Fixed version (ground truth):
public Response(int headerBufferSize,int contentBufferSize){
  if (headerBufferSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (contentBufferSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  int sz=Numbers.ceilPow2(contentBufferSize);
  this.out=ByteBuffer.allocateDirect(sz);
  this.hb=new ResponseHeaderBuffer(headerBufferSize);
  this.chunkHeader=ByteBuffer.allocateDirect(8 + 2 * EOL.length());
  this.chunkSink=new DirectUnboundedAnsiSink(((DirectBuffer)chunkHeader).address());
  this.chunkSink.put(EOL);
  this.outPtr=this._wptr=((DirectBuffer)out).address();
  this.limit=outPtr + sz;
}
Program: 31525
Project: 31525
Buggy source:
public void flush() throws IOException {
  int lim=(int)(_wptr - outPtr);
  if (lim > 0) {
    chunk(lim);
    out.limit(lim);
    channel.write(out);
    out.clear();
    _wptr=outPtr;
  }
}

Fixed version (ground truth):
public void flush() throws IOException {
  int lim=(int)(_wptr - outPtr);
  if (lim > 0) {
    chunk(lim);
    out.limit(lim);
    MultipartParser.dump(out);
    channel.write(out);
    out.clear();
    _wptr=outPtr;
  }
}
Program: 31526
Project: 31526
Buggy source:
private void chunk(int len) throws IOException {
  chunkHeader.clear();
  String h=EOL + Integer.toHexString(len) + EOL;
  for (int i=0; i < h.length(); i++) {
    chunkHeader.put((byte)h.charAt(i));
  }
  chunkHeader.flip();
  channel.write(chunkHeader);
}

Fixed version (ground truth):
private void chunk(int len) throws IOException {
  chunkHeader.clear();
  chunkSink.clear(EOL.length());
  Numbers.appendHex(chunkSink,len);
  chunkSink.put(EOL);
  chunkHeader.limit(chunkSink.length());
  MultipartParser.dump(chunkHeader);
  channel.write(chunkHeader);
}
Program: 31527
Project: 31527
Buggy source:
void flush(WritableByteChannel channel) throws IOException {
  headers.limit((int)(_wptr - headerPtr));
  channel.write(headers);
  headers.clear();
}

Fixed version (ground truth):
void flush(WritableByteChannel channel) throws IOException {
  headers.limit((int)(_wptr - headerPtr));
  MultipartParser.dump(headers);
  channel.write(headers);
  headers.clear();
}
Program: 31528
Project: 31528
Buggy source:
private int writeRec(Record record,long offset){
  return writeRec0(pages.getQuick(pageIndex(offset)) + pageOffset(offset) + 4,record) + 4;
}

Fixed version (ground truth):
private void writeRec(Record record,long offset){
  writeRec0(pages.getQuick(pageIndex(offset)) + pageOffset(offset) + 4,record);
}
Program: 31529
Project: 31529
Buggy source:
public void put(Record record){
  final MapValues values=getBySlave(record);
  int size=varOffset;
  for (int i=0, n=varColumns.size(); i < n; i++) {
    size+=record.getStrLen(varColumns.getQuick(i)) * 2 + 4;
  }
  if (size > maxRecordSize) {
    throw new JournalRuntimeException("String_Node_Str");
  }
  if (values.isNew()) {
    values.putLong(0,appendOffset);
    appendOffset+=appendRec(record,size);
  }
 else {
    long offset=values.getLong(0);
    int pgInx=pageIndex(offset);
    int pgOfs=pageOffset(offset);
    int oldSize=Unsafe.getUnsafe().getInt(pages.getQuick(pgInx) + pgOfs);
    if (size > oldSize) {
      freeList.add(offset,oldSize);
      if (freeList.getTotalSize() < maxRecordSize) {
        values.putLong(0,appendOffset);
        appendOffset+=appendRec(record,size);
      }
 else {
        long _offset=freeList.findAndRemove(size);
        if (_offset == -1) {
          appendOffset+=appendRec(record,size);
        }
 else {
          writeRec(record,_offset);
        }
      }
    }
 else {
      writeRec(record,offset);
    }
  }
}

Fixed version (ground truth):
public void put(Record record){
  final MapValues values=getBySlave(record);
  int size=varOffset;
  for (int i=0, n=varColumns.size(); i < n; i++) {
    size+=record.getStrLen(varColumns.getQuick(i)) * 2 + 4;
  }
  if (size > maxRecordSize) {
    throw new JournalRuntimeException("String_Node_Str");
  }
  if (values.isNew()) {
    appendRec(record,size,values);
  }
 else {
    long offset=values.getLong(0);
    int pgInx=pageIndex(offset);
    int pgOfs=pageOffset(offset);
    int oldSize=Unsafe.getUnsafe().getInt(pages.getQuick(pgInx) + pgOfs);
    if (size > oldSize) {
      freeList.add(offset,oldSize);
      if (freeList.getTotalSize() < maxRecordSize) {
        appendRec(record,size,values);
      }
 else {
        long _offset=freeList.findAndRemove(size);
        if (_offset == -1) {
          appendRec(record,size,values);
        }
 else {
          writeRec(record,_offset);
        }
      }
    }
 else {
      writeRec(record,offset);
    }
  }
}
Program: 31530
Project: 31530
Buggy source:
private int appendRec(Record record,int size){
  int pgInx=pageIndex(appendOffset);
  int pgOfs=pageOffset(appendOffset);
  if (pgOfs + size > pageSize) {
    pgInx++;
    pgOfs=0;
  }
  if (pgInx == pages.size()) {
    pages.add(Unsafe.getUnsafe().allocateMemory(pageSize));
  }
  long addr=pages.getQuick(pgInx) + pgOfs;
  Unsafe.getUnsafe().putInt(addr,size + size / 10);
  return writeRec0(addr + 4,record) + 4;
}

Fixed version (ground truth):
private void appendRec(Record record,int size,MapValues values){
  int pgInx=pageIndex(appendOffset);
  int pgOfs=pageOffset(appendOffset);
  size=size + 4 + size / 10;
  if (pgOfs + size > pageSize) {
    pgInx++;
    pgOfs=0;
    values.putLong(0,appendOffset=(pgInx * pageSize));
  }
 else {
    values.putLong(0,appendOffset);
  }
  appendOffset+=size;
  if (pgInx == pages.size()) {
    pages.add(Unsafe.getUnsafe().allocateMemory(pageSize));
  }
  long addr=pages.getQuick(pgInx) + pgOfs;
  Unsafe.getUnsafe().putInt(addr,size - 4);
  writeRec0(addr + 4,record);
}
Program: 31531
Project: 31531
Buggy source:
private int pageOffset(long offset){
  return (int)(offset % pageSize);
}

Fixed version (ground truth):
private int pageOffset(long offset){
  return (int)(offset & mask);
}
Program: 31533
Project: 31533
Buggy source:
private int 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 INT:
case SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(idx));
    break;
case LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(idx));
break;
case FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(idx));
break;
case DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(idx));
break;
case BOOLEAN:
case BYTE:
Unsafe.getUnsafe().putByte(address,record.get(idx));
break;
case SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(idx));
break;
case DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(idx));
break;
case STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
varOffset+=writeStr(addr + varOffset,record.getFlyweightStr(idx));
break;
}
}
return varOffset;
}

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 INT:
case SYMBOL:
      Unsafe.getUnsafe().putInt(address,record.getInt(idx));
    break;
case LONG:
  Unsafe.getUnsafe().putLong(address,record.getLong(idx));
break;
case FLOAT:
Unsafe.getUnsafe().putFloat(address,record.getFloat(idx));
break;
case DOUBLE:
Unsafe.getUnsafe().putDouble(address,record.getDouble(idx));
break;
case BOOLEAN:
case BYTE:
Unsafe.getUnsafe().putByte(address,record.get(idx));
break;
case SHORT:
Unsafe.getUnsafe().putShort(address,record.getShort(idx));
break;
case DATE:
Unsafe.getUnsafe().putLong(address,record.getDate(idx));
break;
case STRING:
Unsafe.getUnsafe().putInt(address,varOffset);
varOffset+=writeStr(addr + varOffset,record.getFlyweightStr(idx));
break;
}
}
}
Program: 31534
Project: 31534
Buggy source:
private int pageIndex(long offset){
  return (int)(offset / pageSize);
}

Fixed version (ground truth):
private int pageIndex(long offset){
  return (int)(offset >> bits);
}
Program: 31535
Project: 31535
Buggy source:
@Override public Record next(){
  Record master=masterCursor.next();
  record.setA(master);
  long ts=master.getDate(masterTimestampIndex);
  if (delayedSlave != null) {
    map.put(delayedSlave);
    delayedSlave=null;
  }
  while (slaveCursor.hasNext()) {
    Record slave=slaveCursor.next();
    if (ts > slave.getDate(slaveTimestampIndex)) {
      map.put(slave);
    }
 else {
      record.setB(map.get(master));
      delayedSlave=slave;
      return record;
    }
  }
  record.setB(null);
  return record;
}

Fixed version (ground truth):
@Override public Record next(){
  Record master=masterCursor.next();
  record.setA(master);
  long ts=master.getDate(masterTimestampIndex);
  if (delayedSlave != null) {
    if (ts > delayedSlave.getDate(slaveTimestampIndex)) {
      map.put(delayedSlave);
      delayedSlave=null;
    }
 else {
      record.setB(null);
      return record;
    }
  }
  while (slaveCursor.hasNext()) {
    Record slave=slaveCursor.next();
    if (ts > slave.getDate(slaveTimestampIndex)) {
      map.put(slave);
    }
 else {
      record.setB(map.get(master));
      delayedSlave=slave;
      return record;
    }
  }
  record.setB(null);
  return record;
}
Program: 31536
Project: 31536
Buggy source:
public AsOfJoinRecordSource(RecordSource<? extends Record> master,int masterTimestampIndex,RecordSource<? extends Record> slave,int slaveTimestampIndex,ObjList<CharSequence> keyColumns){
  this.master=master;
  this.masterTimestampIndex=masterTimestampIndex;
  this.slave=slave;
  this.slaveTimestampIndex=slaveTimestampIndex;
  this.map=new LastVarRecordMap(master.getMetadata(),slave.getMetadata(),keyColumns,4 * 1024 * 1024);
  this.metadata=new SplitRecordMetadata(master.getMetadata(),map.getMetadata());
  this.record=new SplitRecord(this.metadata,master.getMetadata().getColumnCount());
}

Fixed version (ground truth):
public AsOfJoinRecordSource(RecordSource<? extends Record> master,int masterTimestampIndex,RecordSource<? extends Record> slave,int slaveTimestampIndex,ObjList<CharSequence> keyColumns,int pageSize){
  this.master=master;
  this.masterTimestampIndex=masterTimestampIndex;
  this.slave=slave;
  this.slaveTimestampIndex=slaveTimestampIndex;
  this.map=new LastVarRecordMap(master.getMetadata(),slave.getMetadata(),keyColumns,pageSize);
  this.metadata=new SplitRecordMetadata(master.getMetadata(),map.getMetadata());
  this.record=new SplitRecord(this.metadata,master.getMetadata().getColumnCount());
}
Program: 31537
Project: 31537
Buggy source:
@Test public void testJoin() throws Exception {
  final String expected="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
  AsOfJoinRecordSource source=new AsOfJoinRecordSource(compiler.compileSource("String_Node_Str"),0,compiler.compileSource("String_Node_Str"),0,new ObjList<CharSequence>(){
{
      add("String_Node_Str");
    }
  }
);
  printer.printCursor(source.prepareCursor(factory));
  TestUtils.assertEquals(expected,sink);
}

Fixed version (ground truth):
@Test public void testJoin() throws Exception {
  final String expected="String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str";
  AsOfJoinRecordSource source=new AsOfJoinRecordSource(compiler.compileSource("String_Node_Str"),0,compiler.compileSource("String_Node_Str"),0,new ObjList<CharSequence>(){
{
      add("String_Node_Str");
    }
  }
,512);
  printer.printCursor(source.prepareCursor(factory));
  TestUtils.assertEquals(expected,sink);
}
Program: 31538
Project: 31538
Buggy source:
public void clear(int capacity){
  ensureCapacity(capacity);
  pos=0;
  Arrays.fill(buffer,noEntryValue);
}

Fixed version (ground truth):
public void clear(){
  pos=0;
  Arrays.fill(buffer,noEntryValue);
}
Program: 31539
Project: 31539
Buggy source:
public RecordSource<? extends Record> compileSource(CharSequence query) throws ParserException, JournalException {
  RecordSource<? extends Record> rs=cache.get(query);
  if (rs == null) {
    rs=builder.resetAndCompile(parser.parse(query).getQueryModel(),factory);
  }
 else {
    rs.reset();
  }
  return rs;
}

Fixed version (ground truth):
public RecordSource<? extends Record> compileSource(CharSequence query) throws ParserException, JournalException {
  RecordSource<? extends Record> rs=cache.get(query);
  if (rs == null) {
    rs=builder.resetAndCompile(parser.parse(query).getQueryModel(),factory);
    cache.put(query,rs);
  }
 else {
    rs.reset();
  }
  return rs;
}
Program: 31540
Project: 31540
Buggy source:
public DirectPagedBuffer(int pageCapacity){
  this.pageCapacity=Numbers.ceilPow2(pageCapacity);
  this.bits=31 - Integer.numberOfLeadingZeros(this.pageCapacity);
  this.mask=this.pageCapacity - 1;
  pages=new LongList();
  allocateAddress();
}

Fixed version (ground truth):
public DirectPagedBuffer(int pageCapacity){
  this.pageCapacity=Numbers.ceilPow2(pageCapacity);
  this.bits=31 - Integer.numberOfLeadingZeros(this.pageCapacity);
  this.mask=this.pageCapacity - 1;
  pages=new LongList();
  allocateAddress(0);
}
Program: 31541
Project: 31541
Buggy source:
public long getWriteOffsetWithChecks(long length){
  if (cachePageLo + length > cachePageHi) {
    allocateAddressChecked(length);
  }
  return (cachePageLo+=length) - length;
}

Fixed version (ground truth):
public long getWriteOffsetWithChecks(long length){
  if (cachePageLo + length > cachePageHi) {
    allocateAddressChecked((cachePageLo + length) >>> bits,length);
  }
  return (cachePageLo+=length) - length;
}
Program: 31542
Project: 31542
Buggy source:
private long allocatePage(){
  pages.add(Unsafe.getUnsafe().allocateMemory(pageCapacity));
  return (pages.size() - 1) << bits;
}

Fixed version (ground truth):
private long allocatePage(int index){
  pages.add(Unsafe.getUnsafe().allocateMemory(pageCapacity));
  return (pages.size() - 1) << bits;
}
Program: 31543
Project: 31543
Buggy source:
public void clear(){
  cachePageLo=pages.get(0);
  cachePageHi=cachePageLo + pageCapacity;
}

Fixed version (ground truth):
public void clear(){
  cachePageLo=0;
  cachePageHi=cachePageLo + pageCapacity;
  for (int i=0; i < pages.size(); i++) {
    long address=pages.getQuick(i);
    if (address != 0) {
      Unsafe.getUnsafe().freeMemory(address);
    }
  }
  pages.clear();
  allocateAddress(0);
}
Program: 31544
Project: 31544
Buggy source:
private void allocateAddress(){
  cachePageLo=allocatePage();
  cachePageHi=cachePageLo + pageCapacity;
}

Fixed version (ground truth):
private void allocateAddress(long index){
  if (index > Integer.MAX_VALUE) {
    throw new OutOfMemoryError();
  }
  cachePageLo=allocatePage((int)index);
  cachePageHi=cachePageLo + pageCapacity;
}
Program: 31545
Project: 31545
Buggy source:
private void allocateAddressChecked(long length){
  if (length > pageCapacity) {
    throw new JournalRuntimeException("String_Node_Str",length,pageCapacity);
  }
  allocateAddress();
}

Fixed version (ground truth):
private void allocateAddressChecked(long index,long length){
  if (length > pageCapacity) {
    throw new JournalRuntimeException("String_Node_Str",length,pageCapacity);
  }
  allocateAddress(index);
}
Program: 31546
Project: 31546
Buggy source:
@Override public void close() throws IOException {
  if (pages != null) {
    for (int i=0; i < pages.size(); i++) {
      long address=pages.get(i);
      if (address != 0) {
        Unsafe.getUnsafe().freeMemory(address);
      }
    }
    pages=null;
  }
}

Fixed version (ground truth):
@Override public void close() throws IOException {
  clear();
}
Program: 31547
Project: 31547
Buggy source:
public long toAddress(long offset){
  return pages.get((int)(offset >> bits)) + (offset & mask);
}

Fixed version (ground truth):
public long toAddress(long offset){
  return pages.get((int)(offset >>> bits)) + (offset & mask);
}
Program: 31548
Project: 31548
Buggy source:
public long getWriteOffsetQuick(long length){
  if (cachePageLo + length > cachePageHi) {
    allocateAddress();
  }
  return (cachePageLo+=length) - length;
}

Fixed version (ground truth):
public long getWriteOffsetQuick(long length){
  if (cachePageLo + length > cachePageHi) {
    allocateAddress((cachePageLo + length) >>> bits);
  }
  return (cachePageLo+=length) - length;
}
Program: 31549
Project: 31549
Buggy source:
public void clear(){
  buffer.clear();
}

Fixed version (ground truth):
public void clear(){
  buffer.clear();
  readOffset=-1;
}
Program: 31550
Project: 31550
Buggy source:
public void clear(){
  kPos=kStart;
  free=(int)(keyCapacity * loadFactor);
  size=0;
  offsets.clear((byte)-1);
}

Fixed version (ground truth):
public void clear(){
  kPos=kStart;
  free=(int)(keyCapacity * loadFactor);
  size=0;
  offsets.fill(-1);
}
Program: 31551
Project: 31551
Buggy source:
public void clear(){
  map.clear();
}

Fixed version (ground truth):
public void clear(){
  map.clear();
  records.clear();
}
Program: 31552
Project: 31552
Buggy source:
@Override public PartitionCursor prepareCursor(JournalReaderFactory factory) throws JournalException {
  this.journal=factory.reader(metadata).select();
  storageFacade.setJournal(journal);
  storageFacade.setFactory(factory);
  partitionCount=journal.getPartitionCount();
  partitionIndex=0;
  return this;
}

Fixed version (ground truth):
@Override public PartitionCursor prepareCursor(JournalReaderFactory factory) throws JournalException {
  this.journal=factory.reader(metadata);
  storageFacade.setJournal(journal);
  storageFacade.setFactory(factory);
  partitionCount=journal.getPartitionCount();
  partitionIndex=0;
  return this;
}
Program: 31553
Project: 31553
Buggy source:
@Override public RecordCursor<Record> prepareCursor(JournalReaderFactory factory) throws JournalException {
  this.recordCursor=recordSource.prepareCursor(factory);
  return this;
}

Fixed version (ground truth):
@Override public RecordCursor<Record> prepareCursor(JournalReaderFactory factory) throws JournalException {
  this.recordCursor=recordSource.prepareCursor(factory);
  current.prepare(recordCursor.getSymFacade());
  return this;
}
Program: 31554
Project: 31554
Buggy source:
@SuppressFBWarnings({"String_Node_Str"}) public static FunctionFactory find(Signature sig,ObjList<VirtualColumn> args){
  if (Chars.equals("String_Node_Str",sig.name) && sig.paramCount == 2 && sig.paramTypes.getQuick(1) == ColumnType.DOUBLE && args.getQuick(1).isConstant()) {
    double d=args.getQuick(1).getDouble(null);
    if (d != d) {
switch (sig.paramTypes.getQuick(0)) {
case DOUBLE:
        return DoubleEqualsNaNOperatorFactory.INSTANCE;
case INT:
      return IntEqualsNaNOperatorFactory.INSTANCE;
case LONG:
    return LongEqualsNaNOperatorFactory.INSTANCE;
}
}
}
FunctionFactory factory=factories.get(sig);
if (factory != null) {
return factory;
}
 else {
if (sig.paramCount < 3 && Chars.equals("String_Node_Str",sig.name)) {
switch (sig.paramTypes.get(0)) {
case STRING:
  return StrInOperatorFactory.INSTANCE;
case SYMBOL:
return SymInOperatorFactory.INSTANCE;
}
}
 else if (sig.paramCount > 2 && Chars.equals("String_Node_Str",sig.name)) {
switch (sig.paramTypes.getLast()) {
case STRING:
return StrInOperatorFactory.INSTANCE;
case SYMBOL:
return SymInOperatorFactory.INSTANCE;
}
}
}
return null;
}

Fixed version (ground truth):
@SuppressFBWarnings({"String_Node_Str"}) public static FunctionFactory find(Signature sig,ObjList<VirtualColumn> args){
  if (Chars.equals("String_Node_Str",sig.name) && sig.paramCount == 2 && sig.paramTypes.getQuick(1) == ColumnType.DOUBLE && args.getQuick(1).isConstant()) {
    double d=args.getQuick(1).getDouble(null);
    if (d != d) {
switch (sig.paramTypes.getQuick(0)) {
case DOUBLE:
        return DoubleEqualsNaNOperatorFactory.INSTANCE;
case INT:
      return IntEqualsNaNOperatorFactory.INSTANCE;
case LONG:
    return LongEqualsNaNOperatorFactory.INSTANCE;
}
}
}
FunctionFactory factory=factories.get(sig);
if (factory != null) {
return factory;
}
 else {
if (Chars.equals("String_Node_Str",sig.name)) {
switch (sig.paramTypes.getQuick(0)) {
case STRING:
  return StrInOperatorFactory.INSTANCE;
case SYMBOL:
return SymInOperatorFactory.INSTANCE;
}
}
}
return null;
}
Program: 31555
Project: 31555
Buggy source:
private void createColumn(ExprNode node,RecordMetadata metadata) throws ParserException {
  Signature sig=new Signature();
  ObjList<VirtualColumn> args=new ObjList<>();
  int argCount=node.paramCount;
  sig.clear();
switch (argCount) {
case 0:
switch (node.type) {
case LITERAL:
      stack.addFirst(lookupColumn(node,metadata));
    break;
case CONSTANT:
  stack.addFirst(parseConstant(node));
break;
default :
stack.addFirst(lookupFunction(node,sig.setName(node.token).setParamCount(0),null));
}
break;
default :
args.ensureCapacity(argCount);
sig.setName(node.token).setParamCount(argCount);
for (int n=0; n < argCount; n++) {
VirtualColumn c=stack.pollFirst();
if (c == null) {
throw new ParserException(node.position,"String_Node_Str");
}
sig.paramType(n,c.getType(),c.isConstant());
args.setQuick(n,c);
}
stack.addFirst(lookupFunction(node,sig,args));
}
}

Fixed version (ground truth):
private void createColumn(ExprNode node,RecordMetadata metadata) throws ParserException {
  ObjList<VirtualColumn> args=new ObjList<>();
  int argCount=node.paramCount;
  mutableSig.clear();
switch (argCount) {
case 0:
switch (node.type) {
case LITERAL:
      stack.addFirst(lookupColumn(node,metadata));
    break;
case CONSTANT:
  stack.addFirst(parseConstant(node));
break;
default :
stack.addFirst(lookupFunction(node,mutableSig.setName(node.token).setParamCount(0),null));
}
break;
default :
args.ensureCapacity(argCount);
mutableSig.setName(node.token).setParamCount(argCount);
for (int n=0; n < argCount; n++) {
VirtualColumn c=stack.pollFirst();
if (c == null) {
throw new ParserException(node.position,"String_Node_Str");
}
mutableSig.paramType(n,c.getType(),c.isConstant());
args.setQuick(n,c);
}
stack.addFirst(lookupFunction(node,mutableSig,args));
}
}
Program: 31556
Project: 31556
Buggy source:
public RecordSource<? extends Record> compile(QueryModel model) throws ParserException, JournalException {
  RecordSource<? extends Record> rs=createRecordSource(model);
  RecordMetadata meta=rs.getMetadata();
  ObjList<QueryColumn> columns=model.getColumns();
  ObjList<VirtualColumn> virtualColumns=new ObjList<>();
  ObjList<String> selectedColumns=new ObjList<>();
  int columnSequence=0;
  for (int i=0, k=columns.size(); i < k; i++) {
    QueryColumn qc=columns.getQuick(i);
    ExprNode node=qc.getAst();
switch (node.type) {
case LITERAL:
      if (meta.invalidColumn(node.token)) {
        throw new InvalidColumnException(node.position);
      }
    selectedColumns.add(node.token);
  break;
default :
String colName=qc.getName() == null ? "String_Node_Str" + columnSequence++ : qc.getName();
VirtualColumn c=createVirtualColumn(qc.getAst(),rs.getMetadata());
c.setName(colName);
selectedColumns.add(colName);
virtualColumns.add(c);
}
}
if (virtualColumns.size() > 0) {
rs=new VirtualColumnRecordSource(rs,virtualColumns);
}
return new SelectedColumnsRecordSource(rs,selectedColumns);
}

Fixed version (ground truth):
public RecordSource<? extends Record> compile(QueryModel model,JournalReaderFactory factory) throws ParserException, JournalException {
  RecordSource<? extends Record> rs=createRecordSource(model,factory);
  RecordMetadata meta=rs.getMetadata();
  ObjList<QueryColumn> columns=model.getColumns();
  ObjList<VirtualColumn> virtualColumns=new ObjList<>();
  ObjList<String> selectedColumns=new ObjList<>();
  int columnSequence=0;
  for (int i=0, k=columns.size(); i < k; i++) {
    QueryColumn qc=columns.getQuick(i);
    ExprNode node=qc.getAst();
switch (node.type) {
case LITERAL:
      if (meta.invalidColumn(node.token)) {
        throw new InvalidColumnException(node.position);
      }
    selectedColumns.add(node.token);
  break;
default :
String colName=qc.getName() == null ? "String_Node_Str" + columnSequence++ : qc.getName();
VirtualColumn c=createVirtualColumn(qc.getAst(),rs.getMetadata());
c.setName(colName);
selectedColumns.add(colName);
virtualColumns.add(c);
}
}
if (virtualColumns.size() > 0) {
rs=new VirtualColumnRecordSource(rs,virtualColumns);
}
return new SelectedColumnsRecordSource(rs,selectedColumns);
}
Program: 31558
Project: 31558
Buggy source:
private VirtualColumn lookupFunction(ExprNode node,Signature sig,ObjList<VirtualColumn> args) throws ParserException {
  FunctionFactory factory=FunctionFactories.find(sig,args);
  if (factory == null) {
    throw new ParserException(node.position,"String_Node_Str" + sig);
  }
  Function f=factory.newInstance(args);
  if (args != null) {
    int n=node.paramCount;
    for (int i=0; i < n; i++) {
      f.setArg(i,args.getQuick(i));
    }
  }
  return f.isConstant() ? processConstantExpression(f) : f;
}

Fixed version (ground truth):
private VirtualColumn lookupFunction(ExprNode node,Signature sig,ObjList<VirtualColumn> args) throws ParserException {
  FunctionFactory factory=FunctionFactories.find(sig,args);
  if (factory == null) {
    throw new ParserException(node.position,"String_Node_Str" + sig.userReadable());
  }
  Function f=factory.newInstance(args);
  if (args != null) {
    int n=node.paramCount;
    for (int i=0; i < n; i++) {
      f.setArg(i,args.getQuick(i));
    }
  }
  return f.isConstant() ? processConstantExpression(f) : f;
}
Program: 31559
Project: 31559
Buggy source:
private void closeChannels(){
  while (channels.size() > 0) {
    closeChannel(channels.remove(0),true);
  }
}

Fixed version (ground truth):
private void closeChannels(){
  for (  SocketChannelHolder h : channels) {
    closeChannel(h,true);
  }
  channels.clear();
}
Program: 31560
Project: 31560
Buggy source:
public long next(){
  int r=(int)(++rowCount & mask);
  if (r > 0) {
    return Unsafe.getUnsafe().getLong(address + ((r - 1) << 3));
  }
 else {
    remainingBlockCount--;
    this.address=rData.getAddress(Unsafe.getUnsafe().getLong(address + (rowBlockLen << 3)) - rowBlockSize,rowBlockSize);
    return Unsafe.getUnsafe().getLong(address + (r << 3));
  }
}

Fixed version (ground truth):
public long next(){
  int r=(int)(rowCount++ & mask);
  long v=Unsafe.getUnsafe().getLong(address + (r << 3));
  if (r == mask) {
    this.address=rData.getAddress(Unsafe.getUnsafe().getLong(address + (rowBlockLen << 3)) - rowBlockSize,rowBlockSize);
  }
  return v;
}
Program: 31561
Project: 31561
Buggy source:
public FwdIndexCursor setKey(int key){
  this.remainingBlockCount=0;
  this.rowCount=0;
  this.size=0;
  if (key < 0) {
    return this;
  }
  long keyOffset=getKeyOffset(key);
  if (keyOffset >= firstEntryOffset + keyBlockSize) {
    return this;
  }
  long addr=kData.getAddress(keyOffset,ENTRY_SIZE);
  this.size=Unsafe.getUnsafe().getLong(addr + 8);
  if (size == 0) {
    return this;
  }
  this.remainingBlockCount=(int)(this.size >>> bits);
  this.rowCount=0;
  this.address=rData.getAddress(Unsafe.getUnsafe().getLong(addr + 16) - rowBlockSize,rowBlockSize);
  return this;
}

Fixed version (ground truth):
public FwdIndexCursor setKey(int key){
  this.rowCount=0;
  this.size=0;
  if (key < 0) {
    return this;
  }
  long keyOffset=getKeyOffset(key);
  if (keyOffset >= firstEntryOffset + keyBlockSize) {
    return this;
  }
  long addr=kData.getAddress(keyOffset,ENTRY_SIZE);
  this.size=Unsafe.getUnsafe().getLong(addr + 8);
  if (size == 0) {
    return this;
  }
  this.rowCount=0;
  this.address=rData.getAddress(Unsafe.getUnsafe().getLong(addr + 16) - rowBlockSize,rowBlockSize);
  return this;
}
Program: 31562
Project: 31562
Buggy source:
public boolean hasNext(){
  return this.rowCount < size || this.remainingBlockCount > 0;
}

Fixed version (ground truth):
public boolean hasNext(){
  return this.rowCount < size;
}
Program: 31563
Project: 31563
Buggy source:
private void assertValues(long values[][],KVIndex index){
  for (int i=0; i < values.length; i++) {
    try (DirectLongList array=index.getValues(i)){
      Assert.assertEquals(values[i].length,array.size());
      for (int k=0; k < values[i].length; k++) {
        Assert.assertEquals(values[i][k],array.get(k));
      }
      IndexCursor cursor=index.cursor(i);
      int k=(int)cursor.size();
      while (cursor.hasNext()) {
        Assert.assertEquals(values[i][--k],cursor.next());
      }
      IndexCursor c=index.fwdCursor(i);
      while (c.hasNext()) {
        System.out.println(c.next());
      }
    }
   }
}

Fixed version (ground truth):
private void assertValues(long values[][],KVIndex index){
  for (int i=0; i < values.length; i++) {
    try (DirectLongList array=index.getValues(i)){
      Assert.assertEquals(values[i].length,array.size());
      for (int k=0; k < values[i].length; k++) {
        Assert.assertEquals(values[i][k],array.get(k));
      }
      IndexCursor cursor=index.cursor(i);
      int k=(int)cursor.size();
      while (cursor.hasNext()) {
        Assert.assertEquals(values[i][--k],cursor.next());
      }
      IndexCursor c=index.fwdCursor(i);
      int n=0;
      while (c.hasNext()) {
        long l=c.next();
        Assert.assertEquals(values[i][n++],l);
      }
    }
   }
}
Program: 31565
Project: 31565
Buggy source:
public Key commit(){
  Unsafe.getUnsafe().putInt(startAddr,len=(int)(appendAddr - startAddr));
  kPos=appendAddr;
  return this;
}

Fixed version (ground truth):
public KeyWriter commit(){
  Unsafe.getUnsafe().putInt(startAddr,len=(int)(appendAddr - startAddr));
  kPos=appendAddr;
  return this;
}
Program: 31566
Project: 31566
Buggy source:
public Key putLong(long value){
  checkSize(8);
  Unsafe.getUnsafe().putLong(appendAddr,value);
  appendAddr+=8;
  writeOffset();
  return this;
}

Fixed version (ground truth):
public KeyWriter putLong(long value){
  checkSize(8);
  Unsafe.getUnsafe().putLong(appendAddr,value);
  appendAddr+=8;
  writeOffset();
  return this;
}
Program: 31567
Project: 31567
Buggy source:
private MapValues probe0(Key key,int index){
  long offset;
  while ((offset=offsets.get(index=(++index % keyCapacity))) != -1) {
    if (eq(key,offset)) {
      kPos=key.startAddr;
      return values.init(kStart + offset,false);
    }
  }
  offsets.set(index,key.startAddr - kStart);
  free--;
  if (free == 0) {
    rehash();
  }
  size++;
  return values.init(key.startAddr,true);
}

Fixed version (ground truth):
private MapValues probe0(KeyWriter keyWriter,int index){
  long offset;
  while ((offset=offsets.get(index=(++index % keyCapacity))) != -1) {
    if (eq(keyWriter,offset)) {
      kPos=keyWriter.startAddr;
      return values.init(kStart + offset,false);
    }
  }
  offsets.set(index,keyWriter.startAddr - kStart);
  free--;
  if (free == 0) {
    rehash();
  }
  size++;
  return values.init(keyWriter.startAddr,true);
}
Program: 31568
Project: 31568
Buggy source:
public Key init(){
  startAddr=kPos;
  appendAddr=startAddr + keyDataOffset;
  nextColOffset=startAddr + keyBlockOffset;
  return this;
}

Fixed version (ground truth):
public KeyWriter init(){
  startAddr=kPos;
  appendAddr=startAddr + keyDataOffset;
  nextColOffset=startAddr + keyBlockOffset;
  return this;
}
Program: 31569
Project: 31569
Buggy source:
public Key putInt(int value){
  checkSize(4);
  Unsafe.getUnsafe().putInt(appendAddr,value);
  appendAddr+=4;
  writeOffset();
  return this;
}

Fixed version (ground truth):
public KeyWriter putInt(int value){
  checkSize(4);
  Unsafe.getUnsafe().putInt(appendAddr,value);
  appendAddr+=4;
  writeOffset();
  return this;
}
Program: 31570
Project: 31570
Buggy source:
public Key putStr(CharSequence value){
  int len=value.length();
  checkSize(len << 1);
  for (int i=0; i < len; i++) {
    Unsafe.getUnsafe().putChar(appendAddr + (i << 1),value.charAt(i));
  }
  appendAddr+=len << 1;
  writeOffset();
  return this;
}

Fixed version (ground truth):
public KeyWriter putStr(CharSequence value){
  int len=value.length();
  checkSize(len << 1);
  for (int i=0; i < len; i++) {
    Unsafe.getUnsafe().putChar(appendAddr + (i << 1),value.charAt(i));
  }
  appendAddr+=len << 1;
  writeOffset();
  return this;
}
Program: 31571
Project: 31571
Buggy source:
private boolean eq(Key key,long offset){
  long a=kStart + offset;
  long b=key.startAddr;
  if (Unsafe.getUnsafe().getInt(a) != Unsafe.getUnsafe().getInt(b)) {
    return false;
  }
  long lim=b + key.len;
  a+=keyBlockOffset;
  b+=keyBlockOffset;
  while (b < lim - 8) {
    if (Unsafe.getUnsafe().getLong(a) != Unsafe.getUnsafe().getLong(b)) {
      return false;
    }
    a+=8;
    b+=8;
  }
  while (b < lim) {
    if (Unsafe.getUnsafe().getByte(a++) != Unsafe.getUnsafe().getByte(b++)) {
      return false;
    }
  }
  return true;
}

Fixed version (ground truth):
private boolean eq(KeyWriter keyWriter,long offset){
  long a=kStart + offset;
  long b=keyWriter.startAddr;
  if (Unsafe.getUnsafe().getInt(a) != Unsafe.getUnsafe().getInt(b)) {
    return false;
  }
  long lim=b + keyWriter.len;
  a+=keyBlockOffset;
  b+=keyBlockOffset;
  while (b < lim - 8) {
    if (Unsafe.getUnsafe().getLong(a) != Unsafe.getUnsafe().getLong(b)) {
      return false;
    }
    a+=8;
    b+=8;
  }
  while (b < lim) {
    if (Unsafe.getUnsafe().getByte(a++) != Unsafe.getUnsafe().getByte(b++)) {
      return false;
    }
  }
  return true;
}
Program: 31572
Project: 31572
Buggy source:
private void resize(){
  long kCapacity=(kLimit - kStart) << 1;
  long kAddress=Unsafe.getUnsafe().allocateMemory(kCapacity + AbstractDirectList.CACHE_LINE_SIZE);
  long kStart=kAddress + (kAddress & (AbstractDirectList.CACHE_LINE_SIZE - 1));
  Unsafe.getUnsafe().copyMemory(this.kStart,kStart,kCapacity >> 1);
  Unsafe.getUnsafe().freeMemory(this.address);
  long d=kStart - this.kStart;
  key.startAddr+=d;
  key.appendAddr+=d;
  key.nextColOffset+=d;
  this.address=kAddress;
  this.kStart=kStart;
  this.kLimit=kStart + kCapacity;
}

Fixed version (ground truth):
private void resize(){
  long kCapacity=(kLimit - kStart) << 1;
  long kAddress=Unsafe.getUnsafe().allocateMemory(kCapacity + AbstractDirectList.CACHE_LINE_SIZE);
  long kStart=kAddress + (kAddress & (AbstractDirectList.CACHE_LINE_SIZE - 1));
  Unsafe.getUnsafe().copyMemory(this.kStart,kStart,kCapacity >> 1);
  Unsafe.getUnsafe().freeMemory(this.address);
  long d=kStart - this.kStart;
  keyWriter.startAddr+=d;
  keyWriter.appendAddr+=d;
  keyWriter.nextColOffset+=d;
  this.address=kAddress;
  this.kStart=kStart;
  this.kLimit=kStart + kCapacity;
}
Program: 31573
Project: 31573
Buggy source:
public NetworkInterface findExternalNic() throws JournalNetworkException {
  try {
    Enumeration<NetworkInterface> ifs=NetworkInterface.getNetworkInterfaces();
    while (ifs.hasMoreElements()) {
      NetworkInterface ifn=ifs.nextElement();
      if (ifn.isLoopback()) {
        continue;
      }
      if (ifn.isUp() && !ifn.getDisplayName().startsWith("String_Node_Str")) {
        return ifn;
      }
    }
  }
 catch (  SocketException e) {
    throw new JournalNetworkException(e);
  }
  throw new JournalNetworkException("String_Node_Str");
}

Fixed version (ground truth):
public NetworkInterface findExternalNic() throws JournalNetworkException {
  if (defaultInterface != null) {
    return defaultInterface;
  }
  try {
    Enumeration<NetworkInterface> ifs=NetworkInterface.getNetworkInterfaces();
    int index=Integer.MAX_VALUE;
    while (ifs.hasMoreElements()) {
      NetworkInterface q=ifs.nextElement();
      if (!q.isLoopback() && q.isUp() && q.getIndex() < index) {
        defaultInterface=q;
        index=q.getIndex();
      }
    }
    if (defaultInterface == null) {
      throw new JournalNetworkException("String_Node_Str");
    }
    return defaultInterface;
  }
 catch (  SocketException e) {
    throw new JournalNetworkException(e);
  }
}
Program: 31574
Project: 31574
Buggy source:
@Override public void onFields(int line,CharSequence values[],int hi){
  if (line == 0) {
    stashPossibleHeader(values,hi);
  }
  for (int i=0; i < hi; i++) {
    if (values[i].length() == 0) {
      blanks[i]++;
    }
    int offset=i * probeLen;
    for (int k=0; k < probeLen; k++) {
      if (probes[k].probe(values[i])) {
        histogram[k + offset]++;
      }
    }
    MapValues mv=frequencyMaps[i].claimSlot(frequencyMaps[i].claimKey().putStr(values[i]).commit());
    if (mv.isNew()) {
      mv.putInt(0,0);
    }
 else {
      mv.putInt(0,mv.getInt(0) + 1);
    }
  }
}

Fixed version (ground truth):
@Override public void onFields(int line,CharSequence values[],int hi){
  if (line == 0) {
    stashPossibleHeader(values,hi);
  }
  for (int i=0; i < hi; i++) {
    if (values[i].length() == 0) {
      blanks[i]++;
    }
    int offset=i * probeLen;
    for (int k=0; k < probeLen; k++) {
      if (probes[k].probe(values[i])) {
        histogram[k + offset]++;
      }
    }
    frequencyMaps[i].values(frequencyMaps[i].keyWriter().putStr(values[i]));
  }
}
Program: 31575
Project: 31575
Buggy source:
private boolean buildMap(){
  long current=0;
  long sample;
  boolean first=true;
  Record rec;
  map.clear();
  if (nextRecord != null) {
    rec=nextRecord;
  }
 else {
    if (!rowSource.hasNext()) {
      return false;
    }
    rec=rowSource.next();
  }
  do {
switch (sampleBy) {
case YEAR:
      sample=Dates.floorYYYY(rec.getLong(tsIndex));
    break;
case MONTH:
  sample=Dates.floorMM(rec.getLong(tsIndex));
break;
case DAY:
sample=Dates.floorDD(rec.getLong(tsIndex));
break;
case HOUR:
sample=Dates.floorHH(rec.getLong(tsIndex));
break;
case MINUTE:
sample=Dates.floorMI(rec.getLong(tsIndex));
break;
default :
sample=0;
}
if (first) {
current=sample;
first=false;
}
 else if (sample != current) {
nextRecord=rec;
break;
}
MultiMap.Key key=map.claimKey();
key.putLong(sample);
for (int i=0; i < keyIndices.length; i++) {
switch (rowSource.getMetadata().getColumnType(i + 1)) {
case LONG:
key.putLong(rec.getLong(keyIndices[i]));
break;
case INT:
key.putInt(rec.getInt(keyIndices[i]));
break;
case STRING:
key.putStr(rec.getStr(keyIndices[i]));
break;
case SYMBOL:
key.putInt(rec.getInt(keyIndices[i]));
break;
default :
throw new JournalRuntimeException("String_Node_Str" + rowSource.getMetadata().getColumnType(i + 1));
}
}
key.commit();
MapValues values=map.claimSlot(key);
for (int i=0, sz=aggregators.size(); i < sz; i++) {
aggregators.get(i).calculate(rec,values);
}
if (!rowSource.hasNext()) {
nextRecord=null;
break;
}
rec=rowSource.next();
}
 while (true);
return (mapRecordSource=map.getRecordSource()).hasNext();
}

Fixed version (ground truth):
private boolean buildMap(){
  long current=0;
  long sample;
  boolean first=true;
  Record rec;
  map.clear();
  if (nextRecord != null) {
    rec=nextRecord;
  }
 else {
    if (!rowSource.hasNext()) {
      return false;
    }
    rec=rowSource.next();
  }
  do {
switch (sampleBy) {
case YEAR:
      sample=Dates.floorYYYY(rec.getLong(tsIndex));
    break;
case MONTH:
  sample=Dates.floorMM(rec.getLong(tsIndex));
break;
case DAY:
sample=Dates.floorDD(rec.getLong(tsIndex));
break;
case HOUR:
sample=Dates.floorHH(rec.getLong(tsIndex));
break;
case MINUTE:
sample=Dates.floorMI(rec.getLong(tsIndex));
break;
default :
sample=0;
}
if (first) {
current=sample;
first=false;
}
 else if (sample != current) {
nextRecord=rec;
break;
}
MultiMap.KeyWriter keyWriter=map.keyWriter();
keyWriter.putLong(sample);
for (int i=0; i < keyIndices.length; i++) {
switch (rowSource.getMetadata().getColumnType(i + 1)) {
case LONG:
keyWriter.putLong(rec.getLong(keyIndices[i]));
break;
case INT:
keyWriter.putInt(rec.getInt(keyIndices[i]));
break;
case STRING:
keyWriter.putStr(rec.getStr(keyIndices[i]));
break;
case SYMBOL:
keyWriter.putInt(rec.getInt(keyIndices[i]));
break;
default :
throw new JournalRuntimeException("String_Node_Str" + rowSource.getMetadata().getColumnType(i + 1));
}
}
MapValues values=map.values(keyWriter);
for (int i=0, sz=aggregators.size(); i < sz; i++) {
aggregators.get(i).calculate(rec,values);
}
if (!rowSource.hasNext()) {
nextRecord=null;
break;
}
rec=rowSource.next();
}
 while (true);
return (mapRecordSource=map.getRecordSource()).hasNext();
}
Program: 31576
Project: 31576
Buggy source:
public void setContent(String s){
  if ((s == null || s.length() == 0) && buffer != null) {
    buffer.limit(0);
    return;
  }
  if (buffer == null || buffer.capacity() < s.length() * 2) {
    buffer=ByteBuffer.allocate(s.length() * 2);
  }
 else {
    buffer.limit(s.length() * 2);
  }
  buffer.rewind();
  ByteBuffers.putStr(buffer,s);
  buffer.rewind();
}

Fixed version (ground truth):
public void setContent(String s){
  if ((s == null || s.length() == 0) && buffer != null) {
    buffer.limit(0);
    return;
  }
  if (s == null) {
    return;
  }
  if (buffer == null || buffer.capacity() < s.length() * 2) {
    buffer=ByteBuffer.allocate(s.length() * 2);
  }
 else {
    buffer.limit(s.length() * 2);
  }
  buffer.rewind();
  ByteBuffers.putStr(buffer,s);
  buffer.rewind();
}
Program: 31577
Project: 31577
Buggy source:
@Override public boolean hasNext(){
  return buffer != null && buffer.hasRemaining();
}

Fixed version (ground truth):
@Override public boolean hasNext(){
  return next != null || (buffer != null && buffer.hasRemaining());
}
Program: 31578
Project: 31578
Buggy source:
@SuppressFBWarnings({"String_Node_Str"}) public Token getSymbol(char c){
  List<Token> l=symbols.get(c);
  if (l == null) {
    return null;
  }
  int pos=buffer.position();
  for (int i=0, sz=l.size(); i < sz; i++) {
    final Token t=l.get(i);
    boolean match=t.text.length() < buffer.remaining();
    if (match) {
      for (int k=1; k < t.text.length(); k++) {
        if (buffer.getChar(pos + 2 * (k - 1)) != t.text.charAt(k)) {
          match=false;
          break;
        }
      }
    }
    if (match) {
      return t;
    }
  }
  return null;
}

Fixed version (ground truth):
@SuppressFBWarnings({"String_Node_Str"}) public Token getSymbol(char c){
  List<Token> l=symbols.get(c);
  if (l == null) {
    return null;
  }
  int pos=buffer.position();
  for (int i=0, sz=l.size(); i < sz; i++) {
    final Token t=l.get(i);
    boolean match=(t.text.length() - 2) < buffer.remaining();
    if (match) {
      for (int k=1; k < t.text.length(); k++) {
        if (buffer.getChar(pos + 2 * (k - 1)) != t.text.charAt(k)) {
          match=false;
          break;
        }
      }
    }
    if (match) {
      return t;
    }
  }
  return null;
}
Program: 31581
Project: 31581
Buggy source:
public long getTxAddress(){
  ByteBuffer buf=mf.getBuffer(0,9);
  long address;
  while (true) {
    address=buf.getLong();
    byte checksum=buf.get();
    byte b0=(byte)address;
    byte b1=(byte)(address >> 8);
    byte b2=(byte)(address >> 16);
    byte b3=(byte)(address >> 24);
    byte b4=(byte)(address >> 32);
    byte b5=(byte)(address >> 40);
    byte b6=(byte)(address >> 48);
    byte b7=(byte)(address >> 56);
    if ((b0 ^ b1 ^ b2^ b3^ b4^ b5^ b6^ b7) == checksum) {
      break;
    }
  }
  return address;
}

Fixed version (ground truth):
public long getTxAddress(){
  final ByteBuffer buf=mf.getBuffer(0,9);
  final int pos=buf.position();
  long address;
  while (true) {
    address=buf.getLong(pos);
    byte checksum=buf.get(pos + 8);
    byte b0=(byte)address;
    byte b1=(byte)(address >> 8);
    byte b2=(byte)(address >> 16);
    byte b3=(byte)(address >> 24);
    byte b4=(byte)(address >> 32);
    byte b5=(byte)(address >> 40);
    byte b6=(byte)(address >> 48);
    byte b7=(byte)(address >> 56);
    if ((b0 ^ b1 ^ b2^ b3^ b4^ b5^ b6^ b7) == checksum) {
      break;
    }
  }
  return address;
}