Program: 89226
Project: 89226
Buggy source:
@Override @DB public void checkResourceLimit(Account account,ResourceType type,long... count) throws ResourceAllocationException {
  long numResources=((count.length == 0) ? 1 : count[0]);
  Project project=null;
  if (_accountMgr.isAdmin(account.getType())) {
    return;
  }
  if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    project=_projectDao.findByProjectAccountId(account.getId());
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  try {
    Set<Long> rowIdsToLock=_resourceCountDao.listAllRowsToUpdate(account.getId(),ResourceOwnerType.Account,type);
    SearchCriteria<ResourceCountVO> sc=ResourceCountSearch.create();
    sc.setParameters("String_Node_Str",rowIdsToLock.toArray());
    _resourceCountDao.lockRows(sc,null,true);
    long accountLimit=findCorrectResourceLimitForAccount(account,type);
    long potentialCount=_resourceCountDao.getResourceCount(account.getId(),ResourceOwnerType.Account,type) + numResources;
    if (accountLimit != -1 && potentialCount > accountLimit) {
      String message="String_Node_Str" + type + "String_Node_Str"+ account.getAccountName()+ "String_Node_Str"+ account.getDomainId()+ "String_Node_Str";
      if (project != null) {
        message="String_Node_Str" + type + "String_Node_Str"+ project.getName()+ "String_Node_Str"+ account.getDomainId()+ "String_Node_Str";
      }
      throw new ResourceAllocationException(message,type);
    }
    Long domainId=null;
    if (project != null) {
      domainId=project.getDomainId();
    }
 else {
      domainId=account.getDomainId();
    }
    while (domainId != null) {
      DomainVO domain=_domainDao.findById(domainId);
      ResourceLimitVO domainLimit=_resourceLimitDao.findByOwnerIdAndType(domainId,ResourceOwnerType.Domain,type);
      if (domainLimit != null) {
        long domainCount=_resourceCountDao.getResourceCount(domainId,ResourceOwnerType.Domain,type);
        if ((domainCount + numResources) > domainLimit.getMax().longValue()) {
          throw new ResourceAllocationException("String_Node_Str" + type + "String_Node_Str"+ domainId+ "String_Node_Str",type);
        }
      }
      domainId=domain.getParent();
    }
  }
  finally {
    txn.commit();
  }
}

Fixed version (ground truth):
@Override @DB public void checkResourceLimit(Account account,ResourceType type,long... count) throws ResourceAllocationException {
  long numResources=((count.length == 0) ? 1 : count[0]);
  Project project=null;
  if (_accountMgr.isAdmin(account.getType())) {
    return;
  }
  if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
    project=_projectDao.findByProjectAccountId(account.getId());
  }
  Transaction txn=Transaction.currentTxn();
  txn.start();
  try {
    Set<Long> rowIdsToLock=_resourceCountDao.listAllRowsToUpdate(account.getId(),ResourceOwnerType.Account,type);
    SearchCriteria<ResourceCountVO> sc=ResourceCountSearch.create();
    sc.setParameters("String_Node_Str",rowIdsToLock.toArray());
    _resourceCountDao.lockRows(sc,null,true);
    long accountLimit=findCorrectResourceLimitForAccount(account,type);
    long potentialCount=_resourceCountDao.getResourceCount(account.getId(),ResourceOwnerType.Account,type) + numResources;
    if (accountLimit != Resource.RESOURCE_UNLIMITED && potentialCount > accountLimit) {
      String message="String_Node_Str" + type + "String_Node_Str"+ account.getAccountName()+ "String_Node_Str"+ account.getDomainId()+ "String_Node_Str";
      if (project != null) {
        message="String_Node_Str" + type + "String_Node_Str"+ project.getName()+ "String_Node_Str"+ account.getDomainId()+ "String_Node_Str";
      }
      throw new ResourceAllocationException(message,type);
    }
    Long domainId=null;
    if (project != null) {
      domainId=project.getDomainId();
    }
 else {
      domainId=account.getDomainId();
    }
    while (domainId != null) {
      DomainVO domain=_domainDao.findById(domainId);
      ResourceLimitVO domainLimit=_resourceLimitDao.findByOwnerIdAndType(domainId,ResourceOwnerType.Domain,type);
      if (domainLimit != null && domainLimit.getMax().longValue() != Resource.RESOURCE_UNLIMITED) {
        long domainCount=_resourceCountDao.getResourceCount(domainId,ResourceOwnerType.Domain,type);
        if ((domainCount + numResources) > domainLimit.getMax().longValue()) {
          throw new ResourceAllocationException("String_Node_Str" + type + "String_Node_Str"+ domainId+ "String_Node_Str",type);
        }
      }
      domainId=domain.getParent();
    }
  }
  finally {
    txn.commit();
  }
}