Program: 105824
Project: 105824
Buggy source:
@Override public void checkAndRemoveHostFromTunnelNetwork(Network nw,Host host){
  if (nw.getVpcId() != null && isVpcEnabledForDistributedRouter(nw.getVpcId())) {
    List<Long> vmIds=_ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(nw.getVpcId(),host.getId());
    if (vmIds != null && !vmIds.isEmpty()) {
      return;
    }
    List<? extends Network> vpcNetworks=_vpcMgr.getVpcNetworks(nw.getVpcId());
    try {
      for (      Network network : vpcNetworks) {
        int key=getGreKey(nw);
        String bridgeName=generateBridgeName(nw,key);
        List<OvsTunnelNetworkVO> peers=_tunnelNetworkDao.listByToNetwork(host.getId(),nw.getId());
        for (        OvsTunnelNetworkVO p : peers) {
          if (p.getState().equals(OvsTunnel.State.Established.name())) {
            Command cmd=new OvsDestroyTunnelCommand(p.getNetworkId(),bridgeName,p.getPortName());
            s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ p.getFrom());
            Answer ans=_agentMgr.send(p.getFrom(),cmd);
            handleDestroyTunnelAnswer(ans,p.getFrom(),p.getTo(),p.getNetworkId());
          }
        }
      }
      Command cmd=new OvsDestroyBridgeCommand(nw.getId(),generateBridgeNameForVpc(nw.getVpcId()));
      s_logger.debug("String_Node_Str" + nw.getId() + "String_Node_Str"+ host.getId());
      Answer ans=_agentMgr.send(host.getId(),cmd);
      handleDestroyBridgeAnswer(ans,host.getId(),nw.getId());
    }
 catch (    Exception e) {
    }
  }
 else {
    List<Long> vmIds=_ovsNetworkToplogyGuru.getActiveVmsInNetworkOnHost(nw.getId(),host.getId());
    if (vmIds != null && !vmIds.isEmpty()) {
      return;
    }
    try {
      int key=getGreKey(nw);
      String bridgeName=generateBridgeName(nw,key);
      Command cmd=new OvsDestroyBridgeCommand(nw.getId(),bridgeName);
      s_logger.debug("String_Node_Str" + nw.getId() + "String_Node_Str"+ host.getId());
      Answer ans=_agentMgr.send(host.getId(),cmd);
      handleDestroyBridgeAnswer(ans,host.getId(),nw.getId());
      List<OvsTunnelNetworkVO> peers=_tunnelNetworkDao.listByToNetwork(host.getId(),nw.getId());
      for (      OvsTunnelNetworkVO p : peers) {
        if (p.getState().equals(OvsTunnel.State.Established.name())) {
          cmd=new OvsDestroyTunnelCommand(p.getNetworkId(),bridgeName,p.getPortName());
          s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ p.getFrom());
          ans=_agentMgr.send(p.getFrom(),cmd);
          handleDestroyTunnelAnswer(ans,p.getFrom(),p.getTo(),p.getNetworkId());
        }
      }
    }
 catch (    Exception e) {
      s_logger.warn(String.format("String_Node_Str",e));
    }
  }
}

Fixed version (ground truth):
@Override public void checkAndRemoveHostFromTunnelNetwork(Network nw,Host host){
  if (nw.getVpcId() != null && isVpcEnabledForDistributedRouter(nw.getVpcId())) {
    List<Long> vmIds=_ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(nw.getVpcId(),host.getId());
    if (vmIds != null && !vmIds.isEmpty()) {
      return;
    }
    List<? extends Network> vpcNetworks=_vpcMgr.getVpcNetworks(nw.getVpcId());
    try {
      for (      Network network : vpcNetworks) {
        int key=getGreKey(nw);
        String bridgeName=generateBridgeName(nw,key);
        List<OvsTunnelNetworkVO> peers=_tunnelNetworkDao.listByToNetwork(host.getId(),nw.getId());
        for (        OvsTunnelNetworkVO p : peers) {
          if (p.getState().equals(OvsTunnel.State.Established.name())) {
            Command cmd=new OvsDestroyTunnelCommand(p.getNetworkId(),bridgeName,p.getPortName());
            s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ p.getFrom());
            Answer ans=_agentMgr.send(p.getFrom(),cmd);
            handleDestroyTunnelAnswer(ans,p.getFrom(),p.getTo(),p.getNetworkId());
          }
        }
      }
      Command cmd=new OvsDestroyBridgeCommand(nw.getId(),generateBridgeNameForVpc(nw.getVpcId()));
      s_logger.debug("String_Node_Str" + nw.getId() + "String_Node_Str"+ host.getId());
      Answer ans=_agentMgr.send(host.getId(),cmd);
      handleDestroyBridgeAnswer(ans,host.getId(),nw.getId());
    }
 catch (    Exception e) {
    }
  }
 else {
    List<Long> vmIds=_ovsNetworkToplogyGuru.getActiveVmsInNetworkOnHost(nw.getId(),host.getId());
    if (vmIds != null && !vmIds.isEmpty()) {
      return;
    }
    try {
      int key=getGreKey(nw);
      String bridgeName=generateBridgeName(nw,key);
      Command cmd=new OvsDestroyBridgeCommand(nw.getId(),bridgeName);
      s_logger.debug("String_Node_Str" + nw.getId() + "String_Node_Str"+ host.getId());
      Answer ans=_agentMgr.send(host.getId(),cmd);
      handleDestroyBridgeAnswer(ans,host.getId(),nw.getId());
      List<OvsTunnelNetworkVO> peers=_tunnelNetworkDao.listByToNetwork(host.getId(),nw.getId());
      for (      OvsTunnelNetworkVO p : peers) {
        if (p.getState().equals(OvsTunnel.State.Established.name())) {
          cmd=new OvsDestroyTunnelCommand(p.getNetworkId(),bridgeName,p.getPortName());
          s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str"+ p.getFrom());
          ans=_agentMgr.send(p.getFrom(),cmd);
          handleDestroyTunnelAnswer(ans,p.getFrom(),p.getTo(),p.getNetworkId());
        }
      }
    }
 catch (    Exception e) {
      s_logger.warn("String_Node_Str",e);
    }
  }
}