Program: 89174
Project: 89174
Buggy source:
@Override public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd){
  Object keyword=cmd.getKeyword();
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  Long associatedNetworkId=cmd.getAssociatedNetworkId();
  Long zone=cmd.getZoneId();
  String address=cmd.getIpAddress();
  Long vlan=cmd.getVlanId();
  Boolean forVirtualNetwork=cmd.isForVirtualNetwork();
  Boolean forLoadBalancing=cmd.isForLoadBalancing();
  Long ipId=cmd.getId();
  Boolean sourceNat=cmd.getIsSourceNat();
  Boolean staticNat=cmd.getIsStaticNat();
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Boolean isAllocated=cmd.isAllocatedOnly();
  if (isAllocated == null) {
    isAllocated=Boolean.TRUE;
  }
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,cmd.getId(),cmd.getAccountName(),cmd.getProjectId(),permittedAccounts,domainIdRecursiveListProject,cmd.listAll());
  Long domainId=domainIdRecursiveListProject.first();
  Boolean isRecursive=domainIdRecursiveListProject.second();
  ListProjectResourcesCriteria listProjectResourcesCriteria=domainIdRecursiveListProject.third();
  Filter searchFilter=new Filter(IPAddressVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<IPAddressVO> sb=_publicIpAddressDao.createSearchBuilder();
  _accountMgr.buildACLSearchBuilder(sb,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sb.and("String_Node_Str",sb.entity().getDataCenterId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAddress(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getVlanId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getPhysicalNetworkId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAssociatedWithNetworkId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().isSourceNat(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().isOneToOneNat(),SearchCriteria.Op.EQ);
  if (forLoadBalancing != null && (Boolean)forLoadBalancing) {
    SearchBuilder<LoadBalancerVO> lbSearch=_loadbalancerDao.createSearchBuilder();
    sb.join("String_Node_Str",lbSearch,sb.entity().getId(),lbSearch.entity().getSourceIpAddressId(),JoinType.INNER);
    sb.groupBy(sb.entity().getId());
  }
  if (keyword != null && address == null) {
    sb.and("String_Node_Str",sb.entity().getAddress(),SearchCriteria.Op.LIKE);
  }
  SearchBuilder<VlanVO> vlanSearch=_vlanDao.createSearchBuilder();
  vlanSearch.and("String_Node_Str",vlanSearch.entity().getVlanType(),SearchCriteria.Op.EQ);
  sb.join("String_Node_Str",vlanSearch,sb.entity().getVlanId(),vlanSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  boolean allocatedOnly=false;
  if ((isAllocated != null) && (isAllocated == true)) {
    sb.and("String_Node_Str",sb.entity().getAllocatedTime(),SearchCriteria.Op.NNULL);
    allocatedOnly=true;
  }
  VlanType vlanType=null;
  if (forVirtualNetwork != null) {
    vlanType=(Boolean)forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
  }
 else {
    vlanType=VlanType.VirtualNetwork;
  }
  if (vlanType == VlanType.VirtualNetwork && (allocatedOnly)) {
    sb.and("String_Node_Str",sb.entity().getAssociatedWithNetworkId(),SearchCriteria.Op.NNULL);
  }
  SearchCriteria<IPAddressVO> sc=sb.create();
  _accountMgr.buildACLSearchCriteria(sc,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sc.setJoinParameters("String_Node_Str","String_Node_Str",vlanType);
  if (zone != null) {
    sc.setParameters("String_Node_Str",zone);
  }
  if (ipId != null) {
    sc.setParameters("String_Node_Str",ipId);
  }
  if (sourceNat != null) {
    sc.setParameters("String_Node_Str",sourceNat);
  }
  if (staticNat != null) {
    sc.setParameters("String_Node_Str",staticNat);
  }
  if (address == null && keyword != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + keyword + "String_Node_Str");
  }
  if (address != null) {
    sc.setParameters("String_Node_Str",address);
  }
  if (vlan != null) {
    sc.setParameters("String_Node_Str",vlan);
  }
  if (physicalNetworkId != null) {
    sc.setParameters("String_Node_Str",physicalNetworkId);
  }
  if (associatedNetworkId != null) {
    sc.setParameters("String_Node_Str",associatedNetworkId);
  }
  return _publicIpAddressDao.search(sc,searchFilter);
}

Fixed version (ground truth):
@Override public List<IPAddressVO> searchForIPAddresses(ListPublicIpAddressesCmd cmd){
  Object keyword=cmd.getKeyword();
  Long physicalNetworkId=cmd.getPhysicalNetworkId();
  Long associatedNetworkId=cmd.getAssociatedNetworkId();
  Long zone=cmd.getZoneId();
  String address=cmd.getIpAddress();
  Long vlan=cmd.getVlanId();
  Boolean forVirtualNetwork=cmd.isForVirtualNetwork();
  Boolean forLoadBalancing=cmd.isForLoadBalancing();
  Long ipId=cmd.getId();
  Boolean sourceNat=cmd.getIsSourceNat();
  Boolean staticNat=cmd.getIsStaticNat();
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Boolean isAllocated=cmd.isAllocatedOnly();
  if (isAllocated == null) {
    isAllocated=Boolean.TRUE;
  }
  Ternary<Long,Boolean,ListProjectResourcesCriteria> domainIdRecursiveListProject=new Ternary<Long,Boolean,ListProjectResourcesCriteria>(cmd.getDomainId(),cmd.isRecursive(),null);
  _accountMgr.buildACLSearchParameters(caller,cmd.getId(),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(IPAddressVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<IPAddressVO> sb=_publicIpAddressDao.createSearchBuilder();
  _accountMgr.buildACLSearchBuilder(sb,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sb.and("String_Node_Str",sb.entity().getDataCenterId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAddress(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getVlanId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getPhysicalNetworkId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getAssociatedWithNetworkId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().isSourceNat(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().isOneToOneNat(),SearchCriteria.Op.EQ);
  if (forLoadBalancing != null && (Boolean)forLoadBalancing) {
    SearchBuilder<LoadBalancerVO> lbSearch=_loadbalancerDao.createSearchBuilder();
    sb.join("String_Node_Str",lbSearch,sb.entity().getId(),lbSearch.entity().getSourceIpAddressId(),JoinType.INNER);
    sb.groupBy(sb.entity().getId());
  }
  if (keyword != null && address == null) {
    sb.and("String_Node_Str",sb.entity().getAddress(),SearchCriteria.Op.LIKE);
  }
  SearchBuilder<VlanVO> vlanSearch=_vlanDao.createSearchBuilder();
  vlanSearch.and("String_Node_Str",vlanSearch.entity().getVlanType(),SearchCriteria.Op.EQ);
  sb.join("String_Node_Str",vlanSearch,sb.entity().getVlanId(),vlanSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  boolean allocatedOnly=false;
  if ((isAllocated != null) && (isAllocated == true)) {
    sb.and("String_Node_Str",sb.entity().getAllocatedTime(),SearchCriteria.Op.NNULL);
    allocatedOnly=true;
  }
  VlanType vlanType=null;
  if (forVirtualNetwork != null) {
    vlanType=(Boolean)forVirtualNetwork ? VlanType.VirtualNetwork : VlanType.DirectAttached;
  }
 else {
    vlanType=VlanType.VirtualNetwork;
  }
  if (vlanType == VlanType.VirtualNetwork && (allocatedOnly)) {
    sb.and("String_Node_Str",sb.entity().getAssociatedWithNetworkId(),SearchCriteria.Op.NNULL);
  }
  SearchCriteria<IPAddressVO> sc=sb.create();
  _accountMgr.buildACLSearchCriteria(sc,domainId,isRecursive,permittedAccounts,listProjectResourcesCriteria);
  sc.setJoinParameters("String_Node_Str","String_Node_Str",vlanType);
  if (zone != null) {
    sc.setParameters("String_Node_Str",zone);
  }
  if (ipId != null) {
    sc.setParameters("String_Node_Str",ipId);
  }
  if (sourceNat != null) {
    sc.setParameters("String_Node_Str",sourceNat);
  }
  if (staticNat != null) {
    sc.setParameters("String_Node_Str",staticNat);
  }
  if (address == null && keyword != null) {
    sc.setParameters("String_Node_Str","String_Node_Str" + keyword + "String_Node_Str");
  }
  if (address != null) {
    sc.setParameters("String_Node_Str",address);
  }
  if (vlan != null) {
    sc.setParameters("String_Node_Str",vlan);
  }
  if (physicalNetworkId != null) {
    sc.setParameters("String_Node_Str",physicalNetworkId);
  }
  if (associatedNetworkId != null) {
    sc.setParameters("String_Node_Str",associatedNetworkId);
  }
  return _publicIpAddressDao.search(sc,searchFilter);
}