Program: 155247
Project: 155247
Buggy source:
/** 
 * Returns an array of lists, each list contains dangling records  (transactions that han't been completed yet) grouped after global by transaction id.
 */
public synchronized Iterator<List<Record>> getDanglingRecords() throws IOException {
  fileChannel.position(0);
  buffer.clear();
  fileChannel.read(buffer);
  buffer.flip();
  long nextPosition=0;
  int seqNr=0;
  Map<Xid,List<Record>> recordMap=new HashMap<Xid,List<Record>>();
  while (buffer.hasRemaining()) {
    byte recordType=buffer.get();
    if (recordType == TX_START) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      List<Record> recordList=new LinkedList<Record>();
      recordList.add(new Record(recordType,globalId,null,seqNr++));
      recordMap.put(xid,recordList);
      nextPosition+=2 + globalId.length;
    }
 else     if (recordType == BRANCH_ADD) {
      byte globalId[]=new byte[buffer.get()];
      byte branchId[]=new byte[buffer.get()];
      buffer.get(globalId);
      buffer.get(branchId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + new String(branchId) + "String_Node_Str"+ xid+ "String_Node_Str");
      }
      recordMap.get(xid).add(new Record(recordType,globalId,branchId,seqNr++));
      nextPosition+=3 + globalId.length + branchId.length;
    }
 else     if (recordType == MARK_COMMIT) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      List<Record> recordList=recordMap.get(xid);
      recordList.add(new Record(recordType,globalId,null,seqNr++));
      recordMap.put(xid,recordList);
      nextPosition+=2 + globalId.length;
    }
 else     if (recordType == TX_DONE) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      recordMap.remove(xid);
      nextPosition+=2 + globalId.length;
    }
 else {
      throw new IOException("String_Node_Str" + recordType);
    }
    if ((buffer.limit() - buffer.position()) < (3 + Xid.MAXGTRIDSIZE + Xid.MAXBQUALSIZE)) {
      buffer.clear();
      fileChannel.position(nextPosition);
      fileChannel.read(buffer);
      buffer.flip();
    }
  }
  return recordMap.values().iterator();
}

Fixed version (ground truth):
/** 
 * Returns an array of lists, each list contains dangling records  (transactions that han't been completed yet) grouped after global by transaction id.
 */
public synchronized Iterator<List<Record>> getDanglingRecords() throws IOException {
  fileChannel.position(0);
  buffer.clear();
  fileChannel.read(buffer);
  buffer.flip();
  long nextPosition=0;
  int seqNr=0;
  Map<Xid,List<Record>> recordMap=new HashMap<Xid,List<Record>>();
  while (buffer.hasRemaining()) {
    byte recordType=buffer.get();
    if (recordType == TX_START) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      List<Record> recordList=new LinkedList<Record>();
      recordList.add(new Record(recordType,globalId,null,seqNr++));
      recordMap.put(xid,recordList);
      nextPosition+=2 + globalId.length;
    }
 else     if (recordType == BRANCH_ADD) {
      byte globalId[]=new byte[buffer.get()];
      byte branchId[]=new byte[buffer.get()];
      buffer.get(globalId);
      buffer.get(branchId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + new String(branchId) + "String_Node_Str"+ xid+ "String_Node_Str");
      }
      recordMap.get(xid).add(new Record(recordType,globalId,branchId,seqNr++));
      nextPosition+=3 + globalId.length + branchId.length;
    }
 else     if (recordType == MARK_COMMIT) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      List<Record> recordList=recordMap.get(xid);
      recordList.add(new Record(recordType,globalId,null,seqNr++));
      recordMap.put(xid,recordList);
      nextPosition+=2 + globalId.length;
    }
 else     if (recordType == TX_DONE) {
      byte globalId[]=new byte[buffer.get()];
      buffer.get(globalId);
      Xid xid=new XidImpl(globalId,new byte[0]);
      if (!recordMap.containsKey(xid)) {
        throw new IOException("String_Node_Str" + xid + "String_Node_Str");
      }
      recordMap.remove(xid);
      nextPosition+=2 + globalId.length;
    }
 else     if (recordType == 0) {
      continue;
    }
 else {
      throw new IOException("String_Node_Str" + recordType);
    }
    if ((buffer.limit() - buffer.position()) < (3 + Xid.MAXGTRIDSIZE + Xid.MAXBQUALSIZE)) {
      buffer.clear();
      fileChannel.position(nextPosition);
      fileChannel.read(buffer);
      buffer.flip();
    }
  }
  return recordMap.values().iterator();
}