Program: 89253
Project: 89253
Buggy source:
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_NET_IP_ASSIGN,eventDescription="String_Node_Str",create=true) public IpAddress allocateIP(AssociateIPAddrCmd cmd) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
  String accountName=cmd.getAccountName();
  long domainId=cmd.getDomainId();
  Long zoneId=cmd.getZoneId();
  Account caller=UserContext.current().getCaller();
  long userId=UserContext.current().getCallerUserId();
  Account ipOwner=_accountMgr.getActiveAccountByName(accountName,domainId);
  if (ipOwner == null) {
    throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domainId+ "String_Node_Str");
  }
  _accountMgr.checkAccess(caller,null,ipOwner);
  DataCenterVO zone=null;
  if (zoneId != null) {
    zone=_dcDao.findById(zoneId);
    if (zone == null) {
      throw new InvalidParameterValueException("String_Node_Str" + zoneId);
    }
    if (zone.getNetworkType() == NetworkType.Basic) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
      throw new PermissionDeniedException("String_Node_Str" + zoneId);
    }
  }
  long ownerId=ipOwner.getId();
  Long networkId=cmd.getNetworkId();
  Network network=null;
  if (networkId != null) {
    network=_networksDao.findById(networkId);
    if (network == null) {
      throw new InvalidParameterValueException("String_Node_Str" + networkId);
    }
  }
  if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != ipOwner.getId()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  VlanType vlanType=VlanType.VirtualNetwork;
  boolean assign=false;
  if (zone.getNetworkType() == NetworkType.Basic) {
    if (network.getTrafficType() == TrafficType.Guest) {
      vlanType=VlanType.DirectAttached;
      assign=true;
    }
  }
  PublicIp ip=null;
  Transaction txn=Transaction.currentTxn();
  Account accountToLock=null;
  try {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + userId + "String_Node_Str"+ ownerId);
    }
    accountToLock=_accountDao.acquireInLockTable(ownerId);
    if (accountToLock == null) {
      s_logger.warn("String_Node_Str" + ownerId);
      throw new ConcurrentOperationException("String_Node_Str");
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    _resourceLimitMgr.checkResourceLimit(accountToLock,ResourceType.public_ip);
    boolean isSourceNat=false;
    txn.start();
    boolean sharedSourceNat=false;
    Map<Network.Capability,String> sourceNatCapabilities=getNetworkServiceCapabilities(network.getId(),Service.SourceNat);
    if (sourceNatCapabilities != null) {
      String supportedSourceNatTypes=sourceNatCapabilities.get(Capability.SupportedSourceNatTypes).toLowerCase();
      if (supportedSourceNatTypes.contains("String_Node_Str")) {
        sharedSourceNat=true;
      }
    }
    if (!sharedSourceNat) {
      List<IPAddressVO> addrs=listPublicIpAddressesInVirtualNetwork(ownerId,zoneId,true,networkId);
      if (addrs.isEmpty() && network.getGuestType() == Network.GuestType.Isolated) {
        isSourceNat=true;
      }
    }
    ip=fetchNewPublicIp(zoneId,null,null,ipOwner,vlanType,network.getId(),isSourceNat,assign,null);
    if (ip == null) {
      throw new InsufficientAddressCapacityException("String_Node_Str",DataCenter.class,zoneId);
    }
    UserContext.current().setEventDetails("String_Node_Str" + ip.getId());
    Ip ipAddress=ip.getAddress();
    s_logger.debug("String_Node_Str" + ipAddress + "String_Node_Str"+ ipOwner.getId()+ "String_Node_Str"+ network.getDataCenterId());
    txn.commit();
  }
  finally {
    if (accountToLock != null) {
      _accountDao.releaseFromLockTable(ownerId);
      s_logger.debug("String_Node_Str");
    }
  }
  return ip;
}

Fixed version (ground truth):
@Override @DB @ActionEvent(eventType=EventTypes.EVENT_NET_IP_ASSIGN,eventDescription="String_Node_Str",create=true) public IpAddress allocateIP(long networkId,Account ipOwner) throws ResourceAllocationException, InsufficientAddressCapacityException, ConcurrentOperationException {
  Account caller=UserContext.current().getCaller();
  long userId=UserContext.current().getCallerUserId();
  _accountMgr.checkAccess(caller,null,ipOwner);
  long ownerId=ipOwner.getId();
  Network network=_networksDao.findById(networkId);
  if (network == null) {
    throw new InvalidParameterValueException("String_Node_Str" + networkId);
  }
  DataCenter zone=_configMgr.getZone(network.getDataCenterId());
  if (zone.getNetworkType() != NetworkType.Basic && network.getAccountId() != ipOwner.getId()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  VlanType vlanType=VlanType.VirtualNetwork;
  boolean assign=false;
  if (zone.getNetworkType() == NetworkType.Basic) {
    if (network.getTrafficType() == TrafficType.Guest) {
      vlanType=VlanType.DirectAttached;
      assign=true;
    }
  }
  if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
    throw new PermissionDeniedException("String_Node_Str" + zone.getId());
  }
  PublicIp ip=null;
  Transaction txn=Transaction.currentTxn();
  Account accountToLock=null;
  try {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str" + userId + "String_Node_Str"+ ownerId);
    }
    accountToLock=_accountDao.acquireInLockTable(ownerId);
    if (accountToLock == null) {
      s_logger.warn("String_Node_Str" + ownerId);
      throw new ConcurrentOperationException("String_Node_Str");
    }
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    _resourceLimitMgr.checkResourceLimit(accountToLock,ResourceType.public_ip);
    boolean isSourceNat=false;
    txn.start();
    boolean sharedSourceNat=false;
    Map<Network.Capability,String> sourceNatCapabilities=getNetworkServiceCapabilities(network.getId(),Service.SourceNat);
    if (sourceNatCapabilities != null) {
      String supportedSourceNatTypes=sourceNatCapabilities.get(Capability.SupportedSourceNatTypes).toLowerCase();
      if (supportedSourceNatTypes.contains("String_Node_Str")) {
        sharedSourceNat=true;
      }
    }
    if (!sharedSourceNat) {
      List<IPAddressVO> addrs=listPublicIpAddressesInVirtualNetwork(ownerId,zone.getId(),true,networkId);
      if (addrs.isEmpty() && network.getGuestType() == Network.GuestType.Isolated) {
        isSourceNat=true;
      }
    }
    ip=fetchNewPublicIp(zone.getId(),null,null,ipOwner,vlanType,network.getId(),isSourceNat,assign,null);
    if (ip == null) {
      throw new InsufficientAddressCapacityException("String_Node_Str",DataCenter.class,zone.getId());
    }
    UserContext.current().setEventDetails("String_Node_Str" + ip.getId());
    Ip ipAddress=ip.getAddress();
    s_logger.debug("String_Node_Str" + ipAddress + "String_Node_Str"+ ipOwner.getId()+ "String_Node_Str"+ network.getDataCenterId());
    txn.commit();
  }
  finally {
    if (accountToLock != null) {
      _accountDao.releaseFromLockTable(ownerId);
      s_logger.debug("String_Node_Str");
    }
  }
  return ip;
}