Program: 89679
Project: 89679
Buggy source:
@Override @SuppressWarnings("String_Node_Str") public StoragePoolVO createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
  Long clusterId=cmd.getClusterId();
  Long podId=cmd.getPodId();
  Map ds=cmd.getDetails();
  if (clusterId != null && podId == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Map<String,String> details=new HashMap<String,String>();
  if (ds != null) {
    Collection detailsCollection=ds.values();
    Iterator it=detailsCollection.iterator();
    while (it.hasNext()) {
      HashMap d=(HashMap)it.next();
      Iterator it2=d.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry entry=(Map.Entry)it2.next();
        details.put((String)entry.getKey(),(String)entry.getValue());
      }
    }
  }
  Long zoneId=cmd.getZoneId();
  DataCenterVO zone=_dcDao.findById(cmd.getZoneId());
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  Account account=UserContext.current().getCaller();
  if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
    throw new PermissionDeniedException("String_Node_Str" + zoneId);
  }
  List<HostVO> allHosts=_hostDao.listBy(Host.Type.Routing,clusterId,podId,zoneId);
  if (allHosts.isEmpty()) {
    throw new ResourceUnavailableException("String_Node_Str" + clusterId,HostPodVO.class,podId);
  }
  URI uri=null;
  try {
    uri=new URI(cmd.getUrl());
    if (uri.getScheme() == null) {
      throw new InvalidParameterValueException("String_Node_Str" + cmd.getUrl() + "String_Node_Str");
    }
 else     if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
      String uriHost=uri.getHost();
      String uriPath=uri.getPath();
      if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
 else     if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
      String uriPath=uri.getPath();
      if (uriPath == null) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
  }
 catch (  URISyntaxException e) {
    throw new InvalidParameterValueException(cmd.getUrl() + "String_Node_Str");
  }
  String tags=cmd.getTags();
  if (tags != null) {
    String[] tokens=tags.split("String_Node_Str");
    for (    String tag : tokens) {
      tag=tag.trim();
      if (tag.length() == 0) {
        continue;
      }
      details.put(tag,"String_Node_Str");
    }
  }
  String scheme=uri.getScheme();
  String storageHost=uri.getHost();
  String hostPath=uri.getPath();
  int port=uri.getPort();
  StoragePoolVO pool=null;
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + scheme + "String_Node_Str"+ storageHost+ "String_Node_Str"+ hostPath+ "String_Node_Str"+ port);
  }
  if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=2049;
    }
    pool=new StoragePoolVO(StoragePoolType.NetworkFilesystem,storageHost,port,hostPath);
    if (clusterId == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=0;
    }
    pool=new StoragePoolVO(StoragePoolType.Filesystem,"String_Node_Str",0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.SharedMountPoint,storageHost,0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.PreSetup,storageHost,0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    String[] tokens=hostPath.split("String_Node_Str");
    int lun=NumbersUtil.parseInt(tokens[tokens.length - 1],-1);
    if (port == -1) {
      port=3260;
    }
    if (lun != -1) {
      if (clusterId == null) {
        throw new IllegalArgumentException("String_Node_Str");
      }
      hostPath.replaceFirst("String_Node_Str","String_Node_Str");
      pool=new StoragePoolVO(StoragePoolType.IscsiLUN,storageHost,port,hostPath);
    }
 else {
      Enumeration<StoragePoolDiscoverer> en=_discoverers.enumeration();
      while (en.hasMoreElements()) {
        Map<StoragePoolVO,Map<String,String>> pools;
        try {
          pools=en.nextElement().find(cmd.getZoneId(),podId,uri,details);
        }
 catch (        DiscoveryException e) {
          throw new IllegalArgumentException("String_Node_Str" + uri,e);
        }
        if (pools != null) {
          Map.Entry<StoragePoolVO,Map<String,String>> entry=pools.entrySet().iterator().next();
          pool=entry.getKey();
          details=entry.getValue();
          break;
        }
      }
    }
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=2049;
    }
    pool=new StoragePoolVO(StoragePoolType.ISO,storageHost,port,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.VMFS,"String_Node_Str" + hostPath,0,hostPath);
  }
 else {
    s_logger.warn("String_Node_Str" + uri);
    throw new IllegalArgumentException("String_Node_Str" + uri);
  }
  if (pool == null) {
    s_logger.warn("String_Node_Str" + uri);
    throw new IllegalArgumentException("String_Node_Str" + uri);
  }
  List<StoragePoolVO> pools=_storagePoolDao.listPoolByHostPath(storageHost,hostPath);
  if (!pools.isEmpty() && !scheme.equalsIgnoreCase("String_Node_Str")) {
    Long oldPodId=pools.get(0).getPodId();
    throw new ResourceInUseException("String_Node_Str" + uri + "String_Node_Str"+ oldPodId+ "String_Node_Str","String_Node_Str",uri.toASCIIString());
  }
  long poolId=_storagePoolDao.getNextInSequence(Long.class,"String_Node_Str");
  String uuid=null;
  if (scheme.equalsIgnoreCase("String_Node_Str")) {
    uuid=UUID.randomUUID().toString();
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    uuid=hostPath.replace("String_Node_Str","String_Node_Str");
  }
 else {
    uuid=UUID.nameUUIDFromBytes(new String(storageHost + hostPath).getBytes()).toString();
  }
  List<StoragePoolVO> spHandles=_storagePoolDao.findIfDuplicatePoolsExistByUUID(uuid);
  if ((spHandles != null) && (spHandles.size() > 0)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    throw new ResourceInUseException("String_Node_Str");
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + poolId + "String_Node_Str"+ uuid+ "String_Node_Str"+ zoneId+ "String_Node_Str"+ podId+ "String_Node_Str"+ cmd.getStoragePoolName());
  }
  pool.setId(poolId);
  pool.setUuid(uuid);
  pool.setDataCenterId(cmd.getZoneId());
  pool.setPodId(podId);
  pool.setName(cmd.getStoragePoolName());
  pool.setClusterId(clusterId);
  pool.setStatus(StoragePoolStatus.Up);
  pool=_storagePoolDao.persist(pool,details);
  boolean success=false;
  for (  HostVO h : allHosts) {
    success=createStoragePool(h.getId(),pool);
    if (success) {
      break;
    }
  }
  if (!success) {
    s_logger.warn("String_Node_Str" + pool + "String_Node_Str"+ clusterId);
    _storagePoolDao.expunge(pool.getId());
    return null;
  }
  s_logger.debug("String_Node_Str");
  List<HostVO> poolHosts=new ArrayList<HostVO>();
  for (  HostVO h : allHosts) {
    try {
      addPoolToHost(h.getId(),pool);
      poolHosts.add(h);
    }
 catch (    Exception e) {
      s_logger.warn("String_Node_Str" + h + "String_Node_Str"+ pool,e);
    }
  }
  if (poolHosts.isEmpty()) {
    s_logger.warn("String_Node_Str" + pool + "String_Node_Str"+ clusterId);
    _storagePoolDao.expunge(pool.getId());
    return null;
  }
 else {
    createCapacityEntry(pool);
  }
  _configMgr.updateConfiguration(UserContext.current().getCallerUserId(),"String_Node_Str","String_Node_Str");
  return pool;
}

