Program: 4381
Project: 4381
Buggy source:
public void testBasicOutOfBandRequest() throws Exception {
  DatagramPacket pack=null;
  UDP_ACCESS=new DatagramSocket();
{
    drainAll();
    PingReply pong=PingReply.create(GUID.makeGuid(),(byte)4,UDP_ACCESS.getLocalPort(),InetAddress.getLocalHost().getAddress(),10,10,true,900,true);
    ULTRAPEER[0].send(pong);
    ULTRAPEER[0].flush();
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    PingRequest ping=(PingRequest)Message.read(in);
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    pong=PingReply.create(ping.getGUID(),(byte)4,UDP_ACCESS.getLocalPort(),InetAddress.getLocalHost().getAddress(),10,10,true,900,true);
    pong.write(baos);
    pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,pack.getAddress(),pack.getPort());
    UDP_ACCESS.send(pack);
  }
{
    MessagesSupportedVendorMessage support=MessagesSupportedVendorMessage.instance();
    ULTRAPEER[0].send(support);
    ULTRAPEER[0].flush();
    byte[] cbGuid=null;
    int cbPort=-1;
    while (cbGuid == null) {
      try {
        Message m=ULTRAPEER[0].receive(TIMEOUT);
        if (m instanceof UDPConnectBackVendorMessage) {
          UDPConnectBackVendorMessage udp=(UDPConnectBackVendorMessage)m;
          cbGuid=udp.getConnectBackGUID().bytes();
          cbPort=udp.getConnectBackPort();
        }
      }
 catch (      Exception ie) {
        fail("String_Node_Str",ie);
      }
    }
    PingRequest pr=new PingRequest(cbGuid,(byte)1,(byte)0);
    ByteArrayOutputStream baos=new ByteArrayOutputStream();
    pr.write(baos);
    pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,ULTRAPEER[0].getInetAddress(),cbPort);
    UDP_ACCESS.send(pack);
  }
  drainAll();
  QueryRequest query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  ULTRAPEER[0].send(query);
  ULTRAPEER[0].flush();
  PrivilegedAccessor.setValue(RouterService.getUdpService(),"String_Node_Str",new Boolean(true));
  PrivilegedAccessor.setValue(RouterService.getUdpService(),"String_Node_Str",new Boolean(true));
  Message message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  ReplyNumberVendorMessage reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertTrue(reply.canReceiveUnsolicited());
  query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  UDPService service=RouterService.getUdpService();
  PrivilegedAccessor.setValue(service,"String_Node_Str",new Boolean(false));
  assertFalse(RouterService.getUdpService().canReceiveUnsolicited());
  assertTrue(query.desiresOutOfBandReplies());
  ULTRAPEER[1].send(query);
  ULTRAPEER[1].flush();
  message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertFalse(reply.canReceiveUnsolicited());
  query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  PrivilegedAccessor.setValue(service,"String_Node_Str",new Boolean(true));
  ULTRAPEER[2].send(query);
  ULTRAPEER[2].flush();
  message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertTrue(reply.canReceiveUnsolicited());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  LimeACKVendorMessage ack=new LimeACKVendorMessage(new GUID(message.getGUID()),reply.getNumResults());
  ack.write(baos);
  pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,pack.getAddress(),pack.getPort());
  UDP_ACCESS.send(pack);
  while (!(message instanceof QueryReply)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
  }
  assertTrue(Arrays.equals(message.getGUID(),ack.getGUID()));
  assertEquals(1,((QueryReply)message).getResultCount());
  message=null;
  while (!(message instanceof QueryReply)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
  }
  assertTrue(Arrays.equals(message.getGUID(),ack.getGUID()));
  assertEquals(1,((QueryReply)message).getResultCount());
  baos=new ByteArrayOutputStream();
  ack.write(baos);
  pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,pack.getAddress(),pack.getPort());
  UDP_ACCESS.send(pack);
  try {
    while (true) {
      UDP_ACCESS.setSoTimeout(500);
      pack=new DatagramPacket(new byte[1000],1000);
      UDP_ACCESS.receive(pack);
      InputStream in=new ByteArrayInputStream(pack.getData());
      message=Message.read(in);
      assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),ack.getGUID()))));
    }
  }
 catch (  IOException expected) {
  }
}

Fixed version (ground truth):
public void testBasicOutOfBandRequest() throws Exception {
  PrivilegedAccessor.setValue(RouterService.getUdpService(),"String_Node_Str",new Boolean(true));
  PrivilegedAccessor.setValue(RouterService.getUdpService(),"String_Node_Str",new Boolean(true));
  DatagramPacket pack=null;
  UDP_ACCESS=new DatagramSocket();
  drainAll();
  QueryRequest query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  ULTRAPEER[0].send(query);
  ULTRAPEER[0].flush();
  Message message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  ReplyNumberVendorMessage reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertTrue(reply.canReceiveUnsolicited());
  query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  UDPService service=RouterService.getUdpService();
  PrivilegedAccessor.setValue(service,"String_Node_Str",new Boolean(false));
  assertFalse(RouterService.getUdpService().canReceiveUnsolicited());
  assertTrue(query.desiresOutOfBandReplies());
  ULTRAPEER[1].send(query);
  ULTRAPEER[1].flush();
  message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertFalse(reply.canReceiveUnsolicited());
  query=QueryRequest.createOutOfBandQuery("String_Node_Str",InetAddress.getLocalHost().getAddress(),UDP_ACCESS.getLocalPort());
  query.hop();
  PrivilegedAccessor.setValue(service,"String_Node_Str",new Boolean(true));
  ULTRAPEER[2].send(query);
  ULTRAPEER[2].flush();
  message=null;
  while (!(message instanceof ReplyNumberVendorMessage)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
    assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),query.getGUID()))));
  }
  assertTrue(Arrays.equals(query.getGUID(),message.getGUID()));
  reply=(ReplyNumberVendorMessage)message;
  assertEquals(2,reply.getNumResults());
  assertTrue(reply.canReceiveUnsolicited());
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  LimeACKVendorMessage ack=new LimeACKVendorMessage(new GUID(message.getGUID()),reply.getNumResults());
  ack.write(baos);
  pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,pack.getAddress(),pack.getPort());
  UDP_ACCESS.send(pack);
  while (!(message instanceof QueryReply)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
  }
  assertTrue(Arrays.equals(message.getGUID(),ack.getGUID()));
  assertEquals(1,((QueryReply)message).getResultCount());
  message=null;
  while (!(message instanceof QueryReply)) {
    UDP_ACCESS.setSoTimeout(500);
    pack=new DatagramPacket(new byte[1000],1000);
    try {
      UDP_ACCESS.receive(pack);
    }
 catch (    IOException bad) {
      fail("String_Node_Str",bad);
    }
    InputStream in=new ByteArrayInputStream(pack.getData());
    message=Message.read(in);
  }
  assertTrue(Arrays.equals(message.getGUID(),ack.getGUID()));
  assertEquals(1,((QueryReply)message).getResultCount());
  baos=new ByteArrayOutputStream();
  ack.write(baos);
  pack=new DatagramPacket(baos.toByteArray(),baos.toByteArray().length,pack.getAddress(),pack.getPort());
  UDP_ACCESS.send(pack);
  try {
    while (true) {
      UDP_ACCESS.setSoTimeout(500);
      pack=new DatagramPacket(new byte[1000],1000);
      UDP_ACCESS.receive(pack);
      InputStream in=new ByteArrayInputStream(pack.getData());
      message=Message.read(in);
      assertTrue(!((message instanceof QueryReply) && (Arrays.equals(message.getGUID(),ack.getGUID()))));
    }
  }
 catch (  IOException expected) {
  }
}