Program: 107411
Project: 107411
Buggy source:
@Override public Long extractVolume(ExtractVolumeCmd cmd) throws URISyntaxException {
  Long volumeId=cmd.getId();
  String url=cmd.getUrl();
  Long zoneId=cmd.getZoneId();
  AsyncJobVO job=cmd.getJob();
  String mode=cmd.getMode();
  Account account=UserContext.current().getAccount();
  VolumeVO volume=_volumeDao.findById(volumeId);
  if (volume == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + volumeId);
  }
  if (_dcDao.findById(zoneId) == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (volume.getInstanceId() != null && ApiDBUtils.findVMInstanceById(volume.getInstanceId()).getState() != State.Stopped) {
    s_logger.debug("String_Node_Str" + volumeId + "String_Node_Str");
    throw new PermissionDeniedException("String_Node_Str" + volumeId + "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");
  }
 else {
    extractMode=mode.equals(Upload.Mode.FTP_UPLOAD.toString()) ? Upload.Mode.FTP_UPLOAD : Upload.Mode.HTTP_DOWNLOAD;
  }
  if (account != null) {
    if (!isAdmin(account.getType())) {
      if (volume.getAccountId() != account.getId()) {
        throw new PermissionDeniedException("String_Node_Str" + volumeId + "String_Node_Str"+ account.getAccountName());
      }
    }
 else {
      Account userAccount=_accountDao.findById(volume.getAccountId());
      if ((userAccount == null) || !_domainDao.isChildDomain(account.getDomainId(),userAccount.getDomainId())) {
        throw new PermissionDeniedException("String_Node_Str" + volumeId + "String_Node_Str");
      }
    }
  }
  if (extractMode == Upload.Mode.FTP_UPLOAD) {
    URI uri=new URI(url);
    if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("String_Node_Str"))) {
      throw new IllegalArgumentException("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 IllegalArgumentException("String_Node_Str");
      }
      if (hostAddr instanceof Inet6Address) {
        throw new IllegalArgumentException("String_Node_Str" + hostAddr.getHostAddress() + "String_Node_Str");
      }
    }
 catch (    UnknownHostException uhe) {
      throw new IllegalArgumentException("String_Node_Str" + host);
    }
    if (_uploadMonitor.isTypeUploadInProgress(volumeId,Type.VOLUME)) {
      throw new IllegalArgumentException(volume.getName() + "String_Node_Str");
    }
  }
  long userId=UserContext.current().getUserId();
  long accountId=volume.getAccountId();
  String secondaryStorageURL=_storageMgr.getSecondaryStorageURL(zoneId);
  StoragePoolVO srcPool=_poolDao.findById(volume.getPoolId());
  Long sourceHostId=_storageMgr.findHostIdForStoragePool(srcPool);
  List<HostVO> storageServers=_hostDao.listByTypeDataCenter(Host.Type.SecondaryStorage,zoneId);
  HostVO sserver=storageServers.get(0);
  EventUtils.saveStartedEvent(userId,accountId,cmd.getEventType(),"String_Node_Str" + volume.getName() + "String_Node_Str"+ mode,cmd.getStartEventId());
  List<UploadVO> extractURLList=_uploadDao.listByTypeUploadStatus(volumeId,Upload.Type.VOLUME,UploadVO.Status.DOWNLOAD_URL_CREATED);
  if (extractMode == Upload.Mode.HTTP_DOWNLOAD && extractURLList.size() > 0) {
    return extractURLList.get(0).getId();
  }
 else {
    UploadVO uploadJob=_uploadMonitor.createNewUploadEntry(sserver.getId(),volumeId,UploadVO.Status.COPY_IN_PROGRESS,Type.VOLUME,url,extractMode);
    s_logger.debug("String_Node_Str" + uploadJob.getMode());
    uploadJob=_uploadDao.createForUpdate(uploadJob.getId());
    ExtractResponse resultObj=new ExtractResponse(volumeId,volume.getName(),accountId,UploadVO.Status.COPY_IN_PROGRESS.toString(),uploadJob.getId());
    resultObj.setResponseName(cmd.getName());
    _asyncMgr.updateAsyncJobAttachment(job.getId(),Type.VOLUME.toString(),volumeId);
    _asyncMgr.updateAsyncJobStatus(job.getId(),AsyncJobResult.STATUS_IN_PROGRESS,resultObj);
    CopyVolumeCommand cvCmd=new CopyVolumeCommand(volume.getId(),volume.getPath(),srcPool,secondaryStorageURL,true);
    CopyVolumeAnswer cvAnswer=(CopyVolumeAnswer)_agentMgr.easySend(sourceHostId,cvCmd);
    if (cvAnswer == null || !cvAnswer.getResult()) {
      String errorString="String_Node_Str";
      resultObj.setResultString(errorString);
      resultObj.setUploadStatus(UploadVO.Status.COPY_ERROR.toString());
      _asyncMgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_FAILED,0,resultObj);
      uploadJob.setUploadState(UploadVO.Status.COPY_ERROR);
      uploadJob.setErrorString(errorString);
      uploadJob.setLastUpdated(new Date());
      _uploadDao.update(uploadJob.getId(),uploadJob);
      EventUtils.saveEvent(userId,accountId,EventTypes.EVENT_VOLUME_UPLOAD,errorString);
      throw new CloudRuntimeException(errorString);
    }
    String volumeLocalPath="String_Node_Str" + volume.getId() + "String_Node_Str"+ cvAnswer.getVolumePath()+ "String_Node_Str";
    uploadJob.setUploadState(UploadVO.Status.COPY_COMPLETE);
    uploadJob.setLastUpdated(new Date());
    uploadJob.setInstallPath(volumeLocalPath);
    _uploadDao.update(uploadJob.getId(),uploadJob);
    if (extractMode == Mode.FTP_UPLOAD) {
      _uploadMonitor.extractVolume(uploadJob,sserver,volume,url,zoneId,volumeLocalPath,cmd.getStartEventId(),job.getId(),_asyncMgr);
      return uploadJob.getId();
    }
 else {
      _uploadMonitor.createVolumeDownloadURL(volumeId,volumeLocalPath,Type.VOLUME,zoneId,uploadJob.getId());
      EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_INFO,cmd.getEventType(),"String_Node_Str" + volume.getName() + "String_Node_Str"+ mode,null,cmd.getStartEventId());
      return uploadJob.getId();
    }
  }
}

