Program: 106084
Project: 106084
Buggy source:
@Override public boolean configDhcpForSubnet(Network network,final NicProfile nic,VirtualMachineProfile profile,DeployDestination dest,List<DomainRouterVO> routers) throws ResourceUnavailableException {
  UserVmVO vm=_userVmDao.findById(profile.getId());
  _userVmDao.loadDetails(vm);
  final boolean isZoneBasic=(dest.getDataCenter().getNetworkType() == NetworkType.Basic);
  final Long podId=isZoneBasic ? dest.getPod().getId() : null;
  DomainRouterVO router=routers.get(0);
  if (router.getState() != State.Running) {
    s_logger.warn("String_Node_Str");
    throw new ResourceUnavailableException("String_Node_Str" + router.getState(),DataCenter.class,network.getDataCenterId());
  }
  NicVO domr_guest_nic=_nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(),_nicDao.getIpAddress(nic.getNetworkId(),router.getId()),VirtualMachine.Type.DomainRouter);
  if (!NetUtils.sameSubnet(domr_guest_nic.getIp4Address(),nic.getIp4Address(),nic.getNetmask())) {
    List<NicIpAliasVO> aliasIps=_nicIpAliasDao.listByNetworkIdAndState(domr_guest_nic.getNetworkId(),NicIpAlias.state.active);
    boolean ipInVmsubnet=false;
    for (    NicIpAliasVO alias : aliasIps) {
      if (NetUtils.sameSubnet(alias.getIp4Address(),nic.getIp4Address(),nic.getNetmask())) {
        ipInVmsubnet=true;
        break;
      }
    }
    PublicIp routerPublicIP=null;
    String routerAliasIp=null;
    DataCenter dc=_dcDao.findById(router.getDataCenterId());
    if (ipInVmsubnet == false) {
      try {
        if (network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared) {
          Pod pod=_podDao.findById(vm.getPodIdToDeployIn());
          Account caller=CallContext.current().getCallingAccount();
          List<VlanVO> vlanList=_vlanDao.listVlansByNetworkIdAndGateway(network.getId(),nic.getGateway());
          List<Long> vlanDbIdList=new ArrayList<Long>();
          for (          VlanVO vlan : vlanList) {
            vlanDbIdList.add(vlan.getId());
          }
          if (dc.getNetworkType() == NetworkType.Basic) {
            routerPublicIP=_ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),vm.getPodIdToDeployIn(),caller,Vlan.VlanType.DirectAttached,vlanDbIdList,nic.getNetworkId(),null,false);
          }
 else {
            routerPublicIP=_ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),null,caller,Vlan.VlanType.DirectAttached,vlanDbIdList,nic.getNetworkId(),null,false);
          }
          routerAliasIp=routerPublicIP.getAddress().addr();
        }
      }
 catch (      InsufficientAddressCapacityException e) {
        s_logger.info(e.getMessage());
        s_logger.info("String_Node_Str");
        return false;
      }
      NicIpAliasVO alias=new NicIpAliasVO(domr_guest_nic.getId(),routerAliasIp,router.getId(),CallContext.current().getCallingAccountId(),network.getDomainId(),nic.getNetworkId(),nic.getGateway(),nic.getNetmask());
      alias.setAliasCount((routerPublicIP.getIpMacAddress()));
      _nicIpAliasDao.persist(alias);
      List<IpAliasTO> ipaliasTo=new ArrayList<IpAliasTO>();
      ipaliasTo.add(new IpAliasTO(routerAliasIp,alias.getNetmask(),alias.getAliasCount().toString()));
      Commands cmds=new Commands(Command.OnError.Stop);
      createIpAlias(router,ipaliasTo,alias.getNetworkId(),cmds);
      configDnsMasq(router,network,cmds);
      boolean result=sendCommandsToRouter(router,cmds);
      if (result == false) {
        final NicIpAliasVO ipAliasVO=_nicIpAliasDao.findByInstanceIdAndNetworkId(network.getId(),router.getId());
        final PublicIp routerPublicIPFinal=routerPublicIP;
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            _nicIpAliasDao.expunge(ipAliasVO.getId());
            _ipAddressDao.unassignIpAddress(routerPublicIPFinal.getId());
          }
        }
);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
    return true;
  }
  return true;
}

