Program: 105842
Project: 105842
Buggy source:
@DB protected void checkAndCreateVpcTunnelNetworks(Host host,long vpcId){
  long hostId=host.getId();
  List<? extends Network> vpcNetworks=_vpcMgr.getVpcNetworks(vpcId);
  List<Long> vpcSpannedHostIds=_ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
  String bridgeName=generateBridgeNameForVpc(vpcId);
  boolean bridgeNotSetup=true;
  for (  Network vpcNetwork : vpcNetworks) {
    int key=getGreKey(vpcNetwork);
    List<Long> toHostIds=new ArrayList<Long>();
    List<Long> fromHostIds=new ArrayList<Long>();
    for (    Long rh : vpcSpannedHostIds) {
      if (rh == hostId) {
        continue;
      }
      OvsTunnelNetworkVO ta=_tunnelNetworkDao.getByFromToNetwork(hostId,rh.longValue(),vpcNetwork.getId());
      if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ rh.longValue());
        if (ta == null) {
          createTunnelRecord(hostId,rh.longValue(),vpcNetwork.getId(),key);
        }
        if (!toHostIds.contains(rh)) {
          toHostIds.add(rh);
        }
      }
      ta=_tunnelNetworkDao.getByFromToNetwork(rh.longValue(),hostId,vpcNetwork.getId());
      if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
        s_logger.debug("String_Node_Str" + rh.longValue() + "String_Node_Str"+ hostId);
        if (ta == null) {
          createTunnelRecord(rh.longValue(),hostId,vpcNetwork.getId(),key);
        }
        if (!fromHostIds.contains(rh)) {
          fromHostIds.add(rh);
        }
      }
    }
    try {
      String myIp=getGreEndpointIP(host,vpcNetwork);
      if (myIp == null)       throw new GreTunnelException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ host.getId());
      boolean noHost=true;
      for (      Long i : toHostIds) {
        HostVO rHost=_hostDao.findById(i);
        String otherIp=getGreEndpointIP(rHost,vpcNetwork);
        if (otherIp == null)         throw new GreTunnelException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ rHost.getId());
        Commands cmds=new Commands(new OvsCreateTunnelCommand(otherIp,key,Long.valueOf(hostId),i,vpcNetwork.getId(),myIp,bridgeName,vpcNetwork.getUuid()));
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ i+ "String_Node_Str"+ vpcNetwork.getId());
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ i);
        Answer[] answers=_agentMgr.send(hostId,cmds);
        handleCreateTunnelAnswer(answers);
        bridgeNotSetup=false;
      }
      for (      Long i : fromHostIds) {
        HostVO rHost=_hostDao.findById(i);
        String otherIp=getGreEndpointIP(rHost,vpcNetwork);
        Commands cmds=new Commands(new OvsCreateTunnelCommand(myIp,key,i,Long.valueOf(hostId),vpcNetwork.getId(),otherIp,bridgeName,vpcNetwork.getUuid()));
        s_logger.debug("String_Node_Str" + i + "String_Node_Str"+ hostId);
        Answer[] answers=_agentMgr.send(i,cmds);
        handleCreateTunnelAnswer(answers);
        bridgeNotSetup=false;
      }
    }
 catch (    GreTunnelException|OperationTimedoutException|AgentUnavailableException e) {
      s_logger.warn("String_Node_Str",e);
    }
  }
  if (bridgeNotSetup) {
    try {
      Commands cmds=new Commands(new OvsSetupBridgeCommand(bridgeName,hostId,null));
      s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
      Answer[] answers=_agentMgr.send(hostId,cmds);
      handleSetupBridgeAnswer(answers);
    }
 catch (    OperationTimedoutException|AgentUnavailableException e) {
      s_logger.warn("String_Node_Str",e);
    }
  }
  OvsVpcPhysicalTopologyConfigCommand topologyConfigCommand=prepareVpcTopologyUpdate(vpcId);
  for (  Long id : vpcSpannedHostIds) {
    if (!sendVpcTopologyChangeUpdate(topologyConfigCommand,id,bridgeName)) {
      s_logger.debug("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str");
    }
  }
}

