Program: 107385
Project: 107385
Buggy source:
@Override public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd){
  Account account=UserContext.current().getAccount();
  List<DataCenterVO> dcs=null;
  Long domainId=cmd.getDomainId();
  if (domainId != null) {
    dcs=_dcDao.findZonesByDomainId(domainId);
  }
 else   if ((account == null || account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
    dcs=_dcDao.listAll();
  }
 else   if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
    dcs=new ArrayList<DataCenterVO>();
    DomainVO domainRecord=_domainDao.findById(account.getDomainId());
    if (domainRecord != null) {
      while (true) {
        dcs.addAll(_dcDao.findZonesByDomainId(domainRecord.getId()));
        if (domainRecord.getParent() != null)         domainRecord=_domainDao.findById(domainRecord.getParent());
 else         break;
      }
    }
    dcs.addAll(_dcDao.listPublicZones());
  }
 else   if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
    dcs=new ArrayList<DataCenterVO>();
    DomainVO domainRecord=_domainDao.findById(account.getDomainId());
    if (domainRecord != null) {
      DomainVO localRecord=domainRecord;
      while (true) {
        dcs.addAll(_dcDao.findZonesByDomainId(localRecord.getId()));
        if (localRecord.getParent() != null)         localRecord=_domainDao.findById(localRecord.getParent());
 else         break;
      }
    }
    if (domainRecord != null) {
      List<DomainVO> allChildDomains=_domainDao.findAllChildren(domainRecord.getPath());
      List<Long> allChildDomainIds=new ArrayList<Long>();
      for (      DomainVO domain : allChildDomains) {
        allChildDomainIds.add(domain.getId());
      }
      List<DataCenterVO> childZones=_dcDao.findChildZones((allChildDomainIds.toArray()));
      dcs.addAll(childZones);
    }
    dcs.addAll(_dcDao.listPublicZones());
  }
  Boolean available=cmd.isAvailable();
  if (account != null) {
    if ((available != null) && Boolean.FALSE.equals(available)) {
      List<DomainRouterVO> routers=_routerDao.listBy(account.getId());
      for (Iterator<DataCenterVO> iter=dcs.iterator(); iter.hasNext(); ) {
        DataCenterVO dc=iter.next();
        boolean found=false;
        for (        DomainRouterVO router : routers) {
          if (dc.getId() == router.getDataCenterId()) {
            found=true;
            break;
          }
        }
        if (!found)         iter.remove();
      }
    }
  }
  return dcs;
}

Fixed version (ground truth):
@Override public List<DataCenterVO> listDataCenters(ListZonesByCmd cmd){
  Account account=UserContext.current().getAccount();
  List<DataCenterVO> dcs=null;
  Long domainId=cmd.getDomainId();
  if (domainId != null) {
    dcs=_dcDao.findZonesByDomainId(domainId);
  }
 else   if ((account == null || account.getType() == Account.ACCOUNT_TYPE_ADMIN)) {
    dcs=_dcDao.listAll();
  }
 else   if (account.getType() == Account.ACCOUNT_TYPE_NORMAL) {
    dcs=new ArrayList<DataCenterVO>();
    DomainVO domainRecord=_domainDao.findById(account.getDomainId());
    if (domainRecord != null) {
      while (true) {
        dcs.addAll(_dcDao.findZonesByDomainId(domainRecord.getId()));
        if (domainRecord.getParent() != null)         domainRecord=_domainDao.findById(domainRecord.getParent());
 else         break;
      }
    }
    dcs.addAll(_dcDao.listPublicZones());
  }
 else   if (account.getType() == Account.ACCOUNT_TYPE_DOMAIN_ADMIN) {
    dcs=new ArrayList<DataCenterVO>();
    DomainVO domainRecord=_domainDao.findById(account.getDomainId());
    if (domainRecord != null) {
      DomainVO localRecord=domainRecord;
      while (true) {
        dcs.addAll(_dcDao.findZonesByDomainId(localRecord.getId()));
        if (localRecord.getParent() != null)         localRecord=_domainDao.findById(localRecord.getParent());
 else         break;
      }
    }
    if (domainRecord != null) {
      List<DomainVO> allChildDomains=_domainDao.findAllChildren(domainRecord.getPath(),domainRecord.getId());
      List<Long> allChildDomainIds=new ArrayList<Long>();
      for (      DomainVO domain : allChildDomains) {
        allChildDomainIds.add(domain.getId());
      }
      List<DataCenterVO> childZones=_dcDao.findChildZones((allChildDomainIds.toArray()));
      dcs.addAll(childZones);
    }
    dcs.addAll(_dcDao.listPublicZones());
  }
  Boolean available=cmd.isAvailable();
  if (account != null) {
    if ((available != null) && Boolean.FALSE.equals(available)) {
      List<DomainRouterVO> routers=_routerDao.listBy(account.getId());
      for (Iterator<DataCenterVO> iter=dcs.iterator(); iter.hasNext(); ) {
        DataCenterVO dc=iter.next();
        boolean found=false;
        for (        DomainRouterVO router : routers) {
          if (dc.getId() == router.getDataCenterId()) {
            found=true;
            break;
          }
        }
        if (!found)         iter.remove();
      }
    }
  }
  return dcs;
}