Program: 107357
Project: 107357
Buggy source:
private Long extract(Account account,Long templateId,String url,Long zoneId,String mode,Long eventId,boolean isISO,AsyncJobVO job,AsyncJobManager mgr){
  String desc="String_Node_Str";
  if (isISO) {
    desc="String_Node_Str";
  }
  VMTemplateVO template=_tmpltDao.findById(templateId);
  if (template == null) {
    throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str"+ templateId);
  }
  if (template.getId() < 201) {
    throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str"+ template.getName()+ "String_Node_Str");
  }
  if (isISO) {
    if (template.getFormat() != ImageFormat.ISO) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else {
    if (template.getFormat() == ImageFormat.ISO) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  if (_dcDao.findById(zoneId) == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (account != null) {
    if (!isAdmin(account.getType())) {
      if (template.getAccountId() != account.getId()) {
        throw new PermissionDeniedException("String_Node_Str" + desc + "String_Node_Str"+ templateId+ "String_Node_Str"+ account.getAccountName());
      }
    }
 else {
      Account userAccount=_accountDao.findById(template.getAccountId());
      if ((userAccount == null) || !_domainDao.isChildDomain(account.getDomainId(),userAccount.getDomainId())) {
        throw new PermissionDeniedException("String_Node_Str" + desc + "String_Node_Str"+ templateId+ "String_Node_Str");
      }
    }
  }
  HostVO secondaryStorageHost=_storageMgr.getSecondaryStorageHost(zoneId);
  VMTemplateHostVO tmpltHostRef=null;
  if (secondaryStorageHost != null) {
    tmpltHostRef=_tmpltHostDao.findByHostTemplate(secondaryStorageHost.getId(),templateId);
    if (tmpltHostRef != null && tmpltHostRef.getDownloadState() != com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
      throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str");
    }
  }
  Upload.Mode extractMode;
  if (mode == null || (!mode.equals(Upload.Mode.FTP_UPLOAD.toString()) && !mode.equals(Upload.Mode.HTTP_DOWNLOAD.toString()))) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + Upload.Mode.values());
  }
 else {
    extractMode=mode.equals(Upload.Mode.FTP_UPLOAD.toString()) ? Upload.Mode.FTP_UPLOAD : Upload.Mode.HTTP_DOWNLOAD;
  }
  long userId=UserContext.current().getUserId();
  long accountId=template.getAccountId();
  String event=isISO ? EventTypes.EVENT_ISO_EXTRACT : EventTypes.EVENT_TEMPLATE_EXTRACT;
  if (extractMode == Upload.Mode.FTP_UPLOAD) {
    URI uri=null;
    try {
      uri=new URI(url);
      if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("String_Node_Str"))) {
        throw new InvalidParameterValueException("String_Node_Str" + url);
      }
    }
 catch (    Exception ex) {
      throw new InvalidParameterValueException("String_Node_Str" + url);
    }
    String host=uri.getHost();
    try {
      InetAddress hostAddr=InetAddress.getByName(host);
      if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress()|| hostAddr.isMulticastAddress()) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (hostAddr instanceof Inet6Address) {
        throw new InvalidParameterValueException("String_Node_Str" + hostAddr.getHostAddress() + "String_Node_Str");
      }
    }
 catch (    UnknownHostException uhe) {
      throw new InvalidParameterValueException("String_Node_Str" + host);
    }
    if (_uploadMonitor.isTypeUploadInProgress(templateId,isISO ? Type.ISO : Type.TEMPLATE)) {
      throw new IllegalArgumentException(template.getName() + "String_Node_Str");
    }
    EventUtils.saveStartedEvent(userId,accountId,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ extractMode.toString(),eventId);
    return _uploadMonitor.extractTemplate(template,url,tmpltHostRef,zoneId,eventId,job.getId(),mgr);
  }
  EventUtils.saveStartedEvent(userId,accountId,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ extractMode.toString(),eventId);
  UploadVO vo=_uploadMonitor.createEntityDownloadURL(template,tmpltHostRef,zoneId,eventId);
  if (vo != null) {
    ExtractJobResultObject resultObject=new ExtractJobResultObject(template.getAccountId(),template.getName(),Upload.Status.DOWNLOAD_URL_CREATED.toString(),vo.getId(),url);
    mgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_SUCCEEDED,1,resultObject);
    EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_INFO,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ mode,null,eventId);
    return vo.getId();
  }
 else {
    EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_ERROR,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ mode,null,eventId);
    mgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_FAILED,2,null);
    return null;
  }
}

