Program: 105758
Project: 105758
Buggy source:
private void finalizeMonitorServiceOnStrat(Commands cmds,VirtualMachineProfile profile,DomainRouterVO router,Provider provider,long networkId,Boolean add){
  final NetworkVO network=_networkDao.findById(networkId);
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  final List<MonitoringServiceVO> services=new ArrayList<MonitoringServiceVO>();
  if (_networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Dhcp,Provider.VirtualRouter) || _networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Dns,Provider.VirtualRouter)) {
    final MonitoringServiceVO dhcpService=_monitorServiceDao.getServiceByName(MonitoringService.Service.Dhcp.toString());
    if (dhcpService != null) {
      services.add(dhcpService);
    }
  }
  if (_networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Lb,Provider.VirtualRouter)) {
    final MonitoringServiceVO lbService=_monitorServiceDao.getServiceByName(MonitoringService.Service.LoadBalancing.toString());
    if (lbService != null) {
      services.add(lbService);
    }
  }
  final List<MonitoringServiceVO> defaultServices=_monitorServiceDao.listDefaultServices(true);
  services.addAll(defaultServices);
  final List<MonitorServiceTO> servicesTO=new ArrayList<MonitorServiceTO>();
  for (  final MonitoringServiceVO service : services) {
    final MonitorServiceTO serviceTO=new MonitorServiceTO(service.getService(),service.getProcessName(),service.getServiceName(),service.getServicePath(),service.getServicePidFile(),service.isDefaultService());
    servicesTO.add(serviceTO);
  }
  final NicProfile controlNic=getControlNic(profile);
  final SetMonitorServiceCommand command=new SetMonitorServiceCommand(servicesTO);
  command.setAccessDetail(NetworkElementCommand.ROUTER_IP,controlNic.getIp4Address());
  command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,getRouterIpInNetwork(networkId,router.getId()));
  command.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
  if (!add) {
    command.setAccessDetail(NetworkElementCommand.ROUTER_MONITORING_ENABLE,add.toString());
  }
  cmds.addCommand("String_Node_Str",command);
}

Fixed version (ground truth):
private void finalizeMonitorServiceOnStrat(Commands cmds,VirtualMachineProfile profile,DomainRouterVO router,Provider provider,long networkId,Boolean add){
  final NetworkVO network=_networkDao.findById(networkId);
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  final List<MonitoringServiceVO> services=new ArrayList<MonitoringServiceVO>();
  if (_networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Dhcp,Provider.VirtualRouter) || _networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Dns,Provider.VirtualRouter)) {
    final MonitoringServiceVO dhcpService=_monitorServiceDao.getServiceByName(MonitoringService.Service.Dhcp.toString());
    if (dhcpService != null) {
      services.add(dhcpService);
    }
  }
  if (_networkModel.isProviderSupportServiceInNetwork(network.getId(),Service.Lb,Provider.VirtualRouter)) {
    final MonitoringServiceVO lbService=_monitorServiceDao.getServiceByName(MonitoringService.Service.LoadBalancing.toString());
    if (lbService != null) {
      services.add(lbService);
    }
  }
  final List<MonitoringServiceVO> defaultServices=_monitorServiceDao.listDefaultServices(true);
  services.addAll(defaultServices);
  final List<MonitorServiceTO> servicesTO=new ArrayList<MonitorServiceTO>();
  for (  final MonitoringServiceVO service : services) {
    final MonitorServiceTO serviceTO=new MonitorServiceTO(service.getService(),service.getProcessName(),service.getServiceName(),service.getServicePath(),service.getServicePidFile(),service.isDefaultService());
    servicesTO.add(serviceTO);
  }
  final NicProfile controlNic=getControlNic(profile);
  if (controlNic == null) {
    throw new CloudRuntimeException("String_Node_Str" + profile.getInstanceName() + "String_Node_Str");
  }
  final SetMonitorServiceCommand command=new SetMonitorServiceCommand(servicesTO);
  command.setAccessDetail(NetworkElementCommand.ROUTER_IP,controlNic.getIp4Address());
  command.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP,getRouterIpInNetwork(networkId,router.getId()));
  command.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
  if (!add) {
    command.setAccessDetail(NetworkElementCommand.ROUTER_MONITORING_ENABLE,add.toString());
  }
  cmds.addCommand("String_Node_Str",command);
}