Program: 4449
Project: 4449
Buggy source:
/** 
 * Returns true if this has slots for an incoming connection, <b>without accounting for this' ultrapeer capabilities</b>.  More specifically: <ul> <li>if ultrapeerHeader==null, returns true if this has space for an  unrouted old-style connection. <li>if ultrapeerHeader.equals("true"), returns true if this has slots for a leaf connection. <li>if ultrapeerHeader.equals("false"), returns true if this has slots  for an ultrapeer connection. </ul> <tt>useragentHeader</tt> is used to prefer LimeWire and certain trusted vendors.  <tt>outgoing</tt> is currently unused, but may be used to  prefer incoming or outgoing connections in the forward.
 * @param outgoing true if this is an outgoing connection; true if incoming
 * @param ultrapeerHeader the value of the X-Ultrapeer header, or nullif it was not written
 * @param useragentHeader the value of the User-Agent header, or null ifit was not written
 * @return true if a connection of the given type is allowed
 */
public boolean allowConnection(HandshakeResponse hr,boolean leaf){
  if (!ConnectionSettings.PREFERENCING_ACTIVE.getValue())   return true;
  if (!ConnectionSettings.IGNORE_KEEP_ALIVE.getValue() && _keepAlive <= 0) {
    return false;
  }
 else   if (RouterService.isShieldedLeaf()) {
    if (hr.isGoodUltrapeer() && _shieldedConnections < PREFERRED_CONNECTIONS_FOR_LEAF) {
      return true;
    }
 else {
      return false;
    }
  }
 else   if (hr.isLeaf() || leaf) {
    if (!allowUltrapeer2LeafConnection(hr)) {
      return false;
    }
    int leaves=getNumInitializedClientConnections();
    int nonLimeWireLeaves=_nonLimeWireLeaves;
    if (!hr.isLimeWire()) {
      if (leaves < UltrapeerSettings.MAX_LEAVES.getValue() && nonLimeWireLeaves < RESERVED_NON_LIMEWIRE_LEAVES) {
        return true;
      }
 else {
        return false;
      }
    }
    if (hr.isGoodLeaf()) {
      return (leaves + RESERVED_NON_LIMEWIRE_LEAVES - nonLimeWireLeaves) < UltrapeerSettings.MAX_LEAVES.getValue();
    }
    return leaves < (UltrapeerSettings.MAX_LEAVES.getValue() - RESERVED_GOOD_LEAF_CONNECTIONS);
  }
 else   if (hr.isUltrapeer()) {
    int peers=getNumInitializedConnections();
    int nonLimeWirePeers=_nonLimeWirePeers;
    int locale_num=0;
    if (!allowUltrapeer2UltrapeerConnection(hr)) {
      return false;
    }
    if (ConnectionSettings.USE_LOCALE_PREF.getValue()) {
      if (checkLocale(hr.getLocalePref()) && _localeMatchingPeers < ConnectionSettings.NUM_LOCALE_PREF.getValue()) {
        return true;
      }
      locale_num=getNumLimeWireLocalePrefSlots();
    }
    if (!hr.isLimeWire()) {
      if (peers < ULTRAPEER_CONNECTIONS && nonLimeWirePeers < RESERVED_NON_LIMEWIRE_PEERS) {
        return true;
      }
    }
    return (peers + RESERVED_NON_LIMEWIRE_PEERS - nonLimeWirePeers + locale_num) < ULTRAPEER_CONNECTIONS;
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Returns true if this has slots for an incoming connection, <b>without accounting for this' ultrapeer capabilities</b>.  More specifically: <ul> <li>if ultrapeerHeader==null, returns true if this has space for an  unrouted old-style connection. <li>if ultrapeerHeader.equals("true"), returns true if this has slots for a leaf connection. <li>if ultrapeerHeader.equals("false"), returns true if this has slots  for an ultrapeer connection. </ul> <tt>useragentHeader</tt> is used to prefer LimeWire and certain trusted vendors.  <tt>outgoing</tt> is currently unused, but may be used to  prefer incoming or outgoing connections in the forward.
 * @param outgoing true if this is an outgoing connection; true if incoming
 * @param ultrapeerHeader the value of the X-Ultrapeer header, or nullif it was not written
 * @param useragentHeader the value of the User-Agent header, or null ifit was not written
 * @return true if a connection of the given type is allowed
 */
public boolean allowConnection(HandshakeResponse hr,boolean leaf){
  if (!ConnectionSettings.PREFERENCING_ACTIVE.getValue())   return true;
  if (!ConnectionSettings.IGNORE_KEEP_ALIVE.getValue() && _keepAlive <= 0) {
    return false;
  }
 else   if (RouterService.isShieldedLeaf()) {
    if (hr.isGoodUltrapeer() && _shieldedConnections < PREFERRED_CONNECTIONS_FOR_LEAF) {
      return true;
    }
 else {
      return false;
    }
  }
 else   if (hr.isLeaf() || leaf) {
    if (!allowUltrapeer2LeafConnection(hr)) {
      return false;
    }
    int leaves=getNumInitializedClientConnections();
    int nonLimeWireLeaves=_nonLimeWireLeaves;
    if (!hr.isLimeWire()) {
      if (leaves < UltrapeerSettings.MAX_LEAVES.getValue() && nonLimeWireLeaves < RESERVED_NON_LIMEWIRE_LEAVES) {
        return true;
      }
 else {
        return false;
      }
    }
    if (hr.isGoodLeaf()) {
      return (leaves + Math.max(0,RESERVED_NON_LIMEWIRE_LEAVES - nonLimeWireLeaves)) < UltrapeerSettings.MAX_LEAVES.getValue();
    }
    return leaves < (UltrapeerSettings.MAX_LEAVES.getValue() - RESERVED_GOOD_LEAF_CONNECTIONS);
  }
 else   if (hr.isUltrapeer()) {
    int peers=getNumInitializedConnections();
    int nonLimeWirePeers=_nonLimeWirePeers;
    int locale_num=0;
    if (!allowUltrapeer2UltrapeerConnection(hr)) {
      return false;
    }
    if (ConnectionSettings.USE_LOCALE_PREF.getValue()) {
      if (checkLocale(hr.getLocalePref()) && _localeMatchingPeers < ConnectionSettings.NUM_LOCALE_PREF.getValue()) {
        return true;
      }
      locale_num=getNumLimeWireLocalePrefSlots();
    }
    if (!hr.isLimeWire()) {
      if (peers < ULTRAPEER_CONNECTIONS && nonLimeWirePeers < RESERVED_NON_LIMEWIRE_PEERS) {
        return true;
      }
    }
    return (peers + Math.max(0,RESERVED_NON_LIMEWIRE_PEERS - nonLimeWirePeers) + locale_num) < ULTRAPEER_CONNECTIONS;
  }
  return false;
}