Program: 106553
Project: 106553
Buggy source:
@Override public List<EventVO> searchForEvents(ListEventsCmd cmd){
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Long id=cmd.getId();
  String type=cmd.getType();
  String level=cmd.getLevel();
  Date startDate=cmd.getStartDate();
  Date endDate=cmd.getEndDate();
  String keyword=cmd.getKeyword();
  Integer entryTime=cmd.getEntryTime();
  Integer duration=cmd.getDuration();
  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(EventVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<EventVO> sb=_eventDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    SearchBuilder<AccountVO> accountSearch=_accountDao.createSearchBuilder();
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.EQ);
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.NEQ);
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
  }
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getLevel(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getLevel(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.BETWEEN);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.GTEQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.LTEQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getStartId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.BETWEEN);
  SearchCriteria<EventVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  }
  if (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    if (isRecursive) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setParameters("String_Node_Str",domainId);
    }
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (keyword != null) {
    SearchCriteria<EventVO> ssc=_eventDao.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");
    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 (level != null) {
    sc.setParameters("String_Node_Str",level);
  }
  if (type != null) {
    sc.setParameters("String_Node_Str",type);
  }
  if (startDate != null && endDate != null) {
    sc.setParameters("String_Node_Str",startDate,endDate);
  }
 else   if (startDate != null) {
    sc.setParameters("String_Node_Str",startDate);
  }
 else   if (endDate != null) {
    sc.setParameters("String_Node_Str",endDate);
  }
  if ((entryTime != null) && (duration != null)) {
    if (entryTime <= duration) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    Calendar calMin=Calendar.getInstance();
    Calendar calMax=Calendar.getInstance();
    calMin.add(Calendar.SECOND,-entryTime);
    calMax.add(Calendar.SECOND,-duration);
    Date minTime=calMin.getTime();
    Date maxTime=calMax.getTime();
    sc.setParameters("String_Node_Str",com.cloud.event.Event.State.Completed);
    sc.setParameters("String_Node_Str",0);
    sc.setParameters("String_Node_Str",minTime,maxTime);
    List<EventVO> startedEvents=_eventDao.searchAllEvents(sc,searchFilter);
    List<EventVO> pendingEvents=new ArrayList<EventVO>();
    for (    EventVO event : startedEvents) {
      EventVO completedEvent=_eventDao.findCompletedEvent(event.getId());
      if (completedEvent == null) {
        pendingEvents.add(event);
      }
    }
    return pendingEvents;
  }
 else {
    return _eventDao.searchAllEvents(sc,searchFilter);
  }
}

Fixed version (ground truth):
@Override public List<EventVO> searchForEvents(ListEventsCmd cmd){
  Account caller=UserContext.current().getCaller();
  List<Long> permittedAccounts=new ArrayList<Long>();
  Long id=cmd.getId();
  String type=cmd.getType();
  String level=cmd.getLevel();
  Date startDate=cmd.getStartDate();
  Date endDate=cmd.getEndDate();
  String keyword=cmd.getKeyword();
  Integer entryTime=cmd.getEntryTime();
  Integer duration=cmd.getDuration();
  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(EventVO.class,"String_Node_Str",false,cmd.getStartIndex(),cmd.getPageSizeVal());
  SearchBuilder<EventVO> sb=_eventDao.createSearchBuilder();
  sb.and("String_Node_Str",sb.entity().getAccountId(),SearchCriteria.Op.IN);
  sb.and("String_Node_Str",sb.entity().getDomainId(),SearchCriteria.Op.EQ);
  if (((permittedAccounts.isEmpty()) && (domainId != null) && isRecursive)) {
    SearchBuilder<DomainVO> domainSearch=_domainDao.createSearchBuilder();
    domainSearch.and("String_Node_Str",domainSearch.entity().getPath(),SearchCriteria.Op.LIKE);
    sb.join("String_Node_Str",domainSearch,sb.entity().getDomainId(),domainSearch.entity().getId(),JoinBuilder.JoinType.INNER);
  }
  if (listProjectResourcesCriteria != null) {
    SearchBuilder<AccountVO> accountSearch=_accountDao.createSearchBuilder();
    if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.ListProjectResourcesOnly) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.EQ);
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
 else     if (listProjectResourcesCriteria == Project.ListProjectResourcesCriteria.SkipProjectResources) {
      accountSearch.and("String_Node_Str",accountSearch.entity().getType(),SearchCriteria.Op.NEQ);
      sb.join("String_Node_Str",accountSearch,sb.entity().getAccountId(),accountSearch.entity().getId(),JoinBuilder.JoinType.INNER);
    }
  }
  sb.and("String_Node_Str",sb.entity().getId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getLevel(),SearchCriteria.Op.LIKE);
  sb.and("String_Node_Str",sb.entity().getLevel(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getType(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.BETWEEN);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.GTEQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.LTEQ);
  sb.and("String_Node_Str",sb.entity().getState(),SearchCriteria.Op.NEQ);
  sb.and("String_Node_Str",sb.entity().getStartId(),SearchCriteria.Op.EQ);
  sb.and("String_Node_Str",sb.entity().getCreateDate(),SearchCriteria.Op.BETWEEN);
  SearchCriteria<EventVO> sc=sb.create();
  if (listProjectResourcesCriteria != null) {
    sc.setJoinParameters("String_Node_Str","String_Node_Str",Account.ACCOUNT_TYPE_PROJECT);
  }
  if (!permittedAccounts.isEmpty()) {
    sc.setParameters("String_Node_Str",permittedAccounts.toArray());
  }
 else   if (domainId != null) {
    DomainVO domain=_domainDao.findById(domainId);
    if (isRecursive) {
      sc.setJoinParameters("String_Node_Str","String_Node_Str",domain.getPath() + "String_Node_Str");
    }
 else {
      sc.setParameters("String_Node_Str",domainId);
    }
  }
  if (id != null) {
    sc.setParameters("String_Node_Str",id);
  }
  if (keyword != null) {
    SearchCriteria<EventVO> ssc=_eventDao.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");
    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 (level != null) {
    sc.setParameters("String_Node_Str",level);
  }
  if (type != null) {
    sc.setParameters("String_Node_Str",type);
  }
  if (startDate != null && endDate != null) {
    sc.setParameters("String_Node_Str",startDate,endDate);
  }
 else   if (startDate != null) {
    sc.setParameters("String_Node_Str",startDate);
  }
 else   if (endDate != null) {
    sc.setParameters("String_Node_Str",endDate);
  }
  if ((entryTime != null) && (duration != null)) {
    if (entryTime <= duration) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
    Calendar calMin=Calendar.getInstance();
    Calendar calMax=Calendar.getInstance();
    calMin.add(Calendar.SECOND,-entryTime);
    calMax.add(Calendar.SECOND,-duration);
    Date minTime=calMin.getTime();
    Date maxTime=calMax.getTime();
    sc.setParameters("String_Node_Str",com.cloud.event.Event.State.Completed);
    sc.setParameters("String_Node_Str",0);
    sc.setParameters("String_Node_Str",minTime,maxTime);
    List<EventVO> startedEvents=_eventDao.searchAllEvents(sc,searchFilter);
    List<EventVO> pendingEvents=new ArrayList<EventVO>();
    for (    EventVO event : startedEvents) {
      EventVO completedEvent=_eventDao.findCompletedEvent(event.getId());
      if (completedEvent == null) {
        pendingEvents.add(event);
      }
    }
    return pendingEvents;
  }
 else {
    return _eventDao.searchAllEvents(sc,searchFilter);
  }
}