Program: 106366
Project: 106366
Buggy source:
@Override public Map<? extends ServerResource,Map<String,String>> find(long dcId,Long podId,Long clusterId,URI url,String username,String password,List<String> hostTags) throws DiscoveryException {
  if (s_logger.isInfoEnabled())   s_logger.info("String_Node_Str" + dcId + "String_Node_Str"+ podId+ "String_Node_Str"+ clusterId+ "String_Node_Str"+ url.getHost());
  if (podId == null) {
    if (s_logger.isInfoEnabled())     s_logger.info("String_Node_Str");
    return null;
  }
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) {
    if (s_logger.isInfoEnabled())     s_logger.info("String_Node_Str");
    return null;
  }
  List<HostVO> hosts=_resourceMgr.listAllHostsInCluster(clusterId);
  if (hosts.size() >= _vmwareMgr.getMaxHostsPerCluster()) {
    String msg="String_Node_Str" + cluster.getName() + "String_Node_Str"+ _vmwareMgr.getMaxHostsPerCluster()+ "String_Node_Str";
    s_logger.error(msg);
    throw new DiscoveredWithErrorException(msg);
  }
  String privateTrafficLabel=null;
  String publicTrafficLabel=null;
  String guestTrafficLabel=null;
  Map<String,String> vsmCredentials=null;
  privateTrafficLabel=_netmgr.getDefaultManagementTrafficLabel(dcId,HypervisorType.VMware);
  if (privateTrafficLabel != null) {
    s_logger.info("String_Node_Str" + privateTrafficLabel);
  }
  if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
    DataCenterVO zone=_dcDao.findById(dcId);
    NetworkType zoneType=zone.getNetworkType();
    if (zoneType != NetworkType.Basic) {
      publicTrafficLabel=_netmgr.getDefaultPublicTrafficLabel(dcId,HypervisorType.VMware);
      if (publicTrafficLabel != null) {
        s_logger.info("String_Node_Str" + publicTrafficLabel);
      }
    }
    guestTrafficLabel=_netmgr.getDefaultGuestTrafficLabel(dcId,HypervisorType.VMware);
    if (guestTrafficLabel != null) {
      s_logger.info("String_Node_Str" + guestTrafficLabel);
    }
    vsmCredentials=_vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
  }
  VmwareContext context=null;
  try {
    context=VmwareContextFactory.create(url.getHost(),username,password);
    if (privateTrafficLabel != null)     context.registerStockObject("String_Node_Str",privateTrafficLabel);
    if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
      if (vsmCredentials != null) {
        s_logger.info("String_Node_Str");
        context.registerStockObject("String_Node_Str",vsmCredentials);
      }
    }
    List<ManagedObjectReference> morHosts=_vmwareMgr.addHostToPodCluster(context,dcId,podId,clusterId,URLDecoder.decode(url.getPath()));
    if (morHosts == null)     s_logger.info("String_Node_Str");
    if (privateTrafficLabel != null)     context.uregisterStockObject("String_Node_Str");
    if (morHosts == null) {
      s_logger.error("String_Node_Str" + URLDecoder.decode(url.getPath()));
      return null;
    }
    ManagedObjectReference morCluster=null;
    Map<String,String> clusterDetails=_clusterDetailsDao.findDetails(clusterId);
    if (clusterDetails.get("String_Node_Str") != null) {
      URI uriFromCluster=new URI(UriUtils.encodeURIComponent(clusterDetails.get("String_Node_Str")));
      morCluster=context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath()));
      if (morCluster == null || !morCluster.getType().equalsIgnoreCase("String_Node_Str")) {
        s_logger.warn("String_Node_Str" + clusterDetails.get("String_Node_Str"));
        return null;
      }
 else {
        ClusterMO clusterMo=new ClusterMO(context,morCluster);
        ClusterDasConfigInfo dasConfig=clusterMo.getDasConfig();
        if (dasConfig != null && dasConfig.getEnabled() != null && dasConfig.getEnabled().booleanValue()) {
          clusterDetails.put("String_Node_Str","String_Node_Str");
          _clusterDetailsDao.persist(clusterId,clusterDetails);
        }
      }
    }
    if (!validateDiscoveredHosts(context,morCluster,morHosts)) {
      if (morCluster == null)       s_logger.warn("String_Node_Str");
 else       s_logger.warn("String_Node_Str");
      return null;
    }
    Map<VmwareResource,Map<String,String>> resources=new HashMap<VmwareResource,Map<String,String>>();
    for (    ManagedObjectReference morHost : morHosts) {
      Map<String,String> details=new HashMap<String,String>();
      Map<String,Object> params=new HashMap<String,Object>();
      HostMO hostMo=new HostMO(context,morHost);
      details.put("String_Node_Str",hostMo.getHostName());
      details.put("String_Node_Str",username);
      details.put("String_Node_Str",password);
      String guid=morHost.getType() + "String_Node_Str" + morHost.get_value()+ "String_Node_Str"+ url.getHost();
      details.put("String_Node_Str",guid);
      params.put("String_Node_Str",hostMo.getHostName());
      params.put("String_Node_Str",username);
      params.put("String_Node_Str",password);
      params.put("String_Node_Str",Long.toString(dcId));
      params.put("String_Node_Str",Long.toString(podId));
      params.put("String_Node_Str",Long.toString(clusterId));
      params.put("String_Node_Str",guid);
      if (privateTrafficLabel != null) {
        params.put("String_Node_Str",privateTrafficLabel);
      }
      if (publicTrafficLabel != null) {
        params.put("String_Node_Str",publicTrafficLabel);
      }
      if (guestTrafficLabel != null) {
        params.put("String_Node_Str",guestTrafficLabel);
      }
      VmwareResource resource=new VmwareResource();
      try {
        resource.configure("String_Node_Str",params);
      }
 catch (      ConfigurationException e) {
        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,dcId,podId,"String_Node_Str" + url.getHost(),"String_Node_Str" + e.getMessage());
        s_logger.warn("String_Node_Str" + url.getHost(),e);
      }
      resource.start();
      resources.put(resource,details);
    }
    cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
    _clusterDao.update(clusterId,cluster);
    return resources;
  }
 catch (  DiscoveredWithErrorException e) {
    throw e;
  }