Fixed version (ground truth):
private Long extract(Account account,Long templateId,String url,Long zoneId,String mode,Long eventId,boolean isISO,AsyncJobVO job,AsyncJobManager mgr){
  String desc="String_Node_Str";
  if (isISO) {
    desc="String_Node_Str";
  }
  VMTemplateVO template=_tmpltDao.findById(templateId);
  if (template == null) {
    throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str"+ templateId);
  }
  if (template.getTemplateType() == Storage.TemplateType.SYSTEM) {
    throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str"+ template.getName()+ "String_Node_Str");
  }
  if (isISO) {
    if (template.getFormat() != ImageFormat.ISO) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
 else {
    if (template.getFormat() == ImageFormat.ISO) {
      throw new InvalidParameterValueException("String_Node_Str");
    }
  }
  if (_dcDao.findById(zoneId) == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (account != null) {
    if (!isAdmin(account.getType())) {
      if (template.getAccountId() != account.getId()) {
        throw new PermissionDeniedException("String_Node_Str" + desc + "String_Node_Str"+ templateId+ "String_Node_Str"+ account.getAccountName());
      }
    }
 else {
      Account userAccount=_accountDao.findById(template.getAccountId());
      if ((userAccount == null) || !_domainDao.isChildDomain(account.getDomainId(),userAccount.getDomainId())) {
        throw new PermissionDeniedException("String_Node_Str" + desc + "String_Node_Str"+ templateId+ "String_Node_Str");
      }
    }
  }
  HostVO secondaryStorageHost=_storageMgr.getSecondaryStorageHost(zoneId);
  VMTemplateHostVO tmpltHostRef=null;
  if (secondaryStorageHost != null) {
    tmpltHostRef=_tmpltHostDao.findByHostTemplate(secondaryStorageHost.getId(),templateId);
    if (tmpltHostRef != null && tmpltHostRef.getDownloadState() != com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED) {
      throw new InvalidParameterValueException("String_Node_Str" + desc + "String_Node_Str");
    }
  }
  Upload.Mode extractMode;
  if (mode == null || (!mode.equals(Upload.Mode.FTP_UPLOAD.toString()) && !mode.equals(Upload.Mode.HTTP_DOWNLOAD.toString()))) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + Upload.Mode.values());
  }
 else {
    extractMode=mode.equals(Upload.Mode.FTP_UPLOAD.toString()) ? Upload.Mode.FTP_UPLOAD : Upload.Mode.HTTP_DOWNLOAD;
  }
  long userId=UserContext.current().getUserId();
  long accountId=template.getAccountId();
  String event=isISO ? EventTypes.EVENT_ISO_EXTRACT : EventTypes.EVENT_TEMPLATE_EXTRACT;
  if (extractMode == Upload.Mode.FTP_UPLOAD) {
    URI uri=null;
    try {
      uri=new URI(url);
      if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("String_Node_Str"))) {
        throw new InvalidParameterValueException("String_Node_Str" + url);
      }
    }
 catch (    Exception ex) {
      throw new InvalidParameterValueException("String_Node_Str" + url);
    }
    String host=uri.getHost();
    try {
      InetAddress hostAddr=InetAddress.getByName(host);
      if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress()|| hostAddr.isMulticastAddress()) {
        throw new InvalidParameterValueException("String_Node_Str");
      }
      if (hostAddr instanceof Inet6Address) {
        throw new InvalidParameterValueException("String_Node_Str" + hostAddr.getHostAddress() + "String_Node_Str");
      }
    }
 catch (    UnknownHostException uhe) {
      throw new InvalidParameterValueException("String_Node_Str" + host);
    }
    if (_uploadMonitor.isTypeUploadInProgress(templateId,isISO ? Type.ISO : Type.TEMPLATE)) {
      throw new IllegalArgumentException(template.getName() + "String_Node_Str");
    }
    EventUtils.saveStartedEvent(userId,accountId,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ extractMode.toString(),eventId);
    return _uploadMonitor.extractTemplate(template,url,tmpltHostRef,zoneId,eventId,job.getId(),mgr);
  }
  EventUtils.saveStartedEvent(userId,accountId,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ extractMode.toString(),eventId);
  UploadVO vo=_uploadMonitor.createEntityDownloadURL(template,tmpltHostRef,zoneId,eventId);
  if (vo != null) {
    ExtractJobResultObject resultObject=new ExtractJobResultObject(template.getAccountId(),template.getName(),Upload.Status.DOWNLOAD_URL_CREATED.toString(),vo.getId(),url);
    mgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_SUCCEEDED,1,resultObject);
    EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_INFO,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ mode,null,eventId);
    return vo.getId();
  }
 else {
    EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_ERROR,event,"String_Node_Str" + template.getName() + "String_Node_Str"+ mode,null,eventId);
    mgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_FAILED,2,null);
    return null;
  }
}