Fixed version (ground truth):
@DB protected void checkAndCreateVpcTunnelNetworks(Host host,long vpcId){
  long hostId=host.getId();
  List<? extends Network> vpcNetworks=_vpcMgr.getVpcNetworks(vpcId);
  List<Long> vpcSpannedHostIds=_ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
  String bridgeName=generateBridgeNameForVpc(vpcId);
  boolean bridgeNotSetup=true;
  for (  Network vpcNetwork : vpcNetworks) {
    int key=getGreKey(vpcNetwork);
    List<Long> toHostIds=new ArrayList<Long>();
    List<Long> fromHostIds=new ArrayList<Long>();
    for (    Long rh : vpcSpannedHostIds) {
      if (rh == hostId) {
        continue;
      }
      OvsTunnelNetworkVO ta=_tunnelNetworkDao.getByFromToNetwork(hostId,rh.longValue(),vpcNetwork.getId());
      if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ rh.longValue());
        if (ta == null) {
          createTunnelRecord(hostId,rh.longValue(),vpcNetwork.getId(),key);
        }
        if (!toHostIds.contains(rh)) {
          toHostIds.add(rh);
        }
      }
      ta=_tunnelNetworkDao.getByFromToNetwork(rh.longValue(),hostId,vpcNetwork.getId());
      if (ta == null || ta.getState().equals(OvsTunnel.State.Failed.name())) {
        s_logger.debug("String_Node_Str" + rh.longValue() + "String_Node_Str"+ hostId);
        if (ta == null) {
          createTunnelRecord(rh.longValue(),hostId,vpcNetwork.getId(),key);
        }
        if (!fromHostIds.contains(rh)) {
          fromHostIds.add(rh);
        }
      }
    }
    try {
      String myIp=getGreEndpointIP(host,vpcNetwork);
      if (myIp == null)       throw new GreTunnelException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ host.getId());
      boolean noHost=true;
      for (      Long i : toHostIds) {
        HostVO rHost=_hostDao.findById(i);
        String otherIp=getGreEndpointIP(rHost,vpcNetwork);
        if (otherIp == null)         throw new GreTunnelException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ rHost.getId());
        Commands cmds=new Commands(new OvsCreateTunnelCommand(otherIp,key,Long.valueOf(hostId),i,vpcNetwork.getId(),myIp,bridgeName,vpcNetwork.getUuid()));
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ i+ "String_Node_Str"+ vpcNetwork.getId());
        s_logger.debug("String_Node_Str" + hostId + "String_Node_Str"+ i);
        Answer[] answers=_agentMgr.send(hostId,cmds);
        handleCreateTunnelAnswer(answers);
        bridgeNotSetup=false;
      }
      for (      Long i : fromHostIds) {
        HostVO rHost=_hostDao.findById(i);
        String otherIp=getGreEndpointIP(rHost,vpcNetwork);
        Commands cmds=new Commands(new OvsCreateTunnelCommand(myIp,key,i,Long.valueOf(hostId),vpcNetwork.getId(),otherIp,bridgeName,vpcNetwork.getUuid()));
        s_logger.debug("String_Node_Str" + i + "String_Node_Str"+ hostId);
        Answer[] answers=_agentMgr.send(i,cmds);
        handleCreateTunnelAnswer(answers);
        bridgeNotSetup=false;
      }
    }
 catch (    GreTunnelException|OperationTimedoutException|AgentUnavailableException e) {
      s_logger.warn("String_Node_Str",e);
    }
  }
  if (bridgeNotSetup) {
    try {
      Commands cmds=new Commands(new OvsSetupBridgeCommand(bridgeName,hostId,null));
      s_logger.debug("String_Node_Str" + hostId + "String_Node_Str");
      Answer[] answers=_agentMgr.send(hostId,cmds);
      handleSetupBridgeAnswer(answers);
    }
 catch (    OperationTimedoutException|AgentUnavailableException e) {
      s_logger.warn("String_Node_Str",e);
    }
  }
}