catch (  Exception e) {
    s_logger.warn("String_Node_Str" + url.getHost());
    return null;
  }
 finally {
    if (context != null)     context.close();
  }
}

Fixed version (ground truth):
@Override public Map<? extends ServerResource,Map<String,String>> find(long dcId,Long podId,Long clusterId,URI url,String username,String password,List<String> hostTags) throws DiscoveryException {
  if (s_logger.isInfoEnabled())   s_logger.info("String_Node_Str" + dcId + "String_Node_Str"+ podId+ "String_Node_Str"+ clusterId+ "String_Node_Str"+ url.getHost());
  if (podId == null) {
    if (s_logger.isInfoEnabled())     s_logger.info("String_Node_Str");
    return null;
  }
  ClusterVO cluster=_clusterDao.findById(clusterId);
  if (cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) {
    if (s_logger.isInfoEnabled())     s_logger.info("String_Node_Str");
    return null;
  }
  List<HostVO> hosts=_resourceMgr.listAllHostsInCluster(clusterId);
  if (hosts.size() >= _vmwareMgr.getMaxHostsPerCluster()) {
    String msg="String_Node_Str" + cluster.getName() + "String_Node_Str"+ _vmwareMgr.getMaxHostsPerCluster()+ "String_Node_Str";
    s_logger.error(msg);
    throw new DiscoveredWithErrorException(msg);
  }
  String privateTrafficLabel=null;
  String publicTrafficLabel=null;
  String guestTrafficLabel=null;
  Map<String,String> vsmCredentials=null;
  privateTrafficLabel=_netmgr.getDefaultManagementTrafficLabel(dcId,HypervisorType.VMware);
  if (privateTrafficLabel != null) {
    s_logger.info("String_Node_Str" + privateTrafficLabel);
  }
  if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
    DataCenterVO zone=_dcDao.findById(dcId);
    NetworkType zoneType=zone.getNetworkType();
    if (zoneType != NetworkType.Basic) {
      publicTrafficLabel=_netmgr.getDefaultPublicTrafficLabel(dcId,HypervisorType.VMware);
      if (publicTrafficLabel != null) {
        s_logger.info("String_Node_Str" + publicTrafficLabel);
      }
    }
    guestTrafficLabel=_netmgr.getDefaultGuestTrafficLabel(dcId,HypervisorType.VMware);
    if (guestTrafficLabel != null) {
      s_logger.info("String_Node_Str" + guestTrafficLabel);
    }
    vsmCredentials=_vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
  }
  VmwareContext context=null;
  try {
    context=VmwareContextFactory.create(url.getHost(),username,password);
    if (privateTrafficLabel != null)     context.registerStockObject("String_Node_Str",privateTrafficLabel);
    if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
      if (vsmCredentials != null) {
        s_logger.info("String_Node_Str");
        context.registerStockObject("String_Node_Str",vsmCredentials);
      }
    }
    List<ManagedObjectReference> morHosts=_vmwareMgr.addHostToPodCluster(context,dcId,podId,clusterId,URLDecoder.decode(url.getPath()));
    if (morHosts == null)     s_logger.info("String_Node_Str");
    if (privateTrafficLabel != null)     context.uregisterStockObject("String_Node_Str");
    if (morHosts == null) {
      s_logger.error("String_Node_Str" + URLDecoder.decode(url.getPath()));
      return null;
    }
    ManagedObjectReference morCluster=null;
    Map<String,String> clusterDetails=_clusterDetailsDao.findDetails(clusterId);
    if (clusterDetails.get("String_Node_Str") != null) {
      URI uriFromCluster=new URI(UriUtils.encodeURIComponent(clusterDetails.get("String_Node_Str")));
      morCluster=context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath()));
      if (morCluster == null || !morCluster.getType().equalsIgnoreCase("String_Node_Str")) {
        s_logger.warn("String_Node_Str" + clusterDetails.get("String_Node_Str"));
        return null;
      }
 else {
        ClusterMO clusterMo=new ClusterMO(context,morCluster);
        ClusterDasConfigInfo dasConfig=clusterMo.getDasConfig();
        if (dasConfig != null && dasConfig.isEnabled() != null && dasConfig.isEnabled().booleanValue()) {
          clusterDetails.put("String_Node_Str","String_Node_Str");
          _clusterDetailsDao.persist(clusterId,clusterDetails);
        }
      }
    }
    if (!validateDiscoveredHosts(context,morCluster,morHosts)) {
      if (morCluster == null)       s_logger.warn("String_Node_Str");
 else       s_logger.warn("String_Node_Str");
      return null;
    }
    Map<VmwareResource,Map<String,String>> resources=new HashMap<VmwareResource,Map<String,String>>();
    for (    ManagedObjectReference morHost : morHosts) {
      Map<String,String> details=new HashMap<String,String>();
      Map<String,Object> params=new HashMap<String,Object>();
      HostMO hostMo=new HostMO(context,morHost);
      details.put("String_Node_Str",hostMo.getHostName());
      details.put("String_Node_Str",username);
      details.put("String_Node_Str",password);
      String guid=morHost.getType() + "String_Node_Str" + morHost.getValue()+ "String_Node_Str"+ url.getHost();
      details.put("String_Node_Str",guid);
      params.put("String_Node_Str",hostMo.getHostName());
      params.put("String_Node_Str",username);
      params.put("String_Node_Str",password);
      params.put("String_Node_Str",Long.toString(dcId));
      params.put("String_Node_Str",Long.toString(podId));
      params.put("String_Node_Str",Long.toString(clusterId));
      params.put("String_Node_Str",guid);
      if (privateTrafficLabel != null) {
        params.put("String_Node_Str",privateTrafficLabel);
      }
      if (publicTrafficLabel != null) {
        params.put("String_Node_Str",publicTrafficLabel);
      }
      if (guestTrafficLabel != null) {
        params.put("String_Node_Str",guestTrafficLabel);
      }
      VmwareResource resource=new VmwareResource();
      try {
        resource.configure("String_Node_Str",params);
      }
 catch (      ConfigurationException e) {
        _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST,dcId,podId,"String_Node_Str" + url.getHost(),"String_Node_Str" + e.getMessage());
        s_logger.warn("String_Node_Str" + url.getHost(),e);
      }
      resource.start();
      resources.put(resource,details);
    }
    cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
    _clusterDao.update(clusterId,cluster);
    return resources;
  }
 catch (  DiscoveredWithErrorException e) {
    throw e;
  }
catch (  Exception e) {
    s_logger.warn("String_Node_Str" + url.getHost());
    return null;
  }
 finally {
    if (context != null)     context.close();
  }
}