Program: 4369
Project: 4369
Buggy source:
public void testResultMaxOut() 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(5500 + index);
      }
    }
;
    udpLoopers[i].start();
    Thread.yield();
  }
  QueryRequest qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  QueryUnicaster.instance().addQuery(qr,null);
  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) {
      }
    }
    QueryReply qRep=generateFakeReply(qr.getGUID(),getNumberBetween(25,35));
    QueryUnicaster.instance().handleQueryReply(qRep);
  }
  try {
    Thread.sleep(30 * 1000);
    assertEquals("String_Node_Str",0,QueryUnicaster.instance().getQueryNumber());
  }
 catch (  InterruptedException ignored) {
  }
  int numMessages=0, numQRs=0, numPings=0;
  while (!_messages.isEmpty()) {
    Message currMessage=(Message)_messages.remove(0);
    numMessages++;
    if (currMessage instanceof QueryRequest) {
      QueryRequest currQR=(QueryRequest)currMessage;
      assertTrue(currQR.getQuery().equals("String_Node_Str"));
      numQRs++;
    }
 else     if (currMessage instanceof PingRequest) {
      numPings++;
    }
 else     fail("String_Node_Str" + currMessage);
  }
  assertEquals("String_Node_Str",numMessages,numPings + numQRs);
  assertLessThan("String_Node_Str",11,numQRs);
  assertGreaterThan("String_Node_Str",0,QueryUnicaster.instance().getUnicastEndpoints().size());
  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) {
  }
}

Fixed version (ground truth):
public void testResultMaxOut() 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();
  }
  QueryRequest qr=QueryRequest.createQuery("String_Node_Str",(byte)2);
  QueryUnicaster.instance().addQuery(qr,null);
  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) {
      }
    }
    int low=250 / NUM_UDP_LOOPS + 1;
    int hi=254 / NUM_UDP_LOOPS + 1;
    if (low < 25)     low=25;
    if (hi < 35)     hi=35;
    QueryReply qRep=generateFakeReply(qr.getGUID(),getNumberBetween(low,hi));
    QueryUnicaster.instance().handleQueryReply(qRep);
  }
  try {
    Thread.sleep(30 * 1000);
    assertEquals("String_Node_Str",0,QueryUnicaster.instance().getQueryNumber());
  }
 catch (  InterruptedException ignored) {
  }
  int numMessages=0, numQRs=0, numPings=0;
  while (!_messages.isEmpty()) {
    Message currMessage=(Message)_messages.remove(0);
    numMessages++;
    if (currMessage instanceof QueryRequest) {
      QueryRequest currQR=(QueryRequest)currMessage;
      assertTrue(currQR.getQuery().equals("String_Node_Str"));
      numQRs++;
    }
 else     if (currMessage instanceof PingRequest) {
      numPings++;
    }
 else     fail("String_Node_Str" + currMessage);
  }
  assertEquals("String_Node_Str",numMessages,numPings + numQRs);
  assertLessThan("String_Node_Str",11,numQRs);
  if (NUM_UDP_LOOPS > 10)   assertGreaterThan("String_Node_Str",0,QueryUnicaster.instance().getUnicastEndpoints().size());
  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) {
  }
}