Program: 102929
Project: 102929
Buggy source:
/** 
 * Returns an InetAddress instance that represents the localhost, and that a socket can bind upon or distribute to peers as a contact address.
 * @param intendedDestination the destination that we'd like to use thelocalhost address with.
 * @return an InetAddress instance representing the local host, and thata socket can bind upon or distribute to peers as a contact address.
 */
public synchronized InetAddress getLocalHost(InetAddress intendedDestination){
  InetAddress localHost=null;
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + "String_Node_Str" + intendedDestination + "String_Node_Str");
  }
  String osVersion;
  if (OSUtils.IS_WINDOWS && !(osVersion=System.getProperty("String_Node_Str")).startsWith("String_Node_Str") && !osVersion.startsWith("String_Node_Str")) {
    byte[] src=Win32LocalhostRetriever.getSourceForDestination(intendedDestination.getAddress());
    if (src == null) {
      logger.warn("String_Node_Str");
    }
 else {
      try {
        localHost=InetAddress.getByAddress(src);
      }
 catch (      UnknownHostException uhe) {
        logger.warn("String_Node_Str",uhe);
      }
    }
  }
 else {
    localHostFinderSocket.connect(intendedDestination,RANDOM_ADDR_DISC_PORT);
    localHost=localHostFinderSocket.getLocalAddress();
    localHostFinderSocket.disconnect();
  }
  if (localHost == null) {
    try {
      localHost=InetAddress.getLocalHost();
    }
 catch (    UnknownHostException e) {
      logger.warn("String_Node_Str",e);
    }
  }
  if (localHost.isAnyLocalAddress()) {
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + "String_Node_Str");
    }
    try {
      if (intendedDestination instanceof Inet6Address) {
        boolean done=false;
        Enumeration<NetworkInterface> ifaces=NetworkInterface.getNetworkInterfaces();
        while (!done && ifaces.hasMoreElements()) {
          Enumeration<InetAddress> addresses=ifaces.nextElement().getInetAddresses();
          while (addresses.hasMoreElements()) {
            InetAddress address=addresses.nextElement();
            if ((address instanceof Inet6Address) && !address.isAnyLocalAddress() && !address.isLinkLocalAddress()&& !address.isLoopbackAddress()&& !address.isSiteLocalAddress()) {
              localHost=address;
              done=true;
              break;
            }
          }
        }
      }
 else {
        localHost=InetAddress.getLocalHost();
        if (!(localHost instanceof Inet4Address)) {
          boolean done=false;
          Enumeration<NetworkInterface> ifaces=NetworkInterface.getNetworkInterfaces();
          while (!done && ifaces.hasMoreElements()) {
            Enumeration<InetAddress> addresses=ifaces.nextElement().getInetAddresses();
            while (addresses.hasMoreElements()) {
              InetAddress address=addresses.nextElement();
              if ((address instanceof Inet4Address) && !address.isLoopbackAddress()) {
                localHost=address;
                done=true;
                break;
              }
            }
          }
        }
      }
    }
 catch (    Exception e) {
      logger.warn("String_Node_Str",e);
    }
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + localHost + "String_Node_Str");
  return localHost;
}

Fixed version (ground truth):
/** 
 * Returns an InetAddress instance that represents the localhost, and that a socket can bind upon or distribute to peers as a contact address.
 * @param intendedDestination the destination that we'd like to use thelocalhost address with.
 * @return an InetAddress instance representing the local host, and thata socket can bind upon or distribute to peers as a contact address.
 */
public synchronized InetAddress getLocalHost(InetAddress intendedDestination){
  InetAddress localHost=null;
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + "String_Node_Str" + intendedDestination + "String_Node_Str");
  }
  String osVersion;
  if (OSUtils.IS_WINDOWS && !(osVersion=System.getProperty("String_Node_Str")).startsWith("String_Node_Str") && !osVersion.startsWith("String_Node_Str")) {
    byte[] src=Win32LocalhostRetriever.getSourceForDestination(intendedDestination.getAddress());
    if (src == null) {
      logger.warn("String_Node_Str");
    }
 else {
      try {
        localHost=InetAddress.getByAddress(src);
      }
 catch (      UnknownHostException uhe) {
        logger.warn("String_Node_Str",uhe);
      }
    }
  }
 else {
    localHostFinderSocket.connect(intendedDestination,RANDOM_ADDR_DISC_PORT);
    localHost=localHostFinderSocket.getLocalAddress();
    localHostFinderSocket.disconnect();
  }
  if (localHost == null) {
    try {
      localHost=InetAddress.getLocalHost();
    }
 catch (    UnknownHostException e) {
      logger.warn("String_Node_Str",e);
    }
  }
  if (localHost.isAnyLocalAddress()) {
    if (logger.isTraceEnabled()) {
      logger.trace("String_Node_Str" + "String_Node_Str");
    }
    try {
      if (intendedDestination instanceof Inet6Address) {
        boolean done=false;
        Enumeration<NetworkInterface> ifaces=NetworkInterface.getNetworkInterfaces();
        while (!done && ifaces.hasMoreElements()) {
          Enumeration<InetAddress> addresses=ifaces.nextElement().getInetAddresses();
          while (addresses.hasMoreElements()) {
            InetAddress address=addresses.nextElement();
            if ((address instanceof Inet6Address) && !address.isAnyLocalAddress() && !address.isLinkLocalAddress()&& !address.isLoopbackAddress()&& !address.isSiteLocalAddress()) {
              localHost=address;
              done=true;
              break;
            }
          }
        }
      }
 else {
        if (intendedDestination instanceof Inet4Address) {
          boolean done=false;
          Enumeration<NetworkInterface> ifaces=NetworkInterface.getNetworkInterfaces();
          while (!done && ifaces.hasMoreElements()) {
            Enumeration<InetAddress> addresses=ifaces.nextElement().getInetAddresses();
            while (addresses.hasMoreElements()) {
              InetAddress address=addresses.nextElement();
              if ((address instanceof Inet4Address) && !address.isLoopbackAddress()) {
                localHost=address;
                done=true;
                break;
              }
            }
          }
        }
      }
    }
 catch (    Exception e) {
      logger.warn("String_Node_Str",e);
    }
  }
  if (logger.isTraceEnabled())   logger.trace("String_Node_Str" + localHost + "String_Node_Str");
  return localHost;
}