Fixed version (ground truth):
@Override public Long extractVolume(ExtractVolumeCmd cmd) throws URISyntaxException {
  Long volumeId=cmd.getId();
  String url=cmd.getUrl();
  Long zoneId=cmd.getZoneId();
  AsyncJobVO job=cmd.getJob();
  String mode=cmd.getMode();
  Account account=UserContext.current().getAccount();
  VolumeVO volume=_volumeDao.findById(volumeId);
  if (volume == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str" + volumeId);
  }
  if (_dcDao.findById(zoneId) == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (volume.getPoolId() == null) {
    throw new ServerApiException(BaseCmd.PARAM_ERROR,"String_Node_Str");
  }
  if (volume.getInstanceId() != null && ApiDBUtils.findVMInstanceById(volume.getInstanceId()).getState() != State.Stopped) {
    s_logger.debug("String_Node_Str" + volumeId + "String_Node_Str");
    throw new PermissionDeniedException("String_Node_Str" + volumeId + "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");
  }
 else {
    extractMode=mode.equals(Upload.Mode.FTP_UPLOAD.toString()) ? Upload.Mode.FTP_UPLOAD : Upload.Mode.HTTP_DOWNLOAD;
  }
  if (account != null) {
    if (!isAdmin(account.getType())) {
      if (volume.getAccountId() != account.getId()) {
        throw new PermissionDeniedException("String_Node_Str" + volumeId + "String_Node_Str"+ account.getAccountName());
      }
    }
 else {
      Account userAccount=_accountDao.findById(volume.getAccountId());
      if ((userAccount == null) || !_domainDao.isChildDomain(account.getDomainId(),userAccount.getDomainId())) {
        throw new PermissionDeniedException("String_Node_Str" + volumeId + "String_Node_Str");
      }
    }
  }
  if (extractMode == Upload.Mode.FTP_UPLOAD) {
    URI uri=new URI(url);
    if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("String_Node_Str"))) {
      throw new IllegalArgumentException("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 IllegalArgumentException("String_Node_Str");
      }
      if (hostAddr instanceof Inet6Address) {
        throw new IllegalArgumentException("String_Node_Str" + hostAddr.getHostAddress() + "String_Node_Str");
      }
    }
 catch (    UnknownHostException uhe) {
      throw new IllegalArgumentException("String_Node_Str" + host);
    }
    if (_uploadMonitor.isTypeUploadInProgress(volumeId,Type.VOLUME)) {
      throw new IllegalArgumentException(volume.getName() + "String_Node_Str");
    }
  }
  long userId=UserContext.current().getUserId();
  long accountId=volume.getAccountId();
  String secondaryStorageURL=_storageMgr.getSecondaryStorageURL(zoneId);
  StoragePoolVO srcPool=_poolDao.findById(volume.getPoolId());
  Long sourceHostId=_storageMgr.findHostIdForStoragePool(srcPool);
  List<HostVO> storageServers=_hostDao.listByTypeDataCenter(Host.Type.SecondaryStorage,zoneId);
  HostVO sserver=storageServers.get(0);
  EventUtils.saveStartedEvent(userId,accountId,cmd.getEventType(),"String_Node_Str" + volume.getName() + "String_Node_Str"+ mode,cmd.getStartEventId());
  List<UploadVO> extractURLList=_uploadDao.listByTypeUploadStatus(volumeId,Upload.Type.VOLUME,UploadVO.Status.DOWNLOAD_URL_CREATED);
  if (extractMode == Upload.Mode.HTTP_DOWNLOAD && extractURLList.size() > 0) {
    return extractURLList.get(0).getId();
  }
 else {
    UploadVO uploadJob=_uploadMonitor.createNewUploadEntry(sserver.getId(),volumeId,UploadVO.Status.COPY_IN_PROGRESS,Type.VOLUME,url,extractMode);
    s_logger.debug("String_Node_Str" + uploadJob.getMode());
    uploadJob=_uploadDao.createForUpdate(uploadJob.getId());
    ExtractResponse resultObj=new ExtractResponse(volumeId,volume.getName(),accountId,UploadVO.Status.COPY_IN_PROGRESS.toString(),uploadJob.getId());
    resultObj.setResponseName(cmd.getName());
    _asyncMgr.updateAsyncJobAttachment(job.getId(),Type.VOLUME.toString(),volumeId);
    _asyncMgr.updateAsyncJobStatus(job.getId(),AsyncJobResult.STATUS_IN_PROGRESS,resultObj);
    CopyVolumeCommand cvCmd=new CopyVolumeCommand(volume.getId(),volume.getPath(),srcPool,secondaryStorageURL,true);
    CopyVolumeAnswer cvAnswer=(CopyVolumeAnswer)_agentMgr.easySend(sourceHostId,cvCmd);
    if (cvAnswer == null || !cvAnswer.getResult()) {
      String errorString="String_Node_Str";
      resultObj.setResultString(errorString);
      resultObj.setUploadStatus(UploadVO.Status.COPY_ERROR.toString());
      _asyncMgr.completeAsyncJob(job.getId(),AsyncJobResult.STATUS_FAILED,0,resultObj);
      uploadJob.setUploadState(UploadVO.Status.COPY_ERROR);
      uploadJob.setErrorString(errorString);
      uploadJob.setLastUpdated(new Date());
      _uploadDao.update(uploadJob.getId(),uploadJob);
      EventUtils.saveEvent(userId,accountId,EventTypes.EVENT_VOLUME_UPLOAD,errorString);
      throw new CloudRuntimeException(errorString);
    }
    String volumeLocalPath="String_Node_Str" + volume.getId() + "String_Node_Str"+ cvAnswer.getVolumePath()+ "String_Node_Str";
    uploadJob.setUploadState(UploadVO.Status.COPY_COMPLETE);
    uploadJob.setLastUpdated(new Date());
    uploadJob.setInstallPath(volumeLocalPath);
    _uploadDao.update(uploadJob.getId(),uploadJob);
    if (extractMode == Mode.FTP_UPLOAD) {
      _uploadMonitor.extractVolume(uploadJob,sserver,volume,url,zoneId,volumeLocalPath,cmd.getStartEventId(),job.getId(),_asyncMgr);
      return uploadJob.getId();
    }
 else {
      _uploadMonitor.createVolumeDownloadURL(volumeId,volumeLocalPath,Type.VOLUME,zoneId,uploadJob.getId());
      EventUtils.saveEvent(userId,accountId,EventVO.LEVEL_INFO,cmd.getEventType(),"String_Node_Str" + volume.getName() + "String_Node_Str"+ mode,null,cmd.getStartEventId());
      return uploadJob.getId();
    }
  }
}