Program: 105411
Project: 105411
Buggy source:
protected HostVO createHostVO(StartupCommand[] cmds,ServerResource resource,Map<String,String> details,List<String> hostTags,ResourceStateAdapter.Event stateEvent){
  StartupCommand startup=cmds[0];
  HostVO host=findHostByGuid(startup.getGuid());
  boolean isNew=false;
  if (host == null) {
    host=findHostByGuid(startup.getGuidWithoutResource());
  }
  if (host == null) {
    host=new HostVO(startup.getGuid());
    isNew=true;
  }
  String dataCenter=startup.getDataCenter();
  String pod=startup.getPod();
  String cluster=startup.getCluster();
  if (pod != null && dataCenter != null && pod.equalsIgnoreCase("String_Node_Str") && dataCenter.equalsIgnoreCase("String_Node_Str")) {
    List<HostPodVO> pods=_podDao.listAllIncludingRemoved();
    for (    HostPodVO hpv : pods) {
      if (checkCIDR(hpv,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
        pod=hpv.getName();
        dataCenter=_dcDao.findById(hpv.getDataCenterId()).getName();
        break;
      }
    }
  }
  long dcId=-1;
  DataCenterVO dc=_dcDao.findByName(dataCenter);
  if (dc == null) {
    try {
      dcId=Long.parseLong(dataCenter);
      dc=_dcDao.findById(dcId);
    }
 catch (    final NumberFormatException e) {
      s_logger.debug("String_Node_Str" + dataCenter + "String_Node_Str");
    }
  }
  if (dc == null) {
    throw new IllegalArgumentException("String_Node_Str" + startup.getPrivateIpAddress() + "String_Node_Str"+ dataCenter);
  }
  dcId=dc.getId();
  HostPodVO p=_podDao.findByName(pod,dcId);
  if (p == null) {
    try {
      final long podId=Long.parseLong(pod);
      p=_podDao.findById(podId);
    }
 catch (    final NumberFormatException e) {
      s_logger.debug("String_Node_Str" + pod + "String_Node_Str");
    }
  }
  Long podId=(p == null ? null : p.getId());
  Long clusterId=null;
  if (cluster != null) {
    try {
      clusterId=Long.valueOf(cluster);
    }
 catch (    NumberFormatException e) {
      ClusterVO c=_clusterDao.findBy(cluster,podId);
      if (c == null) {
        c=new ClusterVO(dcId,podId,cluster);
        c=_clusterDao.persist(c);
      }
      clusterId=c.getId();
    }
  }
  if (startup instanceof StartupRoutingCommand) {
    StartupRoutingCommand ssCmd=((StartupRoutingCommand)startup);
    List<String> implicitHostTags=ssCmd.getHostTags();
    if (!implicitHostTags.isEmpty()) {
      if (hostTags == null) {
        hostTags=_hostTagsDao.gethostTags(host.getId());
      }
      if (hostTags != null) {
        implicitHostTags.removeAll(hostTags);
        hostTags.addAll(implicitHostTags);
      }
 else {
        hostTags=implicitHostTags;
      }
    }
  }
  host.setDataCenterId(dc.getId());
  host.setPodId(podId);
  host.setClusterId(clusterId);
  host.setPrivateIpAddress(startup.getPrivateIpAddress());
  host.setPrivateNetmask(startup.getPrivateNetmask());
  host.setPrivateMacAddress(startup.getPrivateMacAddress());
  host.setPublicIpAddress(startup.getPublicIpAddress());
  host.setPublicMacAddress(startup.getPublicMacAddress());
  host.setPublicNetmask(startup.getPublicNetmask());
  host.setStorageIpAddress(startup.getStorageIpAddress());
  host.setStorageMacAddress(startup.getStorageMacAddress());
  host.setStorageNetmask(startup.getStorageNetmask());
  host.setVersion(startup.getVersion());
  host.setName(startup.getName());
  host.setManagementServerId(_nodeId);
  host.setStorageUrl(startup.getIqn());
  host.setLastPinged(System.currentTimeMillis() >> 10);
  host.setHostTags(hostTags);
  host.setDetails(details);
  if (startup.getStorageIpAddressDeux() != null) {
    host.setStorageIpAddressDeux(startup.getStorageIpAddressDeux());
    host.setStorageMacAddressDeux(startup.getStorageMacAddressDeux());
    host.setStorageNetmaskDeux(startup.getStorageNetmaskDeux());
  }
  if (resource != null) {
    host.setResource(resource.getClass().getName());
  }
  host=(HostVO)dispatchToStateAdapters(stateEvent,true,host,cmds,resource,details,hostTags);
  if (host == null) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  if (isNew) {
    host=_hostDao.persist(host);
  }
 else {
    _hostDao.update(host.getId(),host);
  }
  try {
    resourceStateTransitTo(host,ResourceState.Event.InternalCreated,_nodeId);
    _agentMgr.agentStatusTransitTo(host,Status.Event.AgentConnected,_nodeId);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
    _agentMgr.agentStatusTransitTo(host,Status.Event.Error,_nodeId);
    try {
      resourceStateTransitTo(host,ResourceState.Event.Error,_nodeId);
    }
 catch (    NoTransitionException e1) {
      s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
    }
  }
  return host;
}

Fixed version (ground truth):
protected HostVO createHostVO(StartupCommand[] cmds,ServerResource resource,Map<String,String> details,List<String> hostTags,ResourceStateAdapter.Event stateEvent){
  StartupCommand startup=cmds[0];
  HostVO host=findHostByGuid(startup.getGuid());
  boolean isNew=false;
  if (host == null) {
    host=findHostByGuid(startup.getGuidWithoutResource());
  }
  if (host == null) {
    host=new HostVO(startup.getGuid());
    isNew=true;
  }
  String dataCenter=startup.getDataCenter();
  String pod=startup.getPod();
  String cluster=startup.getCluster();
  if (pod != null && dataCenter != null && pod.equalsIgnoreCase("String_Node_Str") && dataCenter.equalsIgnoreCase("String_Node_Str")) {
    List<HostPodVO> pods=_podDao.listAllIncludingRemoved();
    for (    HostPodVO hpv : pods) {
      if (checkCIDR(hpv,startup.getPrivateIpAddress(),startup.getPrivateNetmask())) {
        pod=hpv.getName();
        dataCenter=_dcDao.findById(hpv.getDataCenterId()).getName();
        break;
      }
    }
  }
  long dcId=-1;
  DataCenterVO dc=_dcDao.findByName(dataCenter);
  if (dc == null) {
    try {
      dcId=Long.parseLong(dataCenter);
      dc=_dcDao.findById(dcId);
    }
 catch (    final NumberFormatException e) {
      s_logger.debug("String_Node_Str" + dataCenter + "String_Node_Str");
    }
  }
  if (dc == null) {
    throw new IllegalArgumentException("String_Node_Str" + startup.getPrivateIpAddress() + "String_Node_Str"+ dataCenter);
  }
  dcId=dc.getId();
  HostPodVO p=_podDao.findByName(pod,dcId);
  if (p == null) {
    try {
      final long podId=Long.parseLong(pod);
      p=_podDao.findById(podId);
    }
 catch (    final NumberFormatException e) {
      s_logger.debug("String_Node_Str" + pod + "String_Node_Str");
    }
  }
  Long podId=(p == null ? null : p.getId());
  Long clusterId=null;
  if (cluster != null) {
    try {
      clusterId=Long.valueOf(cluster);
    }
 catch (    NumberFormatException e) {
      if (podId != null) {
        ClusterVO c=_clusterDao.findBy(cluster,podId.longValue());
        if (c == null) {
          c=new ClusterVO(dcId,podId.longValue(),cluster);
          c=_clusterDao.persist(c);
        }
        clusterId=c.getId();
      }
    }
  }
  if (startup instanceof StartupRoutingCommand) {
    StartupRoutingCommand ssCmd=((StartupRoutingCommand)startup);
    List<String> implicitHostTags=ssCmd.getHostTags();
    if (!implicitHostTags.isEmpty()) {
      if (hostTags == null) {
        hostTags=_hostTagsDao.gethostTags(host.getId());
      }
      if (hostTags != null) {
        implicitHostTags.removeAll(hostTags);
        hostTags.addAll(implicitHostTags);
      }
 else {
        hostTags=implicitHostTags;
      }
    }
  }
  host.setDataCenterId(dc.getId());
  host.setPodId(podId);
  host.setClusterId(clusterId);
  host.setPrivateIpAddress(startup.getPrivateIpAddress());
  host.setPrivateNetmask(startup.getPrivateNetmask());
  host.setPrivateMacAddress(startup.getPrivateMacAddress());
  host.setPublicIpAddress(startup.getPublicIpAddress());
  host.setPublicMacAddress(startup.getPublicMacAddress());
  host.setPublicNetmask(startup.getPublicNetmask());
  host.setStorageIpAddress(startup.getStorageIpAddress());
  host.setStorageMacAddress(startup.getStorageMacAddress());
  host.setStorageNetmask(startup.getStorageNetmask());
  host.setVersion(startup.getVersion());
  host.setName(startup.getName());
  host.setManagementServerId(_nodeId);
  host.setStorageUrl(startup.getIqn());
  host.setLastPinged(System.currentTimeMillis() >> 10);
  host.setHostTags(hostTags);
  host.setDetails(details);
  if (startup.getStorageIpAddressDeux() != null) {
    host.setStorageIpAddressDeux(startup.getStorageIpAddressDeux());
    host.setStorageMacAddressDeux(startup.getStorageMacAddressDeux());
    host.setStorageNetmaskDeux(startup.getStorageNetmaskDeux());
  }
  if (resource != null) {
    host.setResource(resource.getClass().getName());
  }
  host=(HostVO)dispatchToStateAdapters(stateEvent,true,host,cmds,resource,details,hostTags);
  if (host == null) {
    throw new CloudRuntimeException("String_Node_Str");
  }
  if (isNew) {
    host=_hostDao.persist(host);
  }
 else {
    _hostDao.update(host.getId(),host);
  }
  try {
    resourceStateTransitTo(host,ResourceState.Event.InternalCreated,_nodeId);
    _agentMgr.agentStatusTransitTo(host,Status.Event.AgentConnected,_nodeId);
  }
 catch (  Exception e) {
    s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
    _agentMgr.agentStatusTransitTo(host,Status.Event.Error,_nodeId);
    try {
      resourceStateTransitTo(host,ResourceState.Event.Error,_nodeId);
    }
 catch (    NoTransitionException e1) {
      s_logger.debug("String_Node_Str" + host.getId() + "String_Node_Str",e);
    }
  }
  return host;
}