Program: 106137
Project: 106137
Buggy source:
@Override public void buildACLSearchParameters(Account caller,Long id,String accountName,Long projectId,List<Long> permittedAccounts,Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject,boolean listAll,boolean forProjectInvitation){
  Long domainId=domainIdRecursiveListProject.first();
  if (domainId != null) {
    Domain domain=_domainDao.findById(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId);
    }
    checkAccess(caller,domain);
  }
  if (id != null) {
    return;
  }
  if (accountName != null) {
    if (projectId != null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    Account userAccount=null;
    Domain domain=null;
    if (domainId != null) {
      userAccount=_accountDao.findActiveAccount(accountName,domainId);
      domain=_domainDao.findById(domainId);
    }
 else {
      userAccount=_accountDao.findActiveAccount(accountName,caller.getDomainId());
      domain=_domainDao.findById(caller.getDomainId());
    }
    if (userAccount != null) {
      checkAccess(caller,null,false,userAccount);
      permittedAccounts.add(userAccount.getId());
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domain.getUuid());
    }
  }
  if (projectId != null) {
    if (!forProjectInvitation) {
      if (projectId.longValue() == -1) {
        if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
          permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
        }
 else {
          domainIdRecursiveListProject.third(Project.ListProjectResourcesCriteria.ListProjectResourcesOnly);
        }
      }
 else {
        Project project=_projectMgr.getProject(projectId);
        if (project == null) {
          throw new InvalidParameterValueException("String_Node_Str" + projectId);
        }
        if (!_projectMgr.canAccessProjectAccount(caller,project.getProjectAccountId())) {
          throw new PermissionDeniedException("String_Node_Str" + caller + "String_Node_Str"+ projectId);
        }
        permittedAccounts.add(project.getProjectAccountId());
      }
    }
  }
 else {
    domainIdRecursiveListProject.third(Project.ListProjectResourcesCriteria.SkipProjectResources);
    AclRolePermission rolePerm=_aclService.getAclRolePermission(caller.getId(),AclEntityType.VM.toString(),AccessType.ListEntry);
    if (rolePerm == null) {
      throw new PermissionDeniedException("String_Node_Str");
    }
    if (permittedAccounts.isEmpty()) {
      if (rolePerm.getScope() == PermissionScope.ACCOUNT || !listAll) {
        permittedAccounts.add(caller.getId());
      }
 else {
        domainIdRecursiveListProject.first(caller.getDomainId());
      }
    }
  }
}

Fixed version (ground truth):
@Override public void buildACLSearchParameters(Account caller,Long id,String accountName,Long projectId,List<Long> permittedAccounts,Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject,boolean listAll,boolean forProjectInvitation){
  Long domainId=domainIdRecursiveListProject.first();
  if (domainId != null) {
    Domain domain=_domainDao.findById(domainId);
    if (domain == null) {
      throw new InvalidParameterValueException("String_Node_Str" + domainId);
    }
    checkAccess(caller,domain);
  }
  if (id != null) {
    return;
  }
  if (accountName != null) {
    if (projectId != null) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    Account userAccount=null;
    Domain domain=null;
    if (domainId != null) {
      userAccount=_accountDao.findActiveAccount(accountName,domainId);
      domain=_domainDao.findById(domainId);
    }
 else {
      userAccount=_accountDao.findActiveAccount(accountName,caller.getDomainId());
      domain=_domainDao.findById(caller.getDomainId());
    }
    if (userAccount != null) {
      checkAccess(caller,null,false,userAccount);
      permittedAccounts.add(userAccount.getId());
    }
 else {
      throw new InvalidParameterValueException("String_Node_Str" + accountName + "String_Node_Str"+ domain.getUuid());
    }
  }
  if (projectId != null) {
    if (!forProjectInvitation) {
      if (projectId.longValue() == -1) {
        if (caller.getType() == Account.ACCOUNT_TYPE_NORMAL) {
          permittedAccounts.addAll(_projectMgr.listPermittedProjectAccounts(caller.getId()));
        }
 else {
          domainIdRecursiveListProject.third(Project.ListProjectResourcesCriteria.ListProjectResourcesOnly);
        }
      }
 else {
        Project project=_projectMgr.getProject(projectId);
        if (project == null) {
          throw new InvalidParameterValueException("String_Node_Str" + projectId);
        }
        if (!_projectMgr.canAccessProjectAccount(caller,project.getProjectAccountId())) {
          throw new PermissionDeniedException("String_Node_Str" + caller + "String_Node_Str"+ projectId);
        }
        permittedAccounts.add(project.getProjectAccountId());
      }
    }
  }
 else {
    domainIdRecursiveListProject.third(Project.ListProjectResourcesCriteria.SkipProjectResources);
    AclRolePermission rolePerm=_aclService.getAclRolePermission(caller.getId(),AclEntityType.VM.toString(),AccessType.ListEntry);
    if (rolePerm == null) {
      throw new PermissionDeniedException("String_Node_Str");
    }
    if (permittedAccounts.isEmpty()) {
      if (rolePerm.getScope() == PermissionScope.ACCOUNT || !listAll) {
        permittedAccounts.add(caller.getId());
      }
 else       if (rolePerm.getScope() == PermissionScope.DOMAIN) {
        domainIdRecursiveListProject.first(caller.getDomainId());
      }
    }
  }
}