Program: 104148
Project: 104148
Buggy source:
/** 
 * Returns the supplied number of recent messages before the given date
 * @param date messages before date
 * @param count messages count
 * @return QueryResultSet the found records
 * @throws RuntimeException
 */
public QueryResultSet findLastRecordsBefore(Date date,int count) throws RuntimeException {
  Vector filelist=filterFilesByDate(this.historyImpl.getFileList(),null,date);
  TreeSet result=new TreeSet(new HistoryRecordComparator());
  int leftCount=count;
  int currentFile=filelist.size() - 1;
  while (leftCount > 0 && currentFile >= 0) {
    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=nodes.getLength() - 1; i >= 0 && 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,null,date))       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 before the given date
 * @param date messages before date
 * @param count messages count
 * @return QueryResultSet the found records
 * @throws RuntimeException
 */
public QueryResultSet findLastRecordsBefore(Date date,int count) throws RuntimeException {
  Vector<String> filelist=filterFilesByDate(this.historyImpl.getFileList(),null,date);
  TreeSet<HistoryRecord> result=new TreeSet<HistoryRecord>(new HistoryRecordComparator());
  int leftCount=count;
  int currentFile=filelist.size() - 1;
  while (leftCount > 0 && currentFile >= 0) {
    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=nodes.getLength() - 1; i >= 0 && 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,null,date))       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);
}