Program: 4370
Project: 4370
Buggy source:
public void testQueries() throws Exception {
  Thread[] udpLoopers=new Thread[NUM_UDP_LOOPS];
  for (int i=0; i < NUM_UDP_LOOPS; i++) {
    final int index=i;
    udpLoopers[i]=new Thread(){
      public void run(){
        udpLoop(5000 + index);
      }
    }
;
    udpLoopers[i].start();
    Thread.yield();
  }
  InetAddress addr=null;
  addr=InetAddress.getByName("String_Node_Str");
  for (int i=0; i < NUM_UDP_LOOPS; i++) {
    QueryUnicaster.instance().addUnicastEndpoint(addr,5000 + i);
    if (i % 5 == 0) {
      try {
        Thread.sleep(200);
      }
 catch (      InterruptedException ignored) {
      }
    }
  }
  QueryRequest qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertEquals("String_Node_Str",0,QueryUnicaster.instance().getQueryNumber());
  QueryUnicaster.instance().addQuery(qr,null);
  assertEquals("String_Node_Str",1,QueryUnicaster.instance().getQueryNumber());
  try {
    Thread.sleep(30 * 1000);
  }
 catch (  InterruptedException ignored) {
  }
  int numMessages=0, numQRs=0, numPings=0, numQKReqs=0;
  while (!_messages.isEmpty()) {
    Message currMessage=(Message)_messages.remove(0);
    numMessages++;
    if (currMessage instanceof QueryRequest) {
      QueryRequest currQR=(QueryRequest)currMessage;
      assertEquals("String_Node_Str","String_Node_Str",currQR.getQuery());
      numQRs++;
    }
 else     if (currMessage instanceof PingRequest) {
      numPings++;
      if (((PingRequest)currMessage).isQueryKeyRequest())       numQKReqs++;
    }
 else     fail("String_Node_Str" + currMessage);
  }
  assertEquals("String_Node_Str",numMessages,numPings + numQRs);
  assertLessThanOrEquals("String_Node_Str",numPings,numQRs);
  assertGreaterThan("String_Node_Str",0,numQRs);
  assertLessThanOrEquals("String_Node_Str",numQKReqs,numQRs);
  debug("String_Node_Str" + numMessages);
  debug("String_Node_Str" + numQRs);
  debug("String_Node_Str" + numPings);
  _shouldRun=false;
  for (int i=0; i < NUM_UDP_LOOPS; i++)   udpLoopers[i].interrupt();
  try {
    Thread.sleep(2 * 1000);
  }
 catch (  InterruptedException ignored) {
  }
  QueryReply qRep=generateFakeReply(qr.getGUID(),251);
  QueryUnicaster.instance().handleQueryReply(qRep);
}

Fixed version (ground truth):
public void testQueries() throws Exception {
  _messages.clear();
  _shouldRun=true;
  Thread[] udpLoopers=new Thread[NUM_UDP_LOOPS];
  for (int i=0; i < NUM_UDP_LOOPS; i++) {
    final int index=i;
    udpLoopers[i]=new Thread(){
      public void run(){
        udpLoop(5000 + index);
      }
    }
;
    udpLoopers[i].start();
    Thread.yield();
  }
  InetAddress addr=null;
  addr=InetAddress.getByName("String_Node_Str");
  for (int i=0; i < NUM_UDP_LOOPS; i++) {
    QueryUnicaster.instance().addUnicastEndpoint(addr,5000 + i);
    if (i % 5 == 0) {
      try {
        Thread.sleep(200);
      }
 catch (      InterruptedException ignored) {
      }
    }
  }
  QueryRequest qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  assertEquals("String_Node_Str",0,QueryUnicaster.instance().getQueryNumber());
  QueryUnicaster.instance().addQuery(qr,null);
  assertEquals("String_Node_Str",1,QueryUnicaster.instance().getQueryNumber());
  try {
    Thread.sleep(30 * 1000);
  }
 catch (  InterruptedException ignored) {
  }
  int numMessages=0, numQRs=0, numPings=0, numQKReqs=0;
  while (!_messages.isEmpty()) {
    Message currMessage=(Message)_messages.remove(0);
    numMessages++;
    if (currMessage instanceof QueryRequest) {
      QueryRequest currQR=(QueryRequest)currMessage;
      assertEquals("String_Node_Str","String_Node_Str",currQR.getQuery());
      numQRs++;
    }
 else     if (currMessage instanceof PingRequest) {
      numPings++;
      if (((PingRequest)currMessage).isQueryKeyRequest())       numQKReqs++;
    }
 else     fail("String_Node_Str" + currMessage);
  }
  assertEquals("String_Node_Str",numMessages,numPings + numQRs);
  assertLessThanOrEquals("String_Node_Str",numPings,numQRs);
  assertGreaterThan("String_Node_Str",0,numQRs);
  assertLessThanOrEquals("String_Node_Str",numQKReqs,numQRs);
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str" + numMessages);
    LOG.debug("String_Node_Str" + numQRs);
    LOG.debug("String_Node_Str" + numPings);
  }
  _shouldRun=false;
  for (int i=0; i < NUM_UDP_LOOPS; i++)   udpLoopers[i].interrupt();
  try {
    Thread.sleep(2 * 1000);
  }
 catch (  InterruptedException ignored) {
  }
  QueryReply qRep=generateFakeReply(qr.getGUID(),251);
  QueryUnicaster.instance().handleQueryReply(qRep);
}