Program: 106134
Project: 106134
Buggy source:
private Pair<List<ServiceOfferingJoinVO>,Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd){
  Boolean isAscending=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  isAscending=(isAscending == null ? true : isAscending);
  Filter searchFilter=new Filter(ServiceOfferingJoinVO.class,"String_Node_Str",isAscending,cmd.getStartIndex(),cmd.getPageSizeVal());
  Account caller=CallContext.current().getCallingAccount();
  Object name=cmd.getServiceOfferingName();
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Long vmId=cmd.getVirtualMachineId();
  Long domainId=cmd.getDomainId();
  Boolean isSystem=cmd.getIsSystem();
  String vmTypeStr=cmd.getSystemVmType();
  Map<String,String> resourceTags=cmd.getResourceTags();
  SearchBuilder<ServiceOfferingJoinVO> sb=_srvOfferingJoinDao.createSearchBuilder();
  if (resourceTags != null && !resourceTags.isEmpty()) {
    SearchBuilder<ResourceTagVO> tagSearch=_resourceTagDao.createSearchBuilder();
    for (int count=0; count < resourceTags.size(); count++) {
      tagSearch.or().op("String_Node_Str" + String.valueOf(count),tagSearch.entity().getKey(),SearchCriteria.Op.EQ);
      tagSearch.and("String_Node_Str" + String.valueOf(count),tagSearch.entity().getValue(),SearchCriteria.Op.EQ);
      tagSearch.cp();
    }
    tagSearch.and("String_Node_Str",tagSearch.entity().getResourceType(),SearchCriteria.Op.EQ);
    sb.groupBy(sb.entity().getId());
    sb.join("String_Node_Str",tagSearch,sb.entity().getId(),tagSearch.entity().getResourceId(),JoinBuilder.JoinType.INNER);
  }
  SearchCriteria<ServiceOfferingJoinVO> sc=sb.create();
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
    if (!isPermissible(caller.getDomainId(),domainId)) {
      throw new PermissionDeniedException("String_Node_Str" + caller.getAccountName() + "String_Node_Str");
    }
  }
  if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
    if (isSystem) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    List<Long> domainIds=new ArrayList<Long>();
    DomainVO domainRecord=_domainDao.findById(caller.getDomainId());
    if (domainRecord == null) {
      s_logger.error("String_Node_Str" + caller.getAccountName());
      throw new CloudAuthenticationException("String_Node_Str" + caller.getAccountName());
    }
    domainIds.add(domainRecord.getId());
    while (domainRecord.getParent() != null) {
      domainRecord=_domainDao.findById(domainRecord.getParent());
      domainIds.add(domainRecord.getId());
    }
    SearchCriteria<ServiceOfferingJoinVO> spc=_srvOfferingJoinDao.createSearchCriteria();
    spc.addOr("String_Node_Str",SearchCriteria.Op.IN,domainIds.toArray());
    spc.addOr("String_Node_Str",SearchCriteria.Op.NULL);
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,spc);
  }
 else {
    if (caller.getDomainId() != 1 && isSystem) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (domainId != null) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,domainId);
    }
  }
  if (keyword != null) {
    SearchCriteria<ServiceOfferingJoinVO> ssc=_srvOfferingJoinDao.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);
  }
 else   if (vmId != null) {
    UserVmVO vmInstance=_userVmDao.findById(vmId);
    if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
      InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
      ex.addProxyObject(vmId.toString(),"String_Node_Str");
      throw ex;
    }
    _accountMgr.checkAccess(caller,null,true,vmInstance);
    ServiceOfferingVO offering=_srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
    sc.addAnd("String_Node_Str",SearchCriteria.Op.NEQ,offering.getId());
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,offering.getUseLocalStorage());
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (isSystem != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,isSystem);
  }
  if (name != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,name);
  }
  if (vmTypeStr != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,vmTypeStr);
  }
  if (resourceTags != null && !resourceTags.isEmpty()) {
    int count=0;
    sc.setJoinParameters("String_Node_Str","String_Node_Str",TaggedResourceType.ServiceOffering.toString());
    for (    String key : resourceTags.keySet()) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str" + String.valueOf(count),key);
      sc.setJoinParameters("String_Node_Str","String_Node_Str" + String.valueOf(count),resourceTags.get(key));
      count++;
    }
  }
  return _srvOfferingJoinDao.searchAndCount(sc,searchFilter);
}