Fixed version (ground truth):
@Override public boolean configDhcpForSubnet(Network network,final NicProfile nic,VirtualMachineProfile profile,DeployDestination dest,List<DomainRouterVO> routers) throws ResourceUnavailableException {
  UserVmVO vm=_userVmDao.findById(profile.getId());
  _userVmDao.loadDetails(vm);
  DomainRouterVO router=routers.get(0);
  if (router.getState() != State.Running) {
    s_logger.warn("String_Node_Str");
    throw new ResourceUnavailableException("String_Node_Str" + router.getState(),DataCenter.class,network.getDataCenterId());
  }
  NicVO domr_guest_nic=_nicDao.findByInstanceIdAndIpAddressAndVmtype(router.getId(),_nicDao.getIpAddress(nic.getNetworkId(),router.getId()),VirtualMachine.Type.DomainRouter);
  if (!NetUtils.sameSubnet(domr_guest_nic.getIp4Address(),nic.getIp4Address(),nic.getNetmask())) {
    List<NicIpAliasVO> aliasIps=_nicIpAliasDao.listByNetworkIdAndState(domr_guest_nic.getNetworkId(),NicIpAlias.state.active);
    boolean ipInVmsubnet=false;
    for (    NicIpAliasVO alias : aliasIps) {
      if (NetUtils.sameSubnet(alias.getIp4Address(),nic.getIp4Address(),nic.getNetmask())) {
        ipInVmsubnet=true;
        break;
      }
    }
    PublicIp routerPublicIP=null;
    String routerAliasIp=null;
    DataCenter dc=_dcDao.findById(router.getDataCenterId());
    if (ipInVmsubnet == false) {
      try {
        if (network.getTrafficType() == TrafficType.Guest && network.getGuestType() == GuestType.Shared) {
          _podDao.findById(vm.getPodIdToDeployIn());
          Account caller=CallContext.current().getCallingAccount();
          List<VlanVO> vlanList=_vlanDao.listVlansByNetworkIdAndGateway(network.getId(),nic.getGateway());
          List<Long> vlanDbIdList=new ArrayList<Long>();
          for (          VlanVO vlan : vlanList) {
            vlanDbIdList.add(vlan.getId());
          }
          if (dc.getNetworkType() == NetworkType.Basic) {
            routerPublicIP=_ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),vm.getPodIdToDeployIn(),caller,Vlan.VlanType.DirectAttached,vlanDbIdList,nic.getNetworkId(),null,false);
          }
 else {
            routerPublicIP=_ipAddrMgr.assignPublicIpAddressFromVlans(router.getDataCenterId(),null,caller,Vlan.VlanType.DirectAttached,vlanDbIdList,nic.getNetworkId(),null,false);
          }
          routerAliasIp=routerPublicIP.getAddress().addr();
        }
      }
 catch (      InsufficientAddressCapacityException e) {
        s_logger.info(e.getMessage());
        s_logger.info("String_Node_Str");
        return false;
      }
      NicIpAliasVO alias=new NicIpAliasVO(domr_guest_nic.getId(),routerAliasIp,router.getId(),CallContext.current().getCallingAccountId(),network.getDomainId(),nic.getNetworkId(),nic.getGateway(),nic.getNetmask());
      alias.setAliasCount((routerPublicIP.getIpMacAddress()));
      _nicIpAliasDao.persist(alias);
      List<IpAliasTO> ipaliasTo=new ArrayList<IpAliasTO>();
      ipaliasTo.add(new IpAliasTO(routerAliasIp,alias.getNetmask(),alias.getAliasCount().toString()));
      Commands cmds=new Commands(Command.OnError.Stop);
      createIpAlias(router,ipaliasTo,alias.getNetworkId(),cmds);
      configDnsMasq(router,network,cmds);
      boolean result=sendCommandsToRouter(router,cmds);
      if (result == false) {
        final NicIpAliasVO ipAliasVO=_nicIpAliasDao.findByInstanceIdAndNetworkId(network.getId(),router.getId());
        final PublicIp routerPublicIPFinal=routerPublicIP;
        Transaction.execute(new TransactionCallbackNoReturn(){
          @Override public void doInTransactionWithoutResult(          TransactionStatus status){
            _nicIpAliasDao.expunge(ipAliasVO.getId());
            _ipAddressDao.unassignIpAddress(routerPublicIPFinal.getId());
          }
        }
);
        throw new CloudRuntimeException("String_Node_Str");
      }
    }
    return true;
  }
  return true;
}