Program: 6756
Project: 6756
Buggy source:
private void configureUPnP(){
  RobonoboConfig roboCfg=rbnb.getConfig();
  MinaConfig minaCfg=(MinaConfig)getRobonobo().getConfig("String_Node_Str");
  roboCfg.setGatewayCfgResult("String_Node_Str");
  minaCfg.setGatewayAddress(null);
  GatewayDiscover gd=new GatewayDiscover();
  Map<InetAddress,GatewayDevice> devices;
  try {
    devices=gd.discover();
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + CodeUtil.shortClassName(e.getClass()) + "String_Node_Str");
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  if (devices.size() == 0) {
    log.info("String_Node_Str");
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  InetAddress localAddr;
  try {
    localAddr=InetAddress.getByName(minaCfg.getLocalAddress());
  }
 catch (  UnknownHostException e) {
    log.error("String_Node_Str" + minaCfg.getLocalAddress());
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  if (devices.containsKey(localAddr)) {
    log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str");
    gateway=devices.get(localAddr);
  }
 else {
    if (roboCfg.getUserSpecifiedLocalAddr()) {
      log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str"+ devices.size()+ "String_Node_Str");
      roboCfg.setGatewayCfgResult("String_Node_Str");
      return;
    }
 else {
      localAddr=devices.keySet().iterator().next();
      minaCfg.setLocalAddress(localAddr.getHostAddress());
      log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str");
      gateway=devices.get(localAddr);
    }
  }
  InetAddress gatewayIp;
  try {
    gatewayIp=InetAddress.getByName(gateway.getExternalIPAddress());
  }
 catch (  Exception e) {
    gatewayIp=null;
  }
  if (gatewayIp == null) {
    try {
      gatewayIp=getPublicIpFromSonar();
    }
 catch (    Exception e) {
      log.error("String_Node_Str",e);
      log.error("String_Node_Str");
      roboCfg.setGatewayCfgResult("String_Node_Str");
      return;
    }
  }
  Set<Integer> usedPorts=new HashSet<Integer>();
  for (int i=0; ; i++) {
    PortMappingEntry entry=new PortMappingEntry();
    try {
      if (!gateway.getGenericPortMappingEntry(i,entry))       break;
    }
 catch (    Exception e) {
      break;
    }
    int externalPort=entry.getExternalPort();
    usedPorts.add(externalPort);
    log.debug("String_Node_Str" + entry.getProtocol() + "String_Node_Str"+ externalPort+ "String_Node_Str"+ entry.getInternalClient()+ "String_Node_Str"+ entry.getInternalPort()+ "String_Node_Str"+ entry.getPortMappingDescription()+ "String_Node_Str");
  }
  String myName="String_Node_Str" + rbnb.getVersion();
  Random rand=new Random();
  int tried=0;
  do {
    try {
      int port;
      do {
        port=1025 + rand.nextInt(65535 - 1025);
      }
 while (usedPorts.contains(port));
      if (gateway.getSpecificPortMappingEntry(port,"String_Node_Str",new PortMappingEntry()))       log.info("String_Node_Str" + port);
 else {
        if (gateway.addPortMapping(port,minaCfg.getListenUdpPort(),localAddr.getHostAddress(),"String_Node_Str",myName)) {
          publicDetails=new InetSocketAddress(gatewayIp,port);
          minaCfg.setGatewayAddress(publicDetails.getAddress().getHostAddress());
          minaCfg.setGatewayUdpPort(port);
          log.info("String_Node_Str" + publicDetails);
          roboCfg.setGatewayCfgResult("String_Node_Str");
          return;
        }
 else         log.info("String_Node_Str" + port);
      }
    }
 catch (    Exception e) {
      log.error("String_Node_Str" + CodeUtil.shortClassName(e.getClass()) + "String_Node_Str");
    }
  }
 while (++tried < PORT_MAPPING_ATTEMPTS);
  log.info("String_Node_Str");
  roboCfg.setGatewayCfgResult("String_Node_Str");
}

Fixed version (ground truth):
private void configureUPnP(){
  RobonoboConfig roboCfg=rbnb.getConfig();
  MinaConfig minaCfg=(MinaConfig)getRobonobo().getConfig("String_Node_Str");
  roboCfg.setGatewayCfgResult("String_Node_Str");
  minaCfg.setGatewayAddress(null);
  GatewayDiscover gd=new GatewayDiscover();
  Map<InetAddress,GatewayDevice> devices;
  try {
    devices=gd.discover();
  }
 catch (  Exception e) {
    log.error("String_Node_Str" + CodeUtil.shortClassName(e.getClass()) + "String_Node_Str");
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  if (devices.size() == 0) {
    log.info("String_Node_Str");
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  InetAddress localAddr;
  try {
    localAddr=InetAddress.getByName(minaCfg.getLocalAddress());
  }
 catch (  UnknownHostException e) {
    log.error("String_Node_Str" + minaCfg.getLocalAddress());
    roboCfg.setGatewayCfgResult("String_Node_Str");
    return;
  }
  if (devices.containsKey(localAddr)) {
    log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str");
    gateway=devices.get(localAddr);
  }
 else {
    if (roboCfg.getUserSpecifiedLocalAddr()) {
      log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str"+ devices.size()+ "String_Node_Str");
      roboCfg.setGatewayCfgResult("String_Node_Str");
      return;
    }
 else {
      localAddr=devices.keySet().iterator().next();
      minaCfg.setLocalAddress(localAddr.getHostAddress());
      log.info("String_Node_Str" + localAddr.getHostAddress() + "String_Node_Str");
      gateway=devices.get(localAddr);
    }
  }
  InetAddress gatewayIp;
  try {
    gatewayIp=InetAddress.getByName(gateway.getExternalIPAddress());
  }
 catch (  Exception e) {
    gatewayIp=null;
  }
  if (gatewayIp == null) {
    try {
      gatewayIp=getPublicIpFromSonar();
    }
 catch (    Exception e) {
      log.error("String_Node_Str",e);
      log.error("String_Node_Str");
      roboCfg.setGatewayCfgResult("String_Node_Str");
      return;
    }
  }
  Set<Integer> usedPorts=new HashSet<Integer>();
  for (int i=0; ; i++) {
    PortMappingEntry entry=new PortMappingEntry();
    try {
      if (!gateway.getGenericPortMappingEntry(i,entry))       break;
    }
 catch (    Exception e) {
      break;
    }
    if (entry.getInternalClient().equals(localAddr.getHostAddress()) && entry.getInternalPort() == minaCfg.getListenUdpPort() && entry.getProtocol().equalsIgnoreCase("String_Node_Str")) {
      publicDetails=new InetSocketAddress(gatewayIp,entry.getExternalPort());
      minaCfg.setGatewayAddress(publicDetails.getAddress().getHostAddress());
      minaCfg.setGatewayUdpPort(entry.getExternalPort());
      log.info("String_Node_Str" + publicDetails);
      roboCfg.setGatewayCfgResult("String_Node_Str");
      return;
    }
    int externalPort=entry.getExternalPort();
    usedPorts.add(externalPort);
    log.debug("String_Node_Str" + entry.getProtocol() + "String_Node_Str"+ externalPort+ "String_Node_Str"+ entry.getInternalClient()+ "String_Node_Str"+ entry.getInternalPort()+ "String_Node_Str"+ entry.getPortMappingDescription()+ "String_Node_Str");
  }
  String myName="String_Node_Str" + rbnb.getVersion();
  Random rand=new Random();
  int tried=0;
  do {
    try {
      int port;
      do {
        port=1025 + rand.nextInt(65535 - 1025);
      }
 while (usedPorts.contains(port));
      if (gateway.getSpecificPortMappingEntry(port,"String_Node_Str",new PortMappingEntry()))       log.info("String_Node_Str" + port);
 else {
        if (gateway.addPortMapping(port,minaCfg.getListenUdpPort(),localAddr.getHostAddress(),"String_Node_Str",myName)) {
          publicDetails=new InetSocketAddress(gatewayIp,port);
          minaCfg.setGatewayAddress(publicDetails.getAddress().getHostAddress());
          minaCfg.setGatewayUdpPort(port);
          log.info("String_Node_Str" + publicDetails);
          roboCfg.setGatewayCfgResult("String_Node_Str");
          return;
        }
 else         log.info("String_Node_Str" + port);
      }
    }
 catch (    Exception e) {
      log.error("String_Node_Str" + CodeUtil.shortClassName(e.getClass()) + "String_Node_Str");
    }
  }
 while (++tried < PORT_MAPPING_ATTEMPTS);
  log.info("String_Node_Str");
  roboCfg.setGatewayCfgResult("String_Node_Str");
}