Program: 106006
Project: 106006
Buggy source:
@DB @Override public IPAddressVO disassociatePortableIPToGuestNetwork(long ipId,long networkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
  Account caller=CallContext.current().getCallingAccount();
  Account owner=null;
  Network network=_networksDao.findById(networkId);
  if (network == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  IPAddressVO ipToAssoc=_ipAddressDao.findById(ipId);
  if (ipToAssoc != null) {
    if (ipToAssoc.getAssociatedWithNetworkId() == null) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str");
    }
    if (ipToAssoc.getAssociatedWithNetworkId() != network.getId()) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str"+ networkId);
    }
    DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Advanced) {
      if (network.getGuestType() == Network.GuestType.Shared) {
        assert(isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()));
        _accountMgr.checkAccess(CallContext.current().getCallingAccount(),AccessType.UseNetwork,false,network);
      }
    }
 else {
      _accountMgr.checkAccess(caller,null,true,ipToAssoc);
    }
    owner=_accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
  }
 else {
    s_logger.debug("String_Node_Str" + ipId);
    return null;
  }
  DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
  if (network.getAccountId() != owner.getId()) {
    if (zone.getNetworkType() != NetworkType.Basic && !(zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Shared)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  List<PublicIpAddress> ipList=new ArrayList<PublicIpAddress>();
  PublicIp publicIp=PublicIp.createFromAddrAndVlan(ipToAssoc,_vlanDao.findById(ipToAssoc.getVlanId()));
  ipList.add(publicIp);
  Map<PublicIpAddress,Set<Service>> ipToServices=_networkModel.getIpToServices(ipList,false,true);
  if (ipToServices != null & !ipToServices.isEmpty()) {
    Set<Service> services=ipToServices.get(publicIp);
    if (services != null && !services.isEmpty()) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str"+ networkId);
    }
  }
  IPAddressVO ip=_ipAddressDao.findById(ipId);
  ip.setAssociatedWithNetworkId(null);
  _ipAddressDao.update(ipId,ip);
  try {
    boolean success=applyIpAssociations(network,false);
    if (success) {
      s_logger.debug("String_Node_Str" + ip.getAddress().addr() + "String_Node_Str"+ network);
    }
 else {
      s_logger.warn("String_Node_Str" + ip.getAddress().addr() + "String_Node_Str"+ network);
    }
    return ip;
  }
  finally {
  }
}

Fixed version (ground truth):
@DB @Override public IPAddressVO disassociatePortableIPToGuestNetwork(long ipId,long networkId) throws ResourceAllocationException, ResourceUnavailableException, InsufficientAddressCapacityException, ConcurrentOperationException {
  Account caller=CallContext.current().getCallingAccount();
  Account owner=null;
  Network network=_networksDao.findById(networkId);
  if (network == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  IPAddressVO ipToAssoc=_ipAddressDao.findById(ipId);
  if (ipToAssoc != null) {
    if (ipToAssoc.getAssociatedWithNetworkId() == null) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str");
    }
    if (ipToAssoc.getAssociatedWithNetworkId() != network.getId()) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str"+ networkId);
    }
    DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
    if (zone.getNetworkType() == NetworkType.Advanced) {
      if (network.getGuestType() == Network.GuestType.Shared) {
        assert(isSharedNetworkOfferingWithServices(network.getNetworkOfferingId()));
        _accountMgr.checkAccess(CallContext.current().getCallingAccount(),AccessType.UseNetwork,false,network);
      }
    }
 else {
      _accountMgr.checkAccess(caller,null,true,ipToAssoc);
    }
    owner=_accountMgr.getAccount(ipToAssoc.getAllocatedToAccountId());
  }
 else {
    s_logger.debug("String_Node_Str" + ipId);
    return null;
  }
  DataCenter zone=_entityMgr.findById(DataCenter.class,network.getDataCenterId());
  if (network.getAccountId() != owner.getId()) {
    if (zone.getNetworkType() != NetworkType.Basic && !(zone.getNetworkType() == NetworkType.Advanced && network.getGuestType() == Network.GuestType.Shared)) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  List<PublicIpAddress> ipList=new ArrayList<PublicIpAddress>();
  PublicIp publicIp=PublicIp.createFromAddrAndVlan(ipToAssoc,_vlanDao.findById(ipToAssoc.getVlanId()));
  ipList.add(publicIp);
  Map<PublicIpAddress,Set<Service>> ipToServices=_networkModel.getIpToServices(ipList,false,true);
  if (ipToServices != null && !ipToServices.isEmpty()) {
    Set<Service> services=ipToServices.get(publicIp);
    if (services != null && !services.isEmpty()) {
      throw new InvalidParameterValueException("String_Node_Str" + ipToAssoc + "String_Node_Str"+ networkId);
    }
  }
  IPAddressVO ip=_ipAddressDao.findById(ipId);
  ip.setAssociatedWithNetworkId(null);
  _ipAddressDao.update(ipId,ip);
  try {
    boolean success=applyIpAssociations(network,false);
    if (success) {
      s_logger.debug("String_Node_Str" + ip.getAddress().addr() + "String_Node_Str"+ network);
    }
 else {
      s_logger.warn("String_Node_Str" + ip.getAddress().addr() + "String_Node_Str"+ network);
    }
    return ip;
  }
  finally {
  }
}