Program: 4365
Project: 4365
Buggy source:
/** 
 * The main work to be done. If there are queries, get a unicast enabled UP, and send each Query to it.  Then sleep and try some more later...
 */
private void queryLoop(){
  UDPService udpService=UDPService.instance();
  while (_shouldRun) {
    try {
      waitForQueries();
      GUESSEndpoint toQuery=getUnicastHost();
      if (!_queryKeys.containsKey(toQuery)) {
        PingRequest pr=PingRequest.createQueryKeyRequest();
        udpService.send(pr,toQuery.getAddress(),toQuery.getPort());
        SentMessageStatHandler.UDP_PING_REQUESTS.addMessage(pr);
        continue;
      }
      QueryKey queryKey=((QueryKeyBundle)_queryKeys.get(toQuery))._queryKey;
      purgeGuidsInternal();
      boolean currentHostUsed=false;
synchronized (_queries) {
        Iterator iter=_queries.values().iterator();
        while (iter.hasNext()) {
          QueryBundle currQB=(QueryBundle)iter.next();
          if ((currQB._numResults > QueryBundle.MAX_RESULTS) || (currQB._hostsQueried.size() > QueryBundle.MAX_QUERIES))           _qGuidsToRemove.add(new GUID(currQB._qr.getGUID()));
 else           if (currQB._hostsQueried.contains(toQuery))           ;
 else {
            InetAddress ip=toQuery.getAddress();
            QueryRequest qrToSend=QueryRequest.createQueryKeyQuery(currQB._qr,queryKey);
            udpService.send(qrToSend,ip,toQuery.getPort());
            currentHostUsed=true;
            SentMessageStatHandler.UDP_QUERY_REQUESTS.addMessage(qrToSend);
            currQB._hostsQueried.add(toQuery);
          }
        }
      }
      if (!currentHostUsed) {
        addUnicastEndpoint(toQuery);
      }
synchronized (_qGuidsToRemove) {
        purgeGuidsInternal();
        _qGuidsToRemove.clear();
      }
      Thread.sleep(ITERATION_TIME);
    }
 catch (    InterruptedException ignored) {
    }
  }
}

Fixed version (ground truth):
/** 
 * The main work to be done. If there are queries, get a unicast enabled UP, and send each Query to it.  Then sleep and try some more later...
 */
private void queryLoop(){
  UDPService udpService=UDPService.instance();
  while (_shouldRun) {
    try {
      waitForQueries();
      GUESSEndpoint toQuery=getUnicastHost();
      if (!_queryKeys.containsKey(toQuery)) {
        PingRequest pr=PingRequest.createQueryKeyRequest();
        udpService.send(pr,toQuery.getAddress(),toQuery.getPort());
        SentMessageStatHandler.UDP_PING_REQUESTS.addMessage(pr);
        continue;
      }
      QueryKey queryKey=((QueryKeyBundle)_queryKeys.get(toQuery))._queryKey;
      purgeGuidsInternal();
      boolean currentHostUsed=false;
synchronized (_queries) {
        Iterator iter=_queries.values().iterator();
        while (iter.hasNext()) {
          QueryBundle currQB=(QueryBundle)iter.next();
          if (currQB._hostsQueried.size() > QueryBundle.MAX_QUERIES)           _qGuidsToRemove.add(new GUID(currQB._qr.getGUID()));
 else           if (currQB._hostsQueried.contains(toQuery))           ;
 else {
            InetAddress ip=toQuery.getAddress();
            QueryRequest qrToSend=QueryRequest.createQueryKeyQuery(currQB._qr,queryKey);
            udpService.send(qrToSend,ip,toQuery.getPort());
            currentHostUsed=true;
            SentMessageStatHandler.UDP_QUERY_REQUESTS.addMessage(qrToSend);
            currQB._hostsQueried.add(toQuery);
          }
        }
      }
      if (!currentHostUsed) {
        addUnicastEndpoint(toQuery);
      }
synchronized (_qGuidsToRemove) {
        purgeGuidsInternal();
        _qGuidsToRemove.clear();
      }
      Thread.sleep(ITERATION_TIME);
    }
 catch (    InterruptedException ignored) {
    }
  }
}