Program: 47277
Project: 47277
Buggy source:
/** 
 * Starts up two threads: one to broadcast UPnP ALIVE messages and another to listen for responses. 
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void listen() throws IOException {
  Runnable rAlive=new Runnable(){
    @Override public void run(){
      int delay=10000;
      while (true) {
        sleep(delay);
        sendAlive();
switch (delay) {
case 10000:
          delay=20000;
        break;
case 20000:
      delay=180000;
    break;
}
}
}
}
;
aliveThread=new Thread(rAlive,"String_Node_Str");
aliveThread.start();
Runnable r=new Runnable(){
@Override public void run(){
boolean bindErrorReported=false;
while (true) {
MulticastSocket multicastSocket=null;
try {
  multicastSocket=new MulticastSocket(configuration.getUpnpPort());
  if (bindErrorReported) {
    LOGGER.warn("String_Node_Str" + configuration.getUpnpPort() + "String_Node_Str");
  }
  NetworkInterface ni=NetworkConfiguration.getInstance().getNetworkInterfaceByServerName();
  if (ni != null) {
    multicastSocket.setNetworkInterface(ni);
  }
 else   if (PMS.get().getServer().getNetworkInterface() != null) {
    LOGGER.trace("String_Node_Str" + PMS.get().getServer().getNetworkInterface());
    multicastSocket.setNetworkInterface(PMS.get().getServer().getNetworkInterface());
  }
  multicastSocket.setTimeToLive(4);
  multicastSocket.setReuseAddress(true);
  InetAddress upnpAddress=getUPNPAddress();
  multicastSocket.joinGroup(upnpAddress);
  while (true) {
    byte[] buf=new byte[1024];
    DatagramPacket receivePacket=new DatagramPacket(buf,buf.length);
    multicastSocket.receive(receivePacket);
    String s=new String(receivePacket.getData());
    InetAddress address=receivePacket.getAddress();
    if (s.startsWith("String_Node_Str")) {
      String remoteAddr=address.getHostAddress();
      int remotePort=receivePacket.getPort();
      if (configuration.getIpFiltering().allowed(address)) {
        LOGGER.trace("String_Node_Str" + remoteAddr + "String_Node_Str"+ remotePort+ "String_Node_Str");
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,PMS.get().usn()) > 0) {
          sendDiscover(remoteAddr,remotePort,PMS.get().usn());
        }
      }
    }
 else     if (s.startsWith("String_Node_Str")) {
      String remoteAddr=address.getHostAddress();
      int remotePort=receivePacket.getPort();
      LOGGER.trace("String_Node_Str" + remoteAddr + "String_Node_Str"+ remotePort+ "String_Node_Str");
    }
  }
}
 catch (BindException e) {
  if (!bindErrorReported) {
    LOGGER.error("String_Node_Str" + configuration.getUpnpPort() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
  }
  bindErrorReported=true;
  sleep(5000);
}
catch (IOException e) {
  LOGGER.error("String_Node_Str",e);
  sleep(1000);
}
 finally {
  if (multicastSocket != null) {
    try {
      InetAddress upnpAddress=getUPNPAddress();
      multicastSocket.leaveGroup(upnpAddress);
    }
 catch (    IOException e) {
    }
    multicastSocket.disconnect();
    multicastSocket.close();
  }
}
}
}
}
;
listenerThread=new Thread(r,"String_Node_Str");
listenerThread.start();
}

Fixed version (ground truth):
/** 
 * Starts up two threads: one to broadcast UPnP ALIVE messages and another to listen for responses. 
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void listen() throws IOException {
  Runnable rAlive=new Runnable(){
    @Override public void run(){
      int delay=10000;
      while (true) {
        sleep(delay);
        sendAlive();
switch (delay) {
case 10000:
          delay=20000;
        break;
case 20000:
      delay=180000;
    break;
}
}
}
}
;
aliveThread=new Thread(rAlive,"String_Node_Str");
aliveThread.start();
Runnable r=new Runnable(){
@Override public void run(){
boolean bindErrorReported=false;
while (true) {
MulticastSocket multicastSocket=null;
try {
  multicastSocket=new MulticastSocket(configuration.getUpnpPort());
  if (bindErrorReported) {
    LOGGER.warn("String_Node_Str" + configuration.getUpnpPort() + "String_Node_Str");
  }
  multicastSocket.setTimeToLive(4);
  multicastSocket.setReuseAddress(true);
  InetAddress upnpAddress=getUPNPAddress();
  multicastSocket.joinGroup(upnpAddress);
  while (true) {
    byte[] buf=new byte[1024];
    DatagramPacket receivePacket=new DatagramPacket(buf,buf.length);
    multicastSocket.receive(receivePacket);
    String s=new String(receivePacket.getData());
    InetAddress address=receivePacket.getAddress();
    if (s.startsWith("String_Node_Str")) {
      String remoteAddr=address.getHostAddress();
      int remotePort=receivePacket.getPort();
      if (configuration.getIpFiltering().allowed(address)) {
        LOGGER.trace("String_Node_Str" + remoteAddr + "String_Node_Str"+ remotePort+ "String_Node_Str");
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,"String_Node_Str") > 0) {
          sendDiscover(remoteAddr,remotePort,"String_Node_Str");
        }
        if (StringUtils.indexOf(s,PMS.get().usn()) > 0) {
          sendDiscover(remoteAddr,remotePort,PMS.get().usn());
        }
      }
    }
 else     if (s.startsWith("String_Node_Str")) {
      String remoteAddr=address.getHostAddress();
      int remotePort=receivePacket.getPort();
      LOGGER.trace("String_Node_Str" + remoteAddr + "String_Node_Str"+ remotePort+ "String_Node_Str");
    }
  }
}
 catch (BindException e) {
  if (!bindErrorReported) {
    LOGGER.error("String_Node_Str" + configuration.getUpnpPort() + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ e.getMessage()+ "String_Node_Str");
  }
  bindErrorReported=true;
  sleep(5000);
}
catch (IOException e) {
  LOGGER.error("String_Node_Str",e);
  sleep(1000);
}
 finally {
  if (multicastSocket != null) {
    try {
      InetAddress upnpAddress=getUPNPAddress();
      multicastSocket.leaveGroup(upnpAddress);
    }
 catch (    IOException e) {
    }
    multicastSocket.disconnect();
    multicastSocket.close();
  }
}
}
}
}
;
listenerThread=new Thread(r,"String_Node_Str");
listenerThread.start();
}