Program: 89168
Project: 89168
Buggy source:
@Override public List<SecurityGroupRulesVO> searchForSecurityGroupRules(ListSecurityGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
  Account caller=UserContext.current().getCaller();
  Long instanceId=cmd.getVirtualMachineId();
  String securityGroup=cmd.getSecurityGroupName();
  Long id=cmd.getId();
  Object keyword=cmd.getKeyword();
  List<Long> permittedAccounts=new ArrayList<Long>();
  if (instanceId != null) {
    UserVmVO userVM=_userVMDao.findById(instanceId);
    if (userVM == null) {
      throw new InvalidParameterValueException("String_Node_Str" + instanceId + "String_Node_Str");
    }
    _accountMgr.checkAccess(caller,null,true,userVM);
    return listSecurityGroupRulesByVM(instanceId.longValue());
  }
  List<SecurityGroupRulesVO> securityRulesList=new ArrayList<SecurityGroupRulesVO>();
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,id,cmd.getAccountName(),cmd.getProjectId(),permittedAccounts,domainIdRecursiveListProject,cmd.listAll());
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(SecurityGroupVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<SecurityGroupVO> sb=_securityGroupDao.createSearchBuilder();
  _accountMgr.buildACLSearchBuilder(sb,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.EQ);
  SearchCriteria<SecurityGroupVO> sc=sb.create();
  _accountMgr.buildACLSearchCriteria(sc,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (securityGroup != null) {
    sc.setParameters("String_Node_Str",securityGroup);
  }
  if (keyword != null) {
    SearchCriteria<SecurityGroupRulesVO> ssc=_securityGroupRulesDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,ssc);
  }
  List<SecurityGroupVO> securityGroups=_securityGroupDao.search(sc,searchFilter);
  for (  SecurityGroupVO group : securityGroups) {
    securityRulesList.addAll(_securityGroupRulesDao.listSecurityRulesByGroupId(group.getId()));
  }
  return securityRulesList;
}

Fixed version (ground truth):
@Override public List<SecurityGroupRulesVO> searchForSecurityGroupRules(ListSecurityGroupsCmd cmd) throws PermissionDeniedException, InvalidParameterValueException {
  Account caller=UserContext.current().getCaller();
  Long instanceId=cmd.getVirtualMachineId();
  String securityGroup=cmd.getSecurityGroupName();
  Long id=cmd.getId();
  Object keyword=cmd.getKeyword();
  List<Long> permittedAccounts=new ArrayList<Long>();
  if (instanceId != null) {
    UserVmVO userVM=_userVMDao.findById(instanceId);
    if (userVM == null) {
      throw new InvalidParameterValueException("String_Node_Str" + instanceId + "String_Node_Str");
    }
    _accountMgr.checkAccess(caller,null,true,userVM);
    return listSecurityGroupRulesByVM(instanceId.longValue());
  }
  List<SecurityGroupRulesVO> securityRulesList=new ArrayList<SecurityGroupRulesVO>();
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,id,cmd.getAccountName(),cmd.getProjectId(),permittedAccounts,domainIdRecursiveListProject,cmd.listAll(),false);
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(SecurityGroupVO.class,"String_Node_Str",true,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<SecurityGroupVO> sb=_securityGroupDao.createSearchBuilder();
  _accountMgr.buildACLSearchBuilder(sb,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getName(),SearchCriteria.Op.EQ);
  SearchCriteria<SecurityGroupVO> sc=sb.create();
  _accountMgr.buildACLSearchCriteria(sc,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (securityGroup != null) {
    sc.setParameters("String_Node_Str",securityGroup);
  }
  if (keyword != null) {
    SearchCriteria<SecurityGroupRulesVO> ssc=_securityGroupRulesDao.createSearchCriteria();
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    ssc.addOr("String_Node_Str",SearchCriteria.Op.LIKE,"String_Node_Str" + keyword + "String_Node_Str");
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,ssc);
  }
  List<SecurityGroupVO> securityGroups=_securityGroupDao.search(sc,searchFilter);
  for (  SecurityGroupVO group : securityGroups) {
    securityRulesList.addAll(_securityGroupRulesDao.listSecurityRulesByGroupId(group.getId()));
  }
  return securityRulesList;
}