Fixed version (ground truth):
@Override @SuppressWarnings("String_Node_Str") public StoragePoolVO createPool(CreateStoragePoolCmd cmd) throws ResourceInUseException, IllegalArgumentException, UnknownHostException, ResourceUnavailableException {
  Long clusterId=cmd.getClusterId();
  Long podId=cmd.getPodId();
  Map ds=cmd.getDetails();
  if (clusterId != null && podId == null) {
    throw new InvalidParameterValueException("String_Node_Str");
  }
  Map<String,String> details=new HashMap<String,String>();
  if (ds != null) {
    Collection detailsCollection=ds.values();
    Iterator it=detailsCollection.iterator();
    while (it.hasNext()) {
      HashMap d=(HashMap)it.next();
      Iterator it2=d.entrySet().iterator();
      while (it2.hasNext()) {
        Map.Entry entry=(Map.Entry)it2.next();
        details.put((String)entry.getKey(),(String)entry.getValue());
      }
    }
  }
  Long zoneId=cmd.getZoneId();
  DataCenterVO zone=_dcDao.findById(cmd.getZoneId());
  if (zone == null) {
    throw new InvalidParameterValueException("String_Node_Str" + zoneId);
  }
  Account account=UserContext.current().getCaller();
  if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(account.getType())) {
    throw new PermissionDeniedException("String_Node_Str" + zoneId);
  }
  List<HostVO> allHosts=_hostDao.listBy(Host.Type.Routing,clusterId,podId,zoneId);
  if (allHosts.isEmpty()) {
    throw new ResourceUnavailableException("String_Node_Str" + clusterId,HostPodVO.class,podId);
  }
  URI uri=null;
  try {
    uri=new URI(cmd.getUrl());
    if (uri.getScheme() == null) {
      throw new InvalidParameterValueException("String_Node_Str" + cmd.getUrl() + "String_Node_Str");
    }
 else     if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
      String uriHost=uri.getHost();
      String uriPath=uri.getPath();
      if (uriHost == null || uriPath == null || uriHost.trim().isEmpty() || uriPath.trim().isEmpty()) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
 else     if (uri.getScheme().equalsIgnoreCase("String_Node_Str")) {
      String uriPath=uri.getPath();
      if (uriPath == null) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
    }
  }
 catch (  URISyntaxException e) {
    throw new InvalidParameterValueException(cmd.getUrl() + "String_Node_Str");
  }
  String tags=cmd.getTags();
  if (tags != null) {
    String[] tokens=tags.split("String_Node_Str");
    for (    String tag : tokens) {
      tag=tag.trim();
      if (tag.length() == 0) {
        continue;
      }
      details.put(tag,"String_Node_Str");
    }
  }
  String scheme=uri.getScheme();
  String storageHost=uri.getHost();
  String hostPath=uri.getPath();
  int port=uri.getPort();
  StoragePoolVO pool=null;
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + scheme + "String_Node_Str"+ storageHost+ "String_Node_Str"+ hostPath+ "String_Node_Str"+ port);
  }
  if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=2049;
    }
    pool=new StoragePoolVO(StoragePoolType.NetworkFilesystem,storageHost,port,hostPath);
    if (clusterId == null) {
      throw new IllegalArgumentException("String_Node_Str");
    }
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=0;
    }
    pool=new StoragePoolVO(StoragePoolType.Filesystem,"String_Node_Str",0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.SharedMountPoint,storageHost,0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.PreSetup,storageHost,0,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    String[] tokens=hostPath.split("String_Node_Str");
    int lun=NumbersUtil.parseInt(tokens[tokens.length - 1],-1);
    if (port == -1) {
      port=3260;
    }
    if (lun != -1) {
      if (clusterId == null) {
        throw new IllegalArgumentException("String_Node_Str");
      }
      hostPath.replaceFirst("String_Node_Str","String_Node_Str");
      pool=new StoragePoolVO(StoragePoolType.IscsiLUN,storageHost,port,hostPath);
    }
 else {
      Enumeration<StoragePoolDiscoverer> en=_discoverers.enumeration();
      while (en.hasMoreElements()) {
        Map<StoragePoolVO,Map<String,String>> pools;
        try {
          pools=en.nextElement().find(cmd.getZoneId(),podId,uri,details);
        }
 catch (        DiscoveryException e) {
          throw new IllegalArgumentException("String_Node_Str" + uri,e);
        }
        if (pools != null) {
          Map.Entry<StoragePoolVO,Map<String,String>> entry=pools.entrySet().iterator().next();
          pool=entry.getKey();
          details=entry.getValue();
          break;
        }
      }
    }
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    if (port == -1) {
      port=2049;
    }
    pool=new StoragePoolVO(StoragePoolType.ISO,storageHost,port,hostPath);
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    pool=new StoragePoolVO(StoragePoolType.VMFS,"String_Node_Str" + hostPath,0,hostPath);
  }
 else {
    s_logger.warn("String_Node_Str" + uri);
    throw new IllegalArgumentException("String_Node_Str" + uri);
  }
  if (pool == null) {
    s_logger.warn("String_Node_Str" + uri);
    throw new IllegalArgumentException("String_Node_Str" + uri);
  }
  List<StoragePoolVO> pools=_storagePoolDao.listPoolByHostPath(storageHost,hostPath);
  if (!pools.isEmpty() && !scheme.equalsIgnoreCase("String_Node_Str")) {
    Long oldPodId=pools.get(0).getPodId();
    throw new ResourceInUseException("String_Node_Str" + uri + "String_Node_Str"+ oldPodId+ "String_Node_Str","String_Node_Str",uri.toASCIIString());
  }
  long poolId=_storagePoolDao.getNextInSequence(Long.class,"String_Node_Str");
  String uuid=null;
  if (scheme.equalsIgnoreCase("String_Node_Str")) {
    uuid=UUID.randomUUID().toString();
  }
 else   if (scheme.equalsIgnoreCase("String_Node_Str")) {
    uuid=hostPath.replace("String_Node_Str","String_Node_Str");
  }
 else {
    uuid=UUID.nameUUIDFromBytes(new String(storageHost + hostPath).getBytes()).toString();
  }
  List<StoragePoolVO> spHandles=_storagePoolDao.findIfDuplicatePoolsExistByUUID(uuid);
  if ((spHandles != null) && (spHandles.size() > 0)) {
    if (s_logger.isDebugEnabled()) {
      s_logger.debug("String_Node_Str");
    }
    throw new ResourceInUseException("String_Node_Str");
  }
  if (s_logger.isDebugEnabled()) {
    s_logger.debug("String_Node_Str" + poolId + "String_Node_Str"+ uuid+ "String_Node_Str"+ zoneId+ "String_Node_Str"+ podId+ "String_Node_Str"+ cmd.getStoragePoolName());
  }
  pool.setId(poolId);
  pool.setUuid(uuid);
  pool.setDataCenterId(cmd.getZoneId());
  pool.setPodId(podId);
  pool.setName(cmd.getStoragePoolName());
  pool.setClusterId(clusterId);
  pool.setStatus(StoragePoolStatus.Up);
  pool=_storagePoolDao.persist(pool,details);
  boolean success=false;
  for (  HostVO h : allHosts) {
    success=createStoragePool(h.getId(),pool);
    if (success) {
      break;
    }
  }
  if (!success) {
    s_logger.warn("String_Node_Str" + pool + "String_Node_Str"+ clusterId);
    _storagePoolDao.expunge(pool.getId());
    return null;
  }
  s_logger.debug("String_Node_Str");
  List<HostVO> poolHosts=new ArrayList<HostVO>();
  for (  HostVO h : allHosts) {
    try {
      connectHostToSharedPool(h.getId(),pool);
      poolHosts.add(h);
    }
 catch (    Exception e) {
      s_logger.warn("String_Node_Str" + h + "String_Node_Str"+ pool,e);
    }
  }
  if (poolHosts.isEmpty()) {
    s_logger.warn("String_Node_Str" + pool + "String_Node_Str"+ clusterId);
    _storagePoolDao.expunge(pool.getId());
    return null;
  }
 else {
    createCapacityEntry(pool);
  }
  _configMgr.updateConfiguration(UserContext.current().getCallerUserId(),"String_Node_Str","String_Node_Str");
  return pool;
}