Program: 104128
Project: 104128
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){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + intendedDestination);
  }
  InetAddress localHost=null;
  localHostFinderSocket.connect(intendedDestination,RANDOM_ADDR_DISC_PORT);
  localHost=localHostFinderSocket.getLocalAddress();
  localHostFinderSocket.disconnect();
  if (localHost.isAnyLocalAddress()) {
    logger.trace("String_Node_Str" + "String_Node_Str");
    try {
      if (intendedDestination instanceof Inet6Address) {
        Enumeration<NetworkInterface> interfaces=NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
          NetworkInterface iface=interfaces.nextElement();
          Enumeration<InetAddress> addresses=iface.getInetAddresses();
          while (addresses.hasMoreElements()) {
            InetAddress address=addresses.nextElement();
            if (address instanceof Inet6Address) {
              if (!address.isAnyLocalAddress() && !address.isLinkLocalAddress() && !address.isSiteLocalAddress()&& !address.isLoopbackAddress()) {
                if (logger.isTraceEnabled()) {
                  logger.trace("String_Node_Str" + address);
                }
                return address;
              }
            }
          }
        }
      }
 else       localHost=InetAddress.getLocalHost();
    }
 catch (    Exception ex) {
      logger.warn("String_Node_Str",ex);
    }
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + localHost);
  }
  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){
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + intendedDestination);
  }
  InetAddress localHost=null;
  localHostFinderSocket.connect(intendedDestination,RANDOM_ADDR_DISC_PORT);
  localHost=localHostFinderSocket.getLocalAddress();
  localHostFinderSocket.disconnect();
  if (localHost.isAnyLocalAddress()) {
    logger.trace("String_Node_Str" + "String_Node_Str");
    try {
      if (intendedDestination instanceof Inet6Address) {
        Enumeration<NetworkInterface> interfaces=NetworkInterface.getNetworkInterfaces();
        while (interfaces.hasMoreElements()) {
          NetworkInterface iface=interfaces.nextElement();
          Enumeration<InetAddress> addresses=iface.getInetAddresses();
          while (addresses.hasMoreElements()) {
            InetAddress address=addresses.nextElement();
            if (address instanceof Inet6Address) {
              if (!address.isAnyLocalAddress() && !address.isLinkLocalAddress() && !address.isSiteLocalAddress()&& !address.isLoopbackAddress()) {
                if (logger.isTraceEnabled()) {
                  logger.trace("String_Node_Str" + address);
                }
                return address;
              }
            }
          }
        }
      }
 else {
        localHost=InetAddress.getLocalHost();
        if (!(localHost instanceof Inet4Address)) {
          Enumeration<NetworkInterface> interfaces=NetworkInterface.getNetworkInterfaces();
          while (interfaces.hasMoreElements()) {
            NetworkInterface iface=interfaces.nextElement();
            Enumeration<InetAddress> addresses=iface.getInetAddresses();
            while (addresses.hasMoreElements()) {
              InetAddress address=addresses.nextElement();
              if (address instanceof Inet4Address) {
                if (!address.isLoopbackAddress()) {
                  if (logger.isTraceEnabled()) {
                    logger.trace("String_Node_Str" + address);
                  }
                  return address;
                }
              }
            }
          }
        }
      }
    }
 catch (    Exception ex) {
      logger.warn("String_Node_Str",ex);
    }
  }
  if (logger.isTraceEnabled()) {
    logger.trace("String_Node_Str" + localHost);
  }
  return localHost;
}