Program: 4447
Project: 4447
Buggy source:
public void testMultipleDownloadsNoPurge() throws Exception {
  keepAllAlive(testUP);
  drainAll();
  DatagramPacket pack=null;
  Message m=null;
  byte[] guid=RouterService.newQueryGUID();
  RouterService.query(guid,"String_Node_Str");
  ((MyCallback)getCallback()).setGUID(new GUID(guid));
  QueryRequest qr=(QueryRequest)getFirstInstanceOfMessageType(testUP[0],QueryRequest.class);
  assertNotNull(qr);
  assertTrue(qr.desiresOutOfBandReplies());
  for (int i=0; i < testUP.length; i++) {
    Response[] res=new Response[200];
    for (int j=0; j < res.length; j++)     res[j]=new Response(10 + j + i,10 + j + i,"String_Node_Str" + j + i);
    m=new QueryReply(qr.getGUID(),(byte)1,6355,myIP(),0,res,GUID.makeGuid(),new byte[0],false,false,true,true,false,false,null);
    testUP[i].send(m);
    testUP[i].flush();
  }
  final int UPLOADER_PORT=10000;
  TestUploader uploader=new TestUploader("String_Node_Str",UPLOADER_PORT);
  uploader.setBusy(true);
  URN urn=URN.createSHA1Urn("String_Node_Str");
  Set urns=new HashSet();
  urns.add(urn);
  RemoteFileDesc rfd=new RemoteFileDesc("String_Node_Str",UPLOADER_PORT,1,"String_Node_Str",10,GUID.makeGuid(),1,false,3,false,null,urns,false,false,"String_Node_Str",0,new HashSet());
  TestUploader uploader2=new TestUploader("String_Node_Str",UPLOADER_PORT);
  uploader2.setBusy(true);
  urn=URN.createSHA1Urn("String_Node_Str");
  urns=new HashSet();
  urns.add(urn);
  RemoteFileDesc rfd2=new RemoteFileDesc("String_Node_Str",UPLOADER_PORT,1,"String_Node_Str",10,GUID.makeGuid(),1,false,3,false,null,urns,false,false,"String_Node_Str",0,new HashSet());
  Thread.sleep(1500);
{
    ReplyNumberVendorMessage vm=new ReplyNumberVendorMessage(new GUID(qr.getGUID()),1);
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    vm.write(baos);
    pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,testUP[0].getInetAddress(),SERVER_PORT);
    UDP_ACCESS[0].send(pack);
  }
  Thread.sleep(500);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(1,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNotNull(endpoints);
    assertEquals(1,endpoints.size());
  }
  Downloader downloader=RouterService.download(new RemoteFileDesc[]{rfd},false,new GUID(guid));
  Downloader downloader2=RouterService.download(new RemoteFileDesc[]{rfd2},false,new GUID(guid));
  Thread.sleep(2000);
  assertEquals(Downloader.WAITING_FOR_RETRY,downloader.getState());
  assertEquals(Downloader.WAITING_FOR_RETRY,downloader2.getState());
  ((MyCallback)getCallback()).clearGUID();
  downloader.stop();
  Thread.sleep(500);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(1,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNotNull(endpoints);
    assertEquals(1,endpoints.size());
  }
  downloader2.stop();
  Thread.sleep(1000);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(0,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNull(endpoints);
  }
}

Fixed version (ground truth):
public void testMultipleDownloadsNoPurge() throws Exception {
  keepAllAlive(testUP);
  drainAll();
  DatagramPacket pack=null;
  Message m=null;
  byte[] guid=RouterService.newQueryGUID();
  RouterService.query(guid,"String_Node_Str");
  ((MyCallback)getCallback()).setGUID(new GUID(guid));
  QueryRequest qr=(QueryRequest)getFirstInstanceOfMessageType(testUP[0],QueryRequest.class);
  assertNotNull(qr);
  assertTrue(qr.desiresOutOfBandReplies());
  for (int i=0; i < testUP.length; i++) {
    Response[] res=new Response[200];
    for (int j=0; j < res.length; j++)     res[j]=new Response(10 + j + i,10 + j + i,"String_Node_Str" + j + i);
    m=new QueryReply(qr.getGUID(),(byte)1,6355,myIP(),0,res,GUID.makeGuid(),new byte[0],false,false,true,true,false,false,null);
    testUP[i].send(m);
    testUP[i].flush();
  }
  final int UPLOADER_PORT=10000;
  TestUploader uploader=new TestUploader("String_Node_Str",UPLOADER_PORT);
  uploader.setBusy(true);
  URN urn=URN.createSHA1Urn("String_Node_Str");
  Set urns=new HashSet();
  urns.add(urn);
  RemoteFileDesc rfd=new RemoteFileDesc("String_Node_Str",UPLOADER_PORT,1,"String_Node_Str",10,GUID.makeGuid(),1,false,3,false,null,urns,false,false,"String_Node_Str",0,new HashSet());
  TestUploader uploader2=new TestUploader("String_Node_Str",UPLOADER_PORT);
  uploader2.setBusy(true);
  urn=URN.createSHA1Urn("String_Node_Str");
  urns=new HashSet();
  urns.add(urn);
  RemoteFileDesc rfd2=new RemoteFileDesc("String_Node_Str",UPLOADER_PORT,1,"String_Node_Str",10,GUID.makeGuid(),1,false,3,false,null,urns,false,false,"String_Node_Str",0,new HashSet());
  Thread.sleep(1500);
{
    ReplyNumberVendorMessage vm=new ReplyNumberVendorMessage(new GUID(qr.getGUID()),1);
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    vm.write(baos);
    pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,testUP[0].getInetAddress(),SERVER_PORT);
    UDP_ACCESS[0].send(pack);
  }
  Thread.sleep(500);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(1,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNotNull(endpoints);
    assertEquals(1,endpoints.size());
  }
  Downloader downloader=RouterService.download(new RemoteFileDesc[]{rfd},false,new GUID(guid));
  Downloader downloader2=RouterService.download(new RemoteFileDesc[]{rfd2},false,new GUID(guid));
  final int MAX_TRIES=60;
  boolean oneGood=false, twoGood=false;
  for (int i=0; i <= MAX_TRIES; i++) {
    Thread.sleep(500);
    if (downloader.getState() == Downloader.WAITING_FOR_RETRY)     oneGood=true;
    if (downloader2.getState() == Downloader.WAITING_FOR_RETRY)     twoGood=true;
    if (oneGood && twoGood)     break;
    if (i == MAX_TRIES)     fail("String_Node_Str");
  }
  ((MyCallback)getCallback()).clearGUID();
  downloader.stop();
  Thread.sleep(500);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(1,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNotNull(endpoints);
    assertEquals(1,endpoints.size());
  }
  downloader2.stop();
  Thread.sleep(1000);
{
    Map _bypassedResults=(Map)PrivilegedAccessor.getValue(RouterService.getMessageRouter(),"String_Node_Str");
    assertNotNull(_bypassedResults);
    assertEquals(0,_bypassedResults.size());
    Set endpoints=(Set)_bypassedResults.get(new GUID(qr.getGUID()));
    assertNull(endpoints);
  }
}