Program: 107277
Project: 107277
Buggy source:
@Override public List<? extends Host> discoverExternalCluster(AddExternalClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
  Long dcId=cmd.getZoneId();
  Long podId=cmd.getPodId();
  String clusterName=cmd.getClusterName();
  String url=cmd.getUrl();
  String username=cmd.getUsername();
  String password=cmd.getPassword();
  URI uri=null;
  if (_dcDao.findById(dcId) == null) {
    throw new InvalidParameterValueException("String_Node_Str" + dcId);
  }
  if (podId != null) {
    if (_podDao.findById(podId) == null) {
      throw new InvalidParameterValueException("String_Node_Str" + podId);
    }
    HostPodVO pod=_podDao.findById(podId);
    if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
      throw new InvalidParameterValueException("String_Node_Str" + podId + "String_Node_Str"+ dcId);
    }
  }
  if (clusterName == null || clusterName.isEmpty()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (cmd.getHypervisor() == null || cmd.getHypervisor().isEmpty()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Hypervisor.HypervisorType hypervisorType=Hypervisor.HypervisorType.valueOf(cmd.getHypervisor());
  if (hypervisorType == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Discoverer discoverer=getMatchingDiscover(cmd.getHypervisor());
  if (discoverer == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  long clusterId=0;
  if (clusterName != null) {
    ClusterVO cluster=new ClusterVO(dcId,podId,clusterName);
    cluster.setHypervisorType(cmd.getHypervisor());
    cluster.setClusterType(Cluster.ClusterType.ExternalManaged);
    try {
      cluster=_clusterDao.persist(cluster);
    }
 catch (    Exception e) {
      cluster=_clusterDao.findBy(clusterName,podId);
      if (cluster == null) {
        throw new CloudRuntimeException("String_Node_Str" + clusterName + "String_Node_Str"+ podId+ "String_Node_Str"+ dcId,e);
      }
    }
    clusterId=cluster.getId();
  }
  try {
    uri=new URI(UriUtils.encodeURIComponent(url));
    if (uri.getScheme() == null) {
      throw new InvalidParameterValueException("String_Node_Str" + url + "String_Node_Str");
    }
 else     if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
      if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("String_Node_Str") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("String_Node_Str")) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
  }
 catch (  URISyntaxException e) {
    throw new InvalidParameterValueException(url + "String_Node_Str");
  }
  List<HostVO> hosts=new ArrayList<HostVO>();
  Map<? extends ServerResource,Map<String,String>> resources=null;
  try {
    resources=discoverer.find(dcId,podId,clusterId,uri,username,password);
  }
 catch (  Exception e) {
    s_logger.info("String_Node_Str" + discoverer.getName());
  }
  if (resources != null) {
    for (    Map.Entry<? extends ServerResource,Map<String,String>> entry : resources.entrySet()) {
      ServerResource resource=entry.getKey();
      AgentAttache attache=simulateStart(resource,entry.getValue(),true);
      if (attache != null) {
        hosts.add(_hostDao.findById(attache.getId()));
      }
      discoverer.postDiscovery(hosts,_nodeId);
    }
    s_logger.info("String_Node_Str" + discoverer.getName());
    return hosts;
  }
  s_logger.warn("String_Node_Str" + url);
  throw new DiscoveryException("String_Node_Str");
}

Fixed version (ground truth):
@Override public List<? extends Host> discoverExternalCluster(AddExternalClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException {
  Long dcId=cmd.getZoneId();
  Long podId=cmd.getPodId();
  String clusterName=cmd.getClusterName();
  String url=cmd.getUrl();
  String username=cmd.getUsername();
  String password=cmd.getPassword();
  URI uri=null;
  if (_dcDao.findById(dcId) == null) {
    throw new InvalidParameterValueException("String_Node_Str" + dcId);
  }
  if (podId != null) {
    if (_podDao.findById(podId) == null) {
      throw new InvalidParameterValueException("String_Node_Str" + podId);
    }
    HostPodVO pod=_podDao.findById(podId);
    if (!Long.valueOf(pod.getDataCenterId()).equals(dcId)) {
      throw new InvalidParameterValueException("String_Node_Str" + podId + "String_Node_Str"+ dcId);
    }
  }
  if (clusterName == null || clusterName.isEmpty()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  if (cmd.getHypervisor() == null || cmd.getHypervisor().isEmpty()) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Hypervisor.HypervisorType hypervisorType=Hypervisor.HypervisorType.valueOf(cmd.getHypervisor());
  if (hypervisorType == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Discoverer discoverer=getMatchingDiscover(hypervisorType);
  if (discoverer == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  long clusterId=0;
  if (clusterName != null) {
    ClusterVO cluster=new ClusterVO(dcId,podId,clusterName);
    cluster.setHypervisorType(cmd.getHypervisor());
    cluster.setClusterType(Cluster.ClusterType.ExternalManaged);
    try {
      cluster=_clusterDao.persist(cluster);
    }
 catch (    Exception e) {
      cluster=_clusterDao.findBy(clusterName,podId);
      if (cluster == null) {
        throw new CloudRuntimeException("String_Node_Str" + clusterName + "String_Node_Str"+ podId+ "String_Node_Str"+ dcId,e);
      }
    }
    clusterId=cluster.getId();
  }
  boolean success=false;
  try {
    try {
      uri=new URI(UriUtils.encodeURIComponent(url));
      if (uri.getScheme() == null) {
        throw new InvalidParameterValueException("String_Node_Str" + url + "String_Node_Str");
      }
 else       if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
        if (uri.getHost() == null || uri.getHost().equalsIgnoreCase("String_Node_Str") || uri.getPath() == null || uri.getPath().equalsIgnoreCase("String_Node_Str")) {
          throw new InvalidParameterValueException("String_Node_Str");
        }
      }
    }
 catch (    URISyntaxException e) {
      throw new InvalidParameterValueException(url + "String_Node_Str");
    }
    List<HostVO> hosts=new ArrayList<HostVO>();
    Map<? extends ServerResource,Map<String,String>> resources=null;
    try {
      resources=discoverer.find(dcId,podId,clusterId,uri,username,password);
    }
 catch (    Exception e) {
      s_logger.info("String_Node_Str" + discoverer.getName());
    }
    if (resources != null) {
      for (      Map.Entry<? extends ServerResource,Map<String,String>> entry : resources.entrySet()) {
        ServerResource resource=entry.getKey();
        AgentAttache attache=simulateStart(resource,entry.getValue(),true);
        if (attache != null) {
          hosts.add(_hostDao.findById(attache.getId()));
        }
        discoverer.postDiscovery(hosts,_nodeId);
      }
      s_logger.info("String_Node_Str" + discoverer.getName());
      success=true;
      return hosts;
    }
    s_logger.warn("String_Node_Str" + url);
    throw new DiscoveryException("String_Node_Str");
  }
  finally {
    if (!success) {
      _clusterDao.remove(clusterId);
    }
  }
}