Program: 105391
Project: 105391
Buggy source:
@DB protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers){
  for (  final DomainRouterVO router : routers) {
    final List<Site2SiteVpnConnectionVO> conns=_s2sVpnMgr.getConnectionsForRouter(router);
    if (conns == null || conns.isEmpty()) {
      continue;
    }
    if (router.getState() != State.Running) {
      for (      final Site2SiteVpnConnectionVO conn : conns) {
        if (conn.getState() != Site2SiteVpnConnection.State.Error) {
          conn.setState(Site2SiteVpnConnection.State.Disconnected);
          _s2sVpnConnectionDao.persist(conn);
        }
      }
      continue;
    }
    final List<String> ipList=new ArrayList<String>();
    for (    final Site2SiteVpnConnectionVO conn : conns) {
      if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
        continue;
      }
      final Site2SiteCustomerGateway gw=_s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
      ipList.add(gw.getGatewayIp());
    }
    final String privateIP=router.getPrivateIpAddress();
    final HostVO host=_hostDao.findById(router.getHostId());
    if (host == null || host.getState() != Status.Up) {
      continue;
    }
 else     if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
      continue;
    }
 else     if (privateIP != null) {
      final CheckS2SVpnConnectionsCommand command=new CheckS2SVpnConnectionsCommand(ipList);
      command.setAccessDetail(NetworkElementCommand.ROUTER_IP,getRouterControlIp(router.getId()));
      command.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
      command.setWait(30);
      final Answer origAnswer=_agentMgr.easySend(router.getHostId(),command);
      CheckS2SVpnConnectionsAnswer answer=null;
      if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
        answer=(CheckS2SVpnConnectionsAnswer)origAnswer;
      }
 else {
        s_logger.warn("String_Node_Str" + router.getHostName() + "String_Node_Str");
        continue;
      }
      if (!answer.getResult()) {
        s_logger.warn("String_Node_Str" + router.getHostName() + "String_Node_Str");
        continue;
      }
      for (      final Site2SiteVpnConnectionVO conn : conns) {
        final Site2SiteVpnConnectionVO lock=_s2sVpnConnectionDao.acquireInLockTable(conn.getId());
        if (lock == null) {
          throw new CloudRuntimeException("String_Node_Str" + lock);
        }
        try {
          if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
            continue;
          }
          final Site2SiteVpnConnection.State oldState=conn.getState();
          final Site2SiteCustomerGateway gw=_s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
          if (answer.isConnected(gw.getGatewayIp())) {
            conn.setState(Site2SiteVpnConnection.State.Connected);
          }
 else {
            conn.setState(Site2SiteVpnConnection.State.Disconnected);
          }
          _s2sVpnConnectionDao.persist(conn);
          if (oldState != conn.getState()) {
            final String title="String_Node_Str" + gw.getName() + "String_Node_Str"+ oldState+ "String_Node_Str"+ conn.getState();
            final String context="String_Node_Str" + gw.getName() + "String_Node_Str"+ router.getHostName()+ "String_Node_Str"+ router.getId()+ "String_Node_Str"+ "String_Node_Str"+ oldState+ "String_Node_Str"+ conn.getState();
            s_logger.info(context);
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,router.getDataCenterId(),router.getPodIdToDeployIn(),title,context);
          }
        }
  finally {
          _s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
        }
      }
    }
  }
}

Fixed version (ground truth):
@DB protected void updateSite2SiteVpnConnectionState(final List<DomainRouterVO> routers){
  for (  final DomainRouterVO router : routers) {
    final List<Site2SiteVpnConnectionVO> conns=_s2sVpnMgr.getConnectionsForRouter(router);
    if (conns == null || conns.isEmpty()) {
      continue;
    }
    if (router.getState() != State.Running) {
      for (      final Site2SiteVpnConnectionVO conn : conns) {
        if (conn.getState() != Site2SiteVpnConnection.State.Error) {
          conn.setState(Site2SiteVpnConnection.State.Disconnected);
          _s2sVpnConnectionDao.persist(conn);
        }
      }
      continue;
    }
    final List<String> ipList=new ArrayList<String>();
    for (    final Site2SiteVpnConnectionVO conn : conns) {
      if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
        continue;
      }
      final Site2SiteCustomerGateway gw=_s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
      ipList.add(gw.getGatewayIp());
    }
    final String privateIP=router.getPrivateIpAddress();
    final HostVO host=_hostDao.findById(router.getHostId());
    if (host == null || host.getState() != Status.Up) {
      continue;
    }
 else     if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
      continue;
    }
 else     if (privateIP != null) {
      final CheckS2SVpnConnectionsCommand command=new CheckS2SVpnConnectionsCommand(ipList);
      command.setAccessDetail(NetworkElementCommand.ROUTER_IP,getRouterControlIp(router.getId()));
      command.setAccessDetail(NetworkElementCommand.ROUTER_NAME,router.getInstanceName());
      command.setWait(30);
      final Answer origAnswer=_agentMgr.easySend(router.getHostId(),command);
      CheckS2SVpnConnectionsAnswer answer=null;
      if (origAnswer instanceof CheckS2SVpnConnectionsAnswer) {
        answer=(CheckS2SVpnConnectionsAnswer)origAnswer;
      }
 else {
        s_logger.warn("String_Node_Str" + router.getHostName() + "String_Node_Str");
        continue;
      }
      if (!answer.getResult()) {
        s_logger.warn("String_Node_Str" + router.getHostName() + "String_Node_Str");
        continue;
      }
      for (      final Site2SiteVpnConnectionVO conn : conns) {
        final Site2SiteVpnConnectionVO lock=_s2sVpnConnectionDao.acquireInLockTable(conn.getId());
        if (lock == null) {
          throw new CloudRuntimeException("String_Node_Str" + conn.getId());
        }
        try {
          if (conn.getState() != Site2SiteVpnConnection.State.Connected && conn.getState() != Site2SiteVpnConnection.State.Disconnected) {
            continue;
          }
          final Site2SiteVpnConnection.State oldState=conn.getState();
          final Site2SiteCustomerGateway gw=_s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId());
          if (answer.isConnected(gw.getGatewayIp())) {
            conn.setState(Site2SiteVpnConnection.State.Connected);
          }
 else {
            conn.setState(Site2SiteVpnConnection.State.Disconnected);
          }
          _s2sVpnConnectionDao.persist(conn);
          if (oldState != conn.getState()) {
            final String title="String_Node_Str" + gw.getName() + "String_Node_Str"+ oldState+ "String_Node_Str"+ conn.getState();
            final String context="String_Node_Str" + gw.getName() + "String_Node_Str"+ router.getHostName()+ "String_Node_Str"+ router.getId()+ "String_Node_Str"+ "String_Node_Str"+ oldState+ "String_Node_Str"+ conn.getState();
            s_logger.info(context);
            _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER,router.getDataCenterId(),router.getPodIdToDeployIn(),title,context);
          }
        }
  finally {
          _s2sVpnConnectionDao.releaseFromLockTable(lock.getId());
        }
      }
    }
  }
}