Program: 105768
Project: 105768
Buggy source:
@Override public NicProfile prepareNic(VirtualMachineProfile vmProfile,DeployDestination dest,ReservationContext context,long nicId,Network network) throws InsufficientVirtualNetworkCapcityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
  Integer networkRate=_networkModel.getNetworkRate(network.getId(),vmProfile.getId());
  NetworkGuru guru=AdapterBase.getAdapterByName(networkGurus,network.getGuruName());
  NicVO nic=_nicDao.findById(nicId);
  NicProfile profile=null;
  if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
    nic.setState(Nic.State.Reserving);
    nic.setReservationId(context.getReservationId());
    _nicDao.update(nic.getId(),nic);
    URI broadcastUri=nic.getBroadcastUri();
    if (broadcastUri == null) {
      broadcastUri=network.getBroadcastUri();
    }
    URI isolationUri=nic.getIsolationUri();
    profile=new NicProfile(nic,network,broadcastUri,isolationUri,networkRate,_networkModel.isSecurityGroupSupportedInNetwork(network),_networkModel.getNetworkTag(vmProfile.getHypervisorType(),network));
    guru.reserve(profile,network,vmProfile,dest,context);
    nic.setIp4Address(profile.getIp4Address());
    nic.setAddressFormat(profile.getFormat());
    nic.setIp6Address(profile.getIp6Address());
    nic.setMacAddress(profile.getMacAddress());
    nic.setIsolationUri(profile.getIsolationUri());
    nic.setBroadcastUri(profile.getBroadCastUri());
    nic.setReserver(guru.getName());
    nic.setState(Nic.State.Reserved);
    nic.setNetmask(profile.getNetmask());
    nic.setGateway(profile.getGateway());
    if (profile.getStrategy() != null) {
      nic.setReservationStrategy(profile.getStrategy());
    }
    updateNic(nic,network.getId(),1);
  }
 else {
    profile=new NicProfile(nic,network,nic.getBroadcastUri(),nic.getIsolationUri(),networkRate,_networkModel.isSecurityGroupSupportedInNetwork(network),_networkModel.getNetworkTag(vmProfile.getHypervisorType(),network));
    guru.updateNicProfile(profile,network);
    nic.setState(Nic.State.Reserved);
    updateNic(nic,network.getId(),1);
  }
  List<Provider> providersToImplement=getNetworkProviders(network.getId());
  for (  NetworkElement element : networkElements) {
    if (providersToImplement.contains(element.getProvider())) {
      if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network),element.getProvider().getName())) {
        throw new CloudRuntimeException("String_Node_Str" + element.getProvider().getName() + "String_Node_Str"+ network.getPhysicalNetworkId());
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + element.getName() + "String_Node_Str"+ nic);
      }
      if (!prepareElement(element,network,profile,vmProfile,dest,context)) {
        throw new InsufficientAddressCapacityException("String_Node_Str",Network.class,network.getId());
      }
    }
  }
  profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
  guru.updateNicProfile(profile,network);
  return profile;
}

Fixed version (ground truth):
@Override public NicProfile prepareNic(VirtualMachineProfile vmProfile,DeployDestination dest,ReservationContext context,long nicId,Network network) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException, ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
  Integer networkRate=_networkModel.getNetworkRate(network.getId(),vmProfile.getId());
  NetworkGuru guru=AdapterBase.getAdapterByName(networkGurus,network.getGuruName());
  NicVO nic=_nicDao.findById(nicId);
  NicProfile profile=null;
  if (nic.getReservationStrategy() == Nic.ReservationStrategy.Start) {
    nic.setState(Nic.State.Reserving);
    nic.setReservationId(context.getReservationId());
    _nicDao.update(nic.getId(),nic);
    URI broadcastUri=nic.getBroadcastUri();
    if (broadcastUri == null) {
      broadcastUri=network.getBroadcastUri();
    }
    URI isolationUri=nic.getIsolationUri();
    profile=new NicProfile(nic,network,broadcastUri,isolationUri,networkRate,_networkModel.isSecurityGroupSupportedInNetwork(network),_networkModel.getNetworkTag(vmProfile.getHypervisorType(),network));
    guru.reserve(profile,network,vmProfile,dest,context);
    nic.setIp4Address(profile.getIp4Address());
    nic.setAddressFormat(profile.getFormat());
    nic.setIp6Address(profile.getIp6Address());
    nic.setMacAddress(profile.getMacAddress());
    nic.setIsolationUri(profile.getIsolationUri());
    nic.setBroadcastUri(profile.getBroadCastUri());
    nic.setReserver(guru.getName());
    nic.setState(Nic.State.Reserved);
    nic.setNetmask(profile.getNetmask());
    nic.setGateway(profile.getGateway());
    if (profile.getStrategy() != null) {
      nic.setReservationStrategy(profile.getStrategy());
    }
    updateNic(nic,network.getId(),1);
  }
 else {
    profile=new NicProfile(nic,network,nic.getBroadcastUri(),nic.getIsolationUri(),networkRate,_networkModel.isSecurityGroupSupportedInNetwork(network),_networkModel.getNetworkTag(vmProfile.getHypervisorType(),network));
    guru.updateNicProfile(profile,network);
    nic.setState(Nic.State.Reserved);
    updateNic(nic,network.getId(),1);
  }
  List<Provider> providersToImplement=getNetworkProviders(network.getId());
  for (  NetworkElement element : networkElements) {
    if (providersToImplement.contains(element.getProvider())) {
      if (!_networkModel.isProviderEnabledInPhysicalNetwork(_networkModel.getPhysicalNetworkId(network),element.getProvider().getName())) {
        throw new CloudRuntimeException("String_Node_Str" + element.getProvider().getName() + "String_Node_Str"+ network.getPhysicalNetworkId());
      }
      if (s_logger.isDebugEnabled()) {
        s_logger.debug("String_Node_Str" + element.getName() + "String_Node_Str"+ nic);
      }
      if (!prepareElement(element,network,profile,vmProfile,dest,context)) {
        throw new InsufficientAddressCapacityException("String_Node_Str",Network.class,network.getId());
      }
    }
  }
  profile.setSecurityGroupEnabled(_networkModel.isSecurityGroupSupportedInNetwork(network));
  guru.updateNicProfile(profile,network);
  return profile;
}