Fixed version (ground truth):
private Pair<List<ServiceOfferingJoinVO>,Integer> searchForServiceOfferingsInternal(ListServiceOfferingsCmd cmd){
  Boolean isAscending=Boolean.parseBoolean(_configDao.getValue("String_Node_Str"));
  isAscending=(isAscending == null ? true : isAscending);
  Filter searchFilter=new Filter(ServiceOfferingJoinVO.class,"String_Node_Str",isAscending,cmd.getStartIndex(),cmd.getPageSizeVal());
  Account caller=CallContext.current().getCallingAccount();
  Object name=cmd.getServiceOfferingName();
  Object id=cmd.getId();
  Object keyword=cmd.getKeyword();
  Long vmId=cmd.getVirtualMachineId();
  Long domainId=cmd.getDomainId();
  Boolean isSystem=cmd.getIsSystem();
  String vmTypeStr=cmd.getSystemVmType();
  Map<String,String> resourceTags=cmd.getResourceTags();
  SearchBuilder<ServiceOfferingJoinVO> sb=_srvOfferingJoinDao.createSearchBuilder();
  if (resourceTags != null && !resourceTags.isEmpty()) {
    SearchBuilder<ResourceTagVO> tagSearch=_resourceTagDao.createSearchBuilder();
    for (int count=0; count < resourceTags.size(); count++) {
      tagSearch.or().op("String_Node_Str" + String.valueOf(count),tagSearch.entity().getKey(),SearchCriteria.Op.EQ);
      tagSearch.and("String_Node_Str" + String.valueOf(count),tagSearch.entity().getValue(),SearchCriteria.Op.EQ);
      tagSearch.cp();
    }
    tagSearch.and("String_Node_Str",tagSearch.entity().getResourceType(),SearchCriteria.Op.EQ);
    sb.groupBy(sb.entity().getId());
    sb.join("String_Node_Str",tagSearch,sb.entity().getId(),tagSearch.entity().getResourceId(),JoinBuilder.JoinType.INNER);
  }
  SearchCriteria<ServiceOfferingJoinVO> sc=sb.create();
  if (caller.getType() != Account.ACCOUNT_TYPE_ADMIN && isSystem) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (domainId != null && caller.getType() != Account.ACCOUNT_TYPE_ADMIN) {
    if (!isPermissible(caller.getDomainId(),domainId)) {
      throw new PermissionDeniedException("String_Node_Str" + caller.getAccountName() + "String_Node_Str");
    }
  }
  if (vmId != null) {
    UserVmVO vmInstance=_userVmDao.findById(vmId);
    if ((vmInstance == null) || (vmInstance.getRemoved() != null)) {
      InvalidParameterValueException ex=new InvalidParameterValueException("String_Node_Str");
      ex.addProxyObject(vmId.toString(),"String_Node_Str");
      throw ex;
    }
    _accountMgr.checkAccess(caller,null,true,vmInstance);
    ServiceOfferingVO offering=_srvOfferingDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
    sc.addAnd("String_Node_Str",SearchCriteria.Op.NEQ,offering.getId());
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,offering.getUseLocalStorage());
  }
  if ((caller.getType() == Account.ACCOUNT_TYPE_NORMAL || caller.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) || caller.getType() == Account.ACCOUNT_TYPE_RESOURCE_DOMAIN_ADMIN) {
    if (isSystem) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    List<Long> domainIds=new ArrayList<Long>();
    DomainVO domainRecord;
    if (vmId != null) {
      UserVmVO vmInstance=_userVmDao.findById(vmId);
      domainRecord=_domainDao.findById(vmInstance.getDomainId());
      if (domainRecord == null) {
        s_logger.error("String_Node_Str" + vmId);
        throw new CloudAuthenticationException("String_Node_Str" + vmId);
      }
    }
 else {
      domainRecord=_domainDao.findById(caller.getDomainId());
      if (domainRecord == null) {
        s_logger.error("String_Node_Str" + caller.getAccountName());
        throw new CloudAuthenticationException("String_Node_Str" + caller.getAccountName());
      }
    }
    domainIds.add(domainRecord.getId());
    while (domainRecord.getParent() != null) {
      domainRecord=_domainDao.findById(domainRecord.getParent());
      domainIds.add(domainRecord.getId());
    }
    SearchCriteria<ServiceOfferingJoinVO> spc=_srvOfferingJoinDao.createSearchCriteria();
    spc.addOr("String_Node_Str",SearchCriteria.Op.IN,domainIds.toArray());
    spc.addOr("String_Node_Str",SearchCriteria.Op.NULL);
    sc.addAnd("String_Node_Str",SearchCriteria.Op.SC,spc);
  }
 else {
    if (caller.getDomainId() != 1 && isSystem) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    if (domainId != null) {
      sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,domainId);
    }
  }
  if (keyword != null) {
    SearchCriteria<ServiceOfferingJoinVO> ssc=_srvOfferingJoinDao.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);
  }
  if (id != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,id);
  }
  if (isSystem != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,isSystem);
  }
  if (name != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,name);
  }
  if (vmTypeStr != null) {
    sc.addAnd("String_Node_Str",SearchCriteria.Op.EQ,vmTypeStr);
  }
  if (resourceTags != null && !resourceTags.isEmpty()) {
    int count=0;
    sc.setJoinParameters("String_Node_Str","String_Node_Str",TaggedResourceType.ServiceOffering.toString());
    for (    String key : resourceTags.keySet()) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str" + String.valueOf(count),key);
      sc.setJoinParameters("String_Node_Str","String_Node_Str" + String.valueOf(count),resourceTags.get(key));
      count++;
    }
  }
  return _srvOfferingJoinDao.searchAndCount(sc,searchFilter);
}