Program: 113617
Project: 113617
Buggy source:
public static DirService discoverDir(int maxWaitSeconds){
  try {
    final DatagramSocket dsock=new DatagramSocket();
    dsock.setSoTimeout(1000);
    final byte[] data=new byte[2048];
    Enumeration<NetworkInterface> nifs=NetworkInterface.getNetworkInterfaces();
    List<InetAddress> broadcasts=new LinkedList();
    broadcasts.add(InetAddress.getLocalHost());
    while (nifs.hasMoreElements()) {
      NetworkInterface nif=nifs.nextElement();
      for (      InterfaceAddress ia : nif.getInterfaceAddresses()) {
        InetAddress bc=ia.getBroadcast();
        if (bc != null) {
          broadcasts.add(bc);
        }
      }
    }
    DatagramPacket pPack=new DatagramPacket(data,0,InetAddress.getByName("String_Node_Str"),DIRInterface.DEFAULT_ONCRPC_PORT);
    dsock.send(pPack);
    for (int i=0; i < maxWaitSeconds; i++) {
      xtreemfs_discover_dirRequest rq=new xtreemfs_discover_dirRequest();
      ONCRPCRequestHeader rqHdr=new ONCRPCRequestHeader(1,1,DIRInterface.getVersion(),rq.TAG);
      ONCRPCBufferWriter wr=new ONCRPCBufferWriter(2048);
      wr.putInt(ONCRPCRecordFragmentHeader.getFragmentHeader(rqHdr.calculateSize() + rq.calculateSize(),true));
      rqHdr.serialize(wr);
      rq.serialize(wr);
      wr.flip();
      byte[] rdata=wr.getBuffers().get(0).array();
      wr.freeBuffers();
      for (      InetAddress bc : broadcasts) {
        DatagramPacket rp=new DatagramPacket(rdata,rdata.length,bc,DIRInterface.DEFAULT_ONCRPC_PORT);
        dsock.send(rp);
      }
      DatagramPacket p=new DatagramPacket(data,data.length);
      try {
        dsock.receive(p);
      }
 catch (      SocketTimeoutException ex) {
        continue;
      }
      ReusableBuffer b=ReusableBuffer.wrap(data,0,p.getLength());
      b.position(Integer.SIZE / 8);
      ONCRPCResponseHeader respHdr=new ONCRPCResponseHeader();
      respHdr.deserialize(b);
      xtreemfs_discover_dirResponse resp=new xtreemfs_discover_dirResponse();
      resp.deserialize(b);
      return resp.getDir_service();
    }
    dsock.close();
    return null;
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    return null;
  }
}

Fixed version (ground truth):
public static DirService discoverDir(int maxWaitSeconds){
  try {
    final DatagramSocket dsock=new DatagramSocket();
    dsock.setBroadcast(true);
    dsock.setSoTimeout(1000);
    final byte[] data=new byte[2048];
    Enumeration<NetworkInterface> nifs=NetworkInterface.getNetworkInterfaces();
    List<InetAddress> broadcasts=new LinkedList();
    broadcasts.add(InetAddress.getLocalHost());
    while (nifs.hasMoreElements()) {
      NetworkInterface nif=nifs.nextElement();
      for (      InterfaceAddress ia : nif.getInterfaceAddresses()) {
        InetAddress bc=ia.getBroadcast();
        if (bc != null) {
          broadcasts.add(bc);
        }
      }
    }
    for (int i=0; i < maxWaitSeconds; i++) {
      xtreemfs_discover_dirRequest rq=new xtreemfs_discover_dirRequest();
      ONCRPCRequestHeader rqHdr=new ONCRPCRequestHeader(1,1,DIRInterface.getVersion(),rq.TAG);
      ONCRPCBufferWriter wr=new ONCRPCBufferWriter(2048);
      wr.putInt(ONCRPCRecordFragmentHeader.getFragmentHeader(rqHdr.calculateSize() + rq.calculateSize(),true));
      rqHdr.serialize(wr);
      rq.serialize(wr);
      wr.flip();
      byte[] rdata=wr.getBuffers().get(0).array();
      wr.freeBuffers();
      for (      InetAddress bc : broadcasts) {
        DatagramPacket rp=new DatagramPacket(rdata,rdata.length,bc,DIRInterface.DEFAULT_ONCRPC_PORT);
        dsock.send(rp);
      }
      DatagramPacket p=new DatagramPacket(data,data.length);
      try {
        dsock.receive(p);
      }
 catch (      SocketTimeoutException ex) {
        continue;
      }
      ReusableBuffer b=ReusableBuffer.wrap(data,0,p.getLength());
      b.position(Integer.SIZE / 8);
      ONCRPCResponseHeader respHdr=new ONCRPCResponseHeader();
      respHdr.deserialize(b);
      xtreemfs_discover_dirResponse resp=new xtreemfs_discover_dirResponse();
      resp.deserialize(b);
      return resp.getDir_service();
    }
    dsock.close();
    return null;
  }
 catch (  Exception ex) {
    ex.printStackTrace();
    return null;
  }
}