Program: 106603
Project: 106603
Buggy source:
@Override public ResourceLimitVO updateResourceLimit(Long accountId,Long domainId,Integer typeId,Long max){
  Account caller=UserContext.current().getCaller();
  if (max == null) {
    max=new Long(-1);
  }
 else   if (max < -1) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ResourceType resourceType=null;
  if (typeId != null) {
    for (    ResourceType type : Resource.ResourceType.values()) {
      if (type.getOrdinal() == typeId.intValue()) {
        resourceType=type;
      }
    }
    if (resourceType == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  ResourceOwnerType ownerType=null;
  Long ownerId=null;
  if (accountId != null) {
    Account account=_entityMgr.findById(Account.class,accountId);
    if (account.getType() == Account.ACCOUNT_ID_SYSTEM) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
      _accountMgr.checkAccess(caller,AccessType.ModifyProject,account);
    }
 else {
      _accountMgr.checkAccess(caller,null,account);
    }
    ownerType=ResourceOwnerType.Account;
    ownerId=accountId;
  }
 else   if (domainId != null) {
    Domain domain=_entityMgr.findById(Domain.class,domainId);
    _accountMgr.checkAccess(caller,domain);
    if ((caller.getDomainId() == domainId.longValue()) && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
      throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
    }
    Long parentDomainId=domain.getParent();
    if (parentDomainId != null) {
      DomainVO parentDomain=_domainDao.findById(parentDomainId);
      long parentMaximum=findCorrectResourceLimitForDomain(parentDomain,resourceType);
      if ((parentMaximum >= 0) && (max.longValue() > parentMaximum)) {
        throw new InvalidParameterValueException("String_Node_Str" + domain.getName() + "String_Node_Str"+ parentDomain.getId()+ "String_Node_Str"+ parentMaximum+ "String_Node_Str"+ resourceType+ "String_Node_Str"+ parentMaximum);
      }
    }
    ownerType=ResourceOwnerType.Domain;
    ownerId=domainId;
  }
  if (ownerId == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ResourceLimitVO limit=_resourceLimitDao.findByOwnerIdAndType(ownerId,ownerType,resourceType);
  if (limit != null) {
    _resourceLimitDao.update(limit.getId(),max);
    return _resourceLimitDao.findById(limit.getId());
  }
 else {
    return _resourceLimitDao.persist(new ResourceLimitVO(resourceType,max,ownerId,ownerType));
  }
}

Fixed version (ground truth):
@Override public ResourceLimitVO updateResourceLimit(Long accountId,Long domainId,Integer typeId,Long max){
  Account caller=UserContext.current().getCaller();
  if (max == null) {
    max=new Long(Resource.RESOURCE_UNLIMITED);
  }
 else   if (max.longValue() < Resource.RESOURCE_UNLIMITED) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ResourceType resourceType=null;
  if (typeId != null) {
    for (    ResourceType type : Resource.ResourceType.values()) {
      if (type.getOrdinal() == typeId.intValue()) {
        resourceType=type;
      }
    }
    if (resourceType == null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  ResourceOwnerType ownerType=null;
  Long ownerId=null;
  if (accountId != null) {
    Account account=_entityMgr.findById(Account.class,accountId);
    if (account.getType() == Account.ACCOUNT_ID_SYSTEM) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (account.getType() == Account.ACCOUNT_TYPE_PROJECT) {
      _accountMgr.checkAccess(caller,AccessType.ModifyProject,account);
    }
 else {
      _accountMgr.checkAccess(caller,null,account);
    }
    ownerType=ResourceOwnerType.Account;
    ownerId=accountId;
  }
 else   if (domainId != null) {
    Domain domain=_entityMgr.findById(Domain.class,domainId);
    _accountMgr.checkAccess(caller,domain);
    if ((caller.getDomainId() == domainId.longValue()) && caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
      throw new PermissionDeniedException("String_Node_Str" + domainId + "String_Node_Str");
    }
    Long parentDomainId=domain.getParent();
    if (parentDomainId != null) {
      DomainVO parentDomain=_domainDao.findById(parentDomainId);
      long parentMaximum=findCorrectResourceLimitForDomain(parentDomain,resourceType);
      if ((parentMaximum >= 0) && (max.longValue() > parentMaximum)) {
        throw new InvalidParameterValueException("String_Node_Str" + domain.getName() + "String_Node_Str"+ parentDomain.getId()+ "String_Node_Str"+ parentMaximum+ "String_Node_Str"+ resourceType+ "String_Node_Str"+ parentMaximum);
      }
    }
    ownerType=ResourceOwnerType.Domain;
    ownerId=domainId;
  }
  if (ownerId == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  ResourceLimitVO limit=_resourceLimitDao.findByOwnerIdAndType(ownerId,ownerType,resourceType);
  if (limit != null) {
    _resourceLimitDao.update(limit.getId(),max);
    return _resourceLimitDao.findById(limit.getId());
  }
 else {
    return _resourceLimitDao.persist(new ResourceLimitVO(resourceType,max,ownerId,ownerType));
  }
}