Program: 107078
Project: 107078
Buggy source:
@Override public boolean finalizeCommandsOnStart(Commands cmds,VirtualMachineProfile<DomainRouterVO> profile){
  DomainRouterVO router=profile.getVirtualMachine();
  NicProfile controlNic=null;
  for (  NicProfile nic : profile.getNics()) {
    if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
      controlNic=nic;
    }
  }
  if (controlNic == null) {
    s_logger.error("String_Node_Str" + router);
    return false;
  }
  cmds.addCommand("String_Node_Str",new CheckSshCommand(profile.getInstanceName(),controlNic.getIp4Address(),3922,5,20));
  boolean restartNetwork=true;
  if (profile.getParameter(Param.RestartNetwork) != null && (Boolean)profile.getParameter(Param.RestartNetwork) == false) {
    restartNetwork=false;
  }
  if (router.getRole() == VirtualRouter.Role.DHCP_FIREWALL_LB_PASSWD_USERDATA && restartNetwork) {
    s_logger.debug("String_Node_Str");
    long networkId=router.getNetworkId();
    long ownerId=router.getAccountId();
    long zoneId=router.getDataCenterId();
    final List<IPAddressVO> userIps=_networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId,zoneId,null,null);
    List<PublicIpAddress> publicIps=new ArrayList<PublicIpAddress>();
    if (userIps != null && !userIps.isEmpty()) {
      for (      IPAddressVO userIp : userIps) {
        PublicIp publicIp=new PublicIp(userIp,_vlanDao.findById(userIp.getVlanId()),userIp.getMacAddress());
        publicIps.add(publicIp);
      }
    }
    s_logger.debug("String_Node_Str" + publicIps.size() + "String_Node_Str"+ router+ "String_Node_Str");
    if (!publicIps.isEmpty()) {
      createAssociateIPCommands(router,publicIps,cmds,0);
      List<RemoteAccessVpn> vpns=new ArrayList<RemoteAccessVpn>();
      List<PortForwardingRule> pfRules=new ArrayList<PortForwardingRule>();
      List<FirewallRule> staticNatFirewallRules=new ArrayList<FirewallRule>();
      for (      PublicIpAddress ip : publicIps) {
        pfRules.addAll(_pfRulesDao.listForApplication(ip.getId()));
        staticNatFirewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(),Purpose.StaticNat));
        RemoteAccessVpn vpn=_vpnDao.findById(ip.getId());
        if (vpn != null) {
          vpns.add(vpn);
        }
      }
      s_logger.debug("String_Node_Str" + pfRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!pfRules.isEmpty()) {
        createApplyPortForwardingRulesCommands(pfRules,router,cmds);
      }
      s_logger.debug("String_Node_Str" + staticNatFirewallRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!staticNatFirewallRules.isEmpty()) {
        List<StaticNatRule> staticNatRules=new ArrayList<StaticNatRule>();
        for (        FirewallRule rule : staticNatFirewallRules) {
          staticNatRules.add(_rulesMgr.buildStaticNatRule(rule));
        }
        createApplyStaticNatRulesCommands(staticNatRules,router,cmds);
      }
      s_logger.debug("String_Node_Str" + vpns.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!vpns.isEmpty()) {
        for (        RemoteAccessVpn vpn : vpns) {
          createApplyVpnCommands(vpn,router,cmds);
        }
      }
      List<LoadBalancerVO> lbs=_loadBalancerDao.listByNetworkId(networkId);
      List<LoadBalancingRule> lbRules=new ArrayList<LoadBalancingRule>();
      for (      LoadBalancerVO lb : lbs) {
        List<LbDestination> dstList=_lbMgr.getExistingDestinations(lb.getId());
        LoadBalancingRule loadBalancing=new LoadBalancingRule(lb,dstList);
        lbRules.add(loadBalancing);
      }
      s_logger.debug("String_Node_Str" + lbRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!lbRules.isEmpty()) {
        createApplyLoadBalancingRulesCommands(lbRules,router,cmds);
      }
    }
  }
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  createDhcpEntriesCommands(router,cmds);
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  createVmDataCommands(router,cmds);
  cmds.addCommand("String_Node_Str",new NetworkUsageCommand(controlNic.getIp4Address(),router.getName(),"String_Node_Str"));
  return true;
}

Fixed version (ground truth):
@Override public boolean finalizeCommandsOnStart(Commands cmds,VirtualMachineProfile<DomainRouterVO> profile){
  DomainRouterVO router=profile.getVirtualMachine();
  NicProfile controlNic=null;
  for (  NicProfile nic : profile.getNics()) {
    if (nic.getTrafficType() == TrafficType.Control && nic.getIp4Address() != null) {
      controlNic=nic;
    }
  }
  if (controlNic == null) {
    s_logger.error("String_Node_Str" + router);
    return false;
  }
  cmds.addCommand("String_Node_Str",new CheckSshCommand(profile.getInstanceName(),controlNic.getIp4Address(),3922,5,20));
  boolean restartNetwork=true;
  if (profile.getParameter(Param.RestartNetwork) != null && (Boolean)profile.getParameter(Param.RestartNetwork) == false) {
    restartNetwork=false;
  }
  if (router.getRole() == VirtualRouter.Role.DHCP_FIREWALL_LB_PASSWD_USERDATA && restartNetwork) {
    s_logger.debug("String_Node_Str");
    long networkId=router.getNetworkId();
    long ownerId=router.getAccountId();
    long zoneId=router.getDataCenterId();
    final List<IPAddressVO> userIps=_networkMgr.listPublicIpAddressesInVirtualNetwork(ownerId,zoneId,null,null);
    List<PublicIpAddress> publicIps=new ArrayList<PublicIpAddress>();
    if (userIps != null && !userIps.isEmpty()) {
      for (      IPAddressVO userIp : userIps) {
        PublicIp publicIp=new PublicIp(userIp,_vlanDao.findById(userIp.getVlanId()),NetUtils.createSequenceBasedMacAddress(userIp.getMacAddress()));
        publicIps.add(publicIp);
      }
    }
    s_logger.debug("String_Node_Str" + publicIps.size() + "String_Node_Str"+ router+ "String_Node_Str");
    if (!publicIps.isEmpty()) {
      createAssociateIPCommands(router,publicIps,cmds,0);
      List<RemoteAccessVpn> vpns=new ArrayList<RemoteAccessVpn>();
      List<PortForwardingRule> pfRules=new ArrayList<PortForwardingRule>();
      List<FirewallRule> staticNatFirewallRules=new ArrayList<FirewallRule>();
      for (      PublicIpAddress ip : publicIps) {
        pfRules.addAll(_pfRulesDao.listForApplication(ip.getId()));
        staticNatFirewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(),Purpose.StaticNat));
        RemoteAccessVpn vpn=_vpnDao.findById(ip.getId());
        if (vpn != null) {
          vpns.add(vpn);
        }
      }
      s_logger.debug("String_Node_Str" + pfRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!pfRules.isEmpty()) {
        createApplyPortForwardingRulesCommands(pfRules,router,cmds);
      }
      s_logger.debug("String_Node_Str" + staticNatFirewallRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!staticNatFirewallRules.isEmpty()) {
        List<StaticNatRule> staticNatRules=new ArrayList<StaticNatRule>();
        for (        FirewallRule rule : staticNatFirewallRules) {
          staticNatRules.add(_rulesMgr.buildStaticNatRule(rule));
        }
        createApplyStaticNatRulesCommands(staticNatRules,router,cmds);
      }
      s_logger.debug("String_Node_Str" + vpns.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!vpns.isEmpty()) {
        for (        RemoteAccessVpn vpn : vpns) {
          createApplyVpnCommands(vpn,router,cmds);
        }
      }
      List<LoadBalancerVO> lbs=_loadBalancerDao.listByNetworkId(networkId);
      List<LoadBalancingRule> lbRules=new ArrayList<LoadBalancingRule>();
      for (      LoadBalancerVO lb : lbs) {
        List<LbDestination> dstList=_lbMgr.getExistingDestinations(lb.getId());
        LoadBalancingRule loadBalancing=new LoadBalancingRule(lb,dstList);
        lbRules.add(loadBalancing);
      }
      s_logger.debug("String_Node_Str" + lbRules.size() + "String_Node_Str"+ router+ "String_Node_Str");
      if (!lbRules.isEmpty()) {
        createApplyLoadBalancingRulesCommands(lbRules,router,cmds);
      }
    }
  }
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  createDhcpEntriesCommands(router,cmds);
  s_logger.debug("String_Node_Str" + router + "String_Node_Str");
  createVmDataCommands(router,cmds);
  cmds.addCommand("String_Node_Str",new NetworkUsageCommand(controlNic.getIp4Address(),router.getName(),"String_Node_Str"));
  return true;
}