Program: 106018
Project: 106018
Buggy source:
private void locatePhysicalNetwork(){
  try {
    long id=_networkService.findPhysicalNetworkId(_zone.getId(),"String_Node_Str",TrafficType.Guest);
    _znet=_networkService.getPhysicalNetwork(id);
    List<PhysicalNetworkVO> nets=_physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(),TrafficType.Public);
    if (nets == null || nets.isEmpty()) {
      _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Public.toString(),null,null,null,null,null,null);
    }
  }
 catch (  InvalidParameterValueException e) {
    List<String> isolationMethods=new ArrayList<String>();
    isolationMethods.add("String_Node_Str");
    _znet=_networkService.createPhysicalNetwork(_zone.getId(),null,null,isolationMethods,BroadcastDomainRange.ZONE.toString(),_zone.getDomainId(),null,"String_Node_Str");
    List<PhysicalNetworkVO> nets=_physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(),TrafficType.Public);
    if (nets == null || nets.isEmpty()) {
      _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Public.toString(),null,null,null,null,null,null);
    }
  }
  if (_znet.getState() != PhysicalNetwork.State.Enabled) {
    _znet=_networkService.updatePhysicalNetwork(_znet.getId(),null,null,null,PhysicalNetwork.State.Enabled.toString());
  }
  Pair<List<? extends PhysicalNetworkTrafficType>,Integer> trafficTypes=_networkService.listTrafficTypes(_znet.getId());
  boolean found=false;
  for (  PhysicalNetworkTrafficType ttype : trafficTypes.first()) {
    if (ttype.getTrafficType() == TrafficType.Guest) {
      found=true;
    }
  }
  if (!found) {
    _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Guest.toString(),null,null,null,null,null,null);
  }
  Pair<List<? extends PhysicalNetworkServiceProvider>,Integer> providers=_networkService.listNetworkServiceProviders(_znet.getId(),Provider.JuniperContrailRouter.getName(),null,null,null);
  if (providers.second() == 0) {
    s_logger.debug("String_Node_Str" + Provider.JuniperContrailRouter.getName() + "String_Node_Str"+ _znet.getName());
    PhysicalNetworkServiceProvider provider=_networkService.addProviderToPhysicalNetwork(_znet.getId(),Provider.JuniperContrailRouter.getName(),null,null);
    _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Enabled.toString(),null);
  }
 else {
    PhysicalNetworkServiceProvider provider=providers.first().get(0);
    if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
      _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Enabled.toString(),null);
    }
  }
  providers=_networkService.listNetworkServiceProviders(_znet.getId(),null,PhysicalNetworkServiceProvider.State.Enabled.toString(),null,null);
  s_logger.debug(_znet.getName() + "String_Node_Str" + providers.second().toString()+ "String_Node_Str");
  for (  PhysicalNetworkServiceProvider provider : providers.first()) {
    if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) {
      continue;
    }
    s_logger.debug("String_Node_Str" + provider.getProviderName());
    _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Disabled.toString(),null);
  }
}

Fixed version (ground truth):
private void locatePhysicalNetwork(){
  try {
    long id=_networkService.findPhysicalNetworkId(_zone.getId(),"String_Node_Str",TrafficType.Guest);
    _znet=_networkService.getPhysicalNetwork(id);
    List<PhysicalNetworkVO> nets=_physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(),TrafficType.Public);
    if (nets == null || nets.isEmpty()) {
      _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Public.toString(),"String_Node_Str",null,null,null,null,null,null);
    }
  }
 catch (  InvalidParameterValueException e) {
    List<String> isolationMethods=new ArrayList<String>();
    isolationMethods.add("String_Node_Str");
    _znet=_networkService.createPhysicalNetwork(_zone.getId(),null,null,isolationMethods,BroadcastDomainRange.ZONE.toString(),_zone.getDomainId(),null,"String_Node_Str");
    List<PhysicalNetworkVO> nets=_physicalNetworkDao.listByZoneAndTrafficType(_zone.getId(),TrafficType.Public);
    if (nets == null || nets.isEmpty()) {
      _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Public.toString(),"String_Node_Str",null,null,null,null,null,null);
    }
  }
  if (_znet.getState() != PhysicalNetwork.State.Enabled) {
    _znet=_networkService.updatePhysicalNetwork(_znet.getId(),null,null,null,PhysicalNetwork.State.Enabled.toString());
  }
  Pair<List<? extends PhysicalNetworkTrafficType>,Integer> trafficTypes=_networkService.listTrafficTypes(_znet.getId());
  boolean found=false;
  for (  PhysicalNetworkTrafficType ttype : trafficTypes.first()) {
    if (ttype.getTrafficType() == TrafficType.Guest) {
      found=true;
    }
  }
  if (!found) {
    _networkService.addTrafficTypeToPhysicalNetwork(_znet.getId(),TrafficType.Guest.toString(),"String_Node_Str",null,null,null,null,null,null);
  }
  Pair<List<? extends PhysicalNetworkServiceProvider>,Integer> providers=_networkService.listNetworkServiceProviders(_znet.getId(),Provider.JuniperContrailRouter.getName(),null,null,null);
  if (providers.second() == 0) {
    s_logger.debug("String_Node_Str" + Provider.JuniperContrailRouter.getName() + "String_Node_Str"+ _znet.getName());
    PhysicalNetworkServiceProvider provider=_networkService.addProviderToPhysicalNetwork(_znet.getId(),Provider.JuniperContrailRouter.getName(),null,null);
    _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Enabled.toString(),null);
  }
 else {
    PhysicalNetworkServiceProvider provider=providers.first().get(0);
    if (provider.getState() != PhysicalNetworkServiceProvider.State.Enabled) {
      _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Enabled.toString(),null);
    }
  }
  providers=_networkService.listNetworkServiceProviders(_znet.getId(),null,PhysicalNetworkServiceProvider.State.Enabled.toString(),null,null);
  s_logger.debug(_znet.getName() + "String_Node_Str" + providers.second().toString()+ "String_Node_Str");
  for (  PhysicalNetworkServiceProvider provider : providers.first()) {
    if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName())) {
      continue;
    }
    s_logger.debug("String_Node_Str" + provider.getProviderName());
    _networkService.updateNetworkServiceProvider(provider.getId(),PhysicalNetworkServiceProvider.State.Disabled.toString(),null);
  }
}