Program: 107416
Project: 107416
Buggy source:
@Override public UploadVO createEntityDownloadURL(VMTemplateVO template,VMTemplateHostVO vmTemplateHost,Long dataCenterId,long eventId){
  List<HostVO> storageServers=_serverDao.listByTypeDataCenter(Host.Type.SecondaryStorage,dataCenterId);
  if (storageServers == null)   throw new CloudRuntimeException("String_Node_Str" + dataCenterId);
  Type type=(template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
  List<UploadVO> extractURLList=_uploadDao.listByTypeUploadStatus(template.getId(),type,UploadVO.Status.DOWNLOAD_URL_CREATED);
  if (extractURLList.size() > 0)   return extractURLList.get(0);
  HostVO sserver=storageServers.get(0);
  UploadVO uploadTemplateObj=new UploadVO(sserver.getId(),template.getId(),new Date(),Status.DOWNLOAD_URL_NOT_CREATED,0,type,Mode.HTTP_DOWNLOAD);
  uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());
  _uploadDao.persist(uploadTemplateObj);
  CreateEntityDownloadURLCommand cmd=new CreateEntityDownloadURLCommand(vmTemplateHost.getInstallPath());
  long result=send(sserver.getId(),cmd,null);
  if (result == -1) {
    s_logger.warn("String_Node_Str");
    throw new CloudRuntimeException("String_Node_Str");
  }
  List<SecondaryStorageVmVO> ssVms=_secStorageVmDao.getSecStorageVmListInStates(dataCenterId,State.Running);
  if (ssVms.size() > 0) {
    SecondaryStorageVmVO ssVm=ssVms.get(0);
    if (ssVm.getPublicIpAddress() == null) {
      s_logger.warn("String_Node_Str");
      throw new CloudRuntimeException("String_Node_Str");
    }
    String extractURL=generateCopyUrl(ssVm.getPublicIpAddress(),vmTemplateHost.getInstallPath());
    UploadVO vo=_uploadDao.createForUpdate();
    vo.setLastUpdated(new Date());
    vo.setUploadUrl(extractURL);
    vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
    if (extractURL == null) {
      vo.setUploadState(Status.ERROR);
      vo.setErrorString("String_Node_Str");
    }
    _uploadDao.update(uploadTemplateObj.getId(),vo);
    return _uploadDao.findById(uploadTemplateObj.getId(),true);
  }
  throw new CloudRuntimeException("String_Node_Str" + dataCenterId + "String_Node_Str");
}

Fixed version (ground truth):
@Override public UploadVO createEntityDownloadURL(VMTemplateVO template,VMTemplateHostVO vmTemplateHost,Long dataCenterId,long eventId){
  String errorString="String_Node_Str";
  boolean success=false;
  List<HostVO> storageServers=_serverDao.listByTypeDataCenter(Host.Type.SecondaryStorage,dataCenterId);
  if (storageServers == null)   throw new CloudRuntimeException("String_Node_Str" + dataCenterId);
  Type type=(template.getFormat() == ImageFormat.ISO) ? Type.ISO : Type.TEMPLATE;
  List<UploadVO> extractURLList=_uploadDao.listByTypeUploadStatus(template.getId(),type,UploadVO.Status.DOWNLOAD_URL_CREATED);
  if (extractURLList.size() > 0)   return extractURLList.get(0);
  HostVO sserver=storageServers.get(0);
  UploadVO uploadTemplateObj=new UploadVO(sserver.getId(),template.getId(),new Date(),Status.DOWNLOAD_URL_NOT_CREATED,0,type,Mode.HTTP_DOWNLOAD);
  uploadTemplateObj.setInstallPath(vmTemplateHost.getInstallPath());
  _uploadDao.persist(uploadTemplateObj);
  try {
    CreateEntityDownloadURLCommand cmd=new CreateEntityDownloadURLCommand(vmTemplateHost.getInstallPath());
    long result=send(sserver.getId(),cmd,null);
    if (result == -1) {
      errorString="String_Node_Str" + type + "String_Node_Str"+ template.getId();
      s_logger.error(errorString);
      throw new CloudRuntimeException(errorString);
    }
    List<SecondaryStorageVmVO> ssVms=_secStorageVmDao.getSecStorageVmListInStates(dataCenterId,State.Running);
    if (ssVms.size() > 0) {
      SecondaryStorageVmVO ssVm=ssVms.get(0);
      if (ssVm.getPublicIpAddress() == null) {
        errorString="String_Node_Str";
        s_logger.error(errorString);
        throw new CloudRuntimeException(errorString);
      }
      String extractURL=generateCopyUrl(ssVm.getPublicIpAddress(),vmTemplateHost.getInstallPath());
      UploadVO vo=_uploadDao.createForUpdate();
      vo.setLastUpdated(new Date());
      vo.setUploadUrl(extractURL);
      vo.setUploadState(Status.DOWNLOAD_URL_CREATED);
      _uploadDao.update(uploadTemplateObj.getId(),vo);
      success=true;
      return _uploadDao.findById(uploadTemplateObj.getId(),true);
    }
    errorString="String_Node_Str" + dataCenterId + "String_Node_Str";
    throw new CloudRuntimeException(errorString);
  }
  finally {
    if (!success) {
      UploadVO uploadJob=_uploadDao.createForUpdate(uploadTemplateObj.getId());
      uploadJob.setLastUpdated(new Date());
      uploadJob.setErrorString(errorString);
      uploadJob.setUploadState(Status.ERROR);
      _uploadDao.update(uploadTemplateObj.getId(),uploadJob);
    }
  }
}