Program: 104154
Project: 104154
Buggy source:
/** 
 * Returns the supplied number of recent messages after the given date
 * @param date messages after date
 * @param count messages count
 * @return QueryResultSet the found records
 * @throws RuntimeException
 */
public QueryResultSet findFirstRecordsAfter(Date date,int count) throws RuntimeException {
  TreeSet result=new TreeSet(new HistoryRecordComparator());
  Vector filelist=filterFilesByDate(this.historyImpl.getFileList(),date,null);
  int leftCount=count;
  int currentFile=0;
  while (leftCount > 0 && currentFile < filelist.size()) {
    Document doc=this.historyImpl.getDocumentForFile((String)filelist.get(currentFile));
    if (doc == null) {
      currentFile++;
      continue;
    }
    NodeList nodes=doc.getElementsByTagName("String_Node_Str");
    Node node;
    for (int i=0; i < nodes.getLength() && leftCount > 0; i++) {
      node=nodes.item(i);
      NodeList propertyNodes=node.getChildNodes();
      String ts=node.getAttributes().getNamedItem("String_Node_Str").getNodeValue();
      Date timestamp=new Date(Long.parseLong(ts));
      if (!isInPeriod(timestamp,date,null))       continue;
      ArrayList nameVals=new ArrayList();
      boolean isRecordOK=true;
      int len=propertyNodes.getLength();
      for (int j=0; j < len; j++) {
        Node propertyNode=propertyNodes.item(j);
        if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
          Node nodeValue=propertyNode.getFirstChild();
          if (nodeValue != null) {
            nameVals.add(propertyNode.getNodeName());
            nameVals.add(nodeValue.getNodeValue());
          }
 else           isRecordOK=false;
        }
      }
      if (!isRecordOK)       continue;
      String[] propertyNames=new String[nameVals.size() / 2];
      String[] propertyValues=new String[propertyNames.length];
      for (int j=0; j < propertyNames.length; j++) {
        propertyNames[j]=(String)nameVals.get(j * 2);
        propertyValues[j]=(String)nameVals.get(j * 2 + 1);
      }
      HistoryRecord record=new HistoryRecord(propertyNames,propertyValues,timestamp);
      result.add(record);
      leftCount--;
    }
    currentFile++;
  }
  return new OrderedQueryResultSet(result);
}

Fixed version (ground truth):
/** 
 * Returns the supplied number of recent messages after the given date
 * @param date messages after date
 * @param count messages count
 * @return QueryResultSet the found records
 * @throws RuntimeException
 */
public QueryResultSet findFirstRecordsAfter(Date date,int count) throws RuntimeException {
  TreeSet<HistoryRecord> result=new TreeSet<HistoryRecord>(new HistoryRecordComparator());
  Vector<String> filelist=filterFilesByDate(this.historyImpl.getFileList(),date,null);
  int leftCount=count;
  int currentFile=0;
  while (leftCount > 0 && currentFile < filelist.size()) {
    Document doc=this.historyImpl.getDocumentForFile((String)filelist.get(currentFile));
    if (doc == null) {
      currentFile++;
      continue;
    }
    NodeList nodes=doc.getElementsByTagName("String_Node_Str");
    Node node;
    for (int i=0; i < nodes.getLength() && leftCount > 0; i++) {
      node=nodes.item(i);
      NodeList propertyNodes=node.getChildNodes();
      String ts=node.getAttributes().getNamedItem("String_Node_Str").getNodeValue();
      Date timestamp=new Date(Long.parseLong(ts));
      if (!isInPeriod(timestamp,date,null))       continue;
      ArrayList<String> nameVals=new ArrayList<String>();
      boolean isRecordOK=true;
      int len=propertyNodes.getLength();
      for (int j=0; j < len; j++) {
        Node propertyNode=propertyNodes.item(j);
        if (propertyNode.getNodeType() == Node.ELEMENT_NODE) {
          Node nodeValue=propertyNode.getFirstChild();
          if (nodeValue != null) {
            nameVals.add(propertyNode.getNodeName());
            nameVals.add(nodeValue.getNodeValue());
          }
 else           isRecordOK=false;
        }
      }
      if (!isRecordOK)       continue;
      String[] propertyNames=new String[nameVals.size() / 2];
      String[] propertyValues=new String[propertyNames.length];
      for (int j=0; j < propertyNames.length; j++) {
        propertyNames[j]=(String)nameVals.get(j * 2);
        propertyValues[j]=(String)nameVals.get(j * 2 + 1);
      }
      HistoryRecord record=new HistoryRecord(propertyNames,propertyValues,timestamp);
      result.add(record);
      leftCount--;
    }
    currentFile++;
  }
  return new OrderedQueryResultSet(result);
}