Program: 105295
Project: 105295
Buggy source:
@Override public Answer execute(final CreatePrivateTemplateFromVolumeCommand command,final LibvirtComputingResource libvirtComputingResource){
  final String secondaryStorageURL=command.getSecondaryStorageUrl();
  KVMStoragePool secondaryStorage=null;
  KVMStoragePool primary=null;
  final KVMStoragePoolManager storagePoolMgr=libvirtComputingResource.getStoragePoolMgr();
  try {
    final String templateFolder=command.getAccountId() + File.separator + command.getTemplateId()+ File.separator;
    final String templateInstallFolder="String_Node_Str" + templateFolder;
    secondaryStorage=storagePoolMgr.getStoragePoolByURI(secondaryStorageURL);
    try {
      primary=storagePoolMgr.getStoragePool(command.getPool().getType(),command.getPrimaryStoragePoolNameLabel());
    }
 catch (    final CloudRuntimeException e) {
      if (e.getMessage().contains("String_Node_Str")) {
        primary=storagePoolMgr.createStoragePool(command.getPool().getUuid(),command.getPool().getHost(),command.getPool().getPort(),command.getPool().getPath(),command.getPool().getUserInfo(),command.getPool().getType());
      }
 else {
        return new CreatePrivateTemplateAnswer(command,false,e.getMessage());
      }
    }
    final KVMPhysicalDisk disk=primary.getPhysicalDisk(command.getVolumePath());
    final String tmpltPath=secondaryStorage.getLocalPath() + File.separator + templateInstallFolder;
    final StorageLayer storage=libvirtComputingResource.getStorage();
    storage.mkdirs(tmpltPath);
    if (primary.getType() != StoragePoolType.RBD) {
      final String createTmplPath=libvirtComputingResource.createTmplPath();
      final int cmdsTimeout=libvirtComputingResource.getCmdsTimeout();
      final Script scriptCommand=new Script(createTmplPath,cmdsTimeout,s_logger);
      scriptCommand.add("String_Node_Str",disk.getPath());
      scriptCommand.add("String_Node_Str",tmpltPath);
      scriptCommand.add("String_Node_Str",command.getUniqueName() + "String_Node_Str");
      final String result=scriptCommand.execute();
      if (result != null) {
        s_logger.debug("String_Node_Str" + result);
        return new CreatePrivateTemplateAnswer(command,false,result);
      }
    }
 else {
      s_logger.debug("String_Node_Str" + disk.getPath() + "String_Node_Str"+ command.getUniqueName());
      final QemuImgFile srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),primary.getSourcePort(),primary.getAuthUserName(),primary.getAuthSecret(),disk.getPath()));
      srcFile.setFormat(PhysicalDiskFormat.RAW);
      final QemuImgFile destFile=new QemuImgFile(tmpltPath + "String_Node_Str" + command.getUniqueName()+ "String_Node_Str");
      destFile.setFormat(PhysicalDiskFormat.QCOW2);
      final QemuImg q=new QemuImg(0);
      try {
        q.convert(srcFile,destFile);
      }
 catch (      final QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      }
      final File templateProp=new File(tmpltPath + "String_Node_Str");
      if (!templateProp.exists()) {
        templateProp.createNewFile();
      }
      String templateContent="String_Node_Str" + command.getUniqueName() + "String_Node_Str"+ System.getProperty("String_Node_Str");
      final DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      final Date date=new Date();
      templateContent+="String_Node_Str" + dateFormat.format(date) + System.getProperty("String_Node_Str");
      try (FileOutputStream templFo=new FileOutputStream(templateProp)){
        templFo.write(templateContent.getBytes());
        templFo.flush();
      }
 catch (      final IOException ex) {
        s_logger.error("String_Node_Str" + ex.getMessage());
      }
    }
    final Map<String,Object> params=new HashMap<String,Object>();
    params.put(StorageLayer.InstanceConfigKey,storage);
    final Processor qcow2Processor=new QCOW2Processor();
    qcow2Processor.configure("String_Node_Str",params);
    final FormatInfo info=qcow2Processor.process(tmpltPath,null,command.getUniqueName());
    final TemplateLocation loc=new TemplateLocation(storage,tmpltPath);
    loc.create(1,true,command.getUniqueName());
    loc.addFormat(info);
    loc.save();
    return new CreatePrivateTemplateAnswer(command,true,null,templateInstallFolder + command.getUniqueName() + "String_Node_Str",info.virtualSize,info.size,command.getUniqueName(),ImageFormat.QCOW2);
  }
 catch (  final InternalErrorException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final IOException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final ConfigurationException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final CloudRuntimeException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
 finally {
    if (secondaryStorage != null) {
      storagePoolMgr.deleteStoragePool(secondaryStorage.getType(),secondaryStorage.getUuid());
    }
  }
}

Fixed version (ground truth):
@Override public Answer execute(final CreatePrivateTemplateFromVolumeCommand command,final LibvirtComputingResource libvirtComputingResource){
  final String secondaryStorageURL=command.getSecondaryStorageUrl();
  KVMStoragePool secondaryStorage=null;
  KVMStoragePool primary=null;
  final KVMStoragePoolManager storagePoolMgr=libvirtComputingResource.getStoragePoolMgr();
  try {
    final String templateFolder=command.getAccountId() + File.separator + command.getTemplateId()+ File.separator;
    final String templateInstallFolder="String_Node_Str" + templateFolder;
    secondaryStorage=storagePoolMgr.getStoragePoolByURI(secondaryStorageURL);
    try {
      primary=storagePoolMgr.getStoragePool(command.getPool().getType(),command.getPrimaryStoragePoolNameLabel());
    }
 catch (    final CloudRuntimeException e) {
      if (e.getMessage().contains("String_Node_Str")) {
        primary=storagePoolMgr.createStoragePool(command.getPool().getUuid(),command.getPool().getHost(),command.getPool().getPort(),command.getPool().getPath(),command.getPool().getUserInfo(),command.getPool().getType());
      }
 else {
        return new CreatePrivateTemplateAnswer(command,false,e.getMessage());
      }
    }
    final KVMPhysicalDisk disk=primary.getPhysicalDisk(command.getVolumePath());
    final String tmpltPath=secondaryStorage.getLocalPath() + File.separator + templateInstallFolder;
    final StorageLayer storage=libvirtComputingResource.getStorage();
    storage.mkdirs(tmpltPath);
    if (primary.getType() != StoragePoolType.RBD) {
      final String createTmplPath=libvirtComputingResource.createTmplPath();
      final int cmdsTimeout=libvirtComputingResource.getCmdsTimeout();
      final Script scriptCommand=new Script(createTmplPath,cmdsTimeout,s_logger);
      scriptCommand.add("String_Node_Str",disk.getPath());
      scriptCommand.add("String_Node_Str",tmpltPath);
      scriptCommand.add("String_Node_Str",command.getUniqueName() + "String_Node_Str");
      final String result=scriptCommand.execute();
      if (result != null) {
        s_logger.debug("String_Node_Str" + result);
        return new CreatePrivateTemplateAnswer(command,false,result);
      }
    }
 else {
      s_logger.debug("String_Node_Str" + disk.getPath() + "String_Node_Str"+ command.getUniqueName());
      final QemuImgFile srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(primary.getSourceHost(),primary.getSourcePort(),primary.getAuthUserName(),primary.getAuthSecret(),disk.getPath()));
      srcFile.setFormat(PhysicalDiskFormat.RAW);
      final QemuImgFile destFile=new QemuImgFile(tmpltPath + "String_Node_Str" + command.getUniqueName()+ "String_Node_Str");
      destFile.setFormat(PhysicalDiskFormat.QCOW2);
      final QemuImg q=new QemuImg(0);
      try {
        q.convert(srcFile,destFile);
      }
 catch (      final QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      }
      final File templateProp=new File(tmpltPath + "String_Node_Str");
      if (!templateProp.exists()) {
        templateProp.createNewFile();
      }
      String templateContent="String_Node_Str" + command.getUniqueName() + "String_Node_Str"+ System.getProperty("String_Node_Str");
      final DateFormat dateFormat=new SimpleDateFormat("String_Node_Str");
      final Date date=new Date();
      templateContent+="String_Node_Str" + dateFormat.format(date) + System.getProperty("String_Node_Str");
      try (FileOutputStream templFo=new FileOutputStream(templateProp)){
        templFo.write(templateContent.getBytes("String_Node_Str"));
        templFo.flush();
      }
 catch (      final IOException ex) {
        s_logger.error("String_Node_Str" + ex.getMessage());
      }
    }
    final Map<String,Object> params=new HashMap<String,Object>();
    params.put(StorageLayer.InstanceConfigKey,storage);
    final Processor qcow2Processor=new QCOW2Processor();
    qcow2Processor.configure("String_Node_Str",params);
    final FormatInfo info=qcow2Processor.process(tmpltPath,null,command.getUniqueName());
    final TemplateLocation loc=new TemplateLocation(storage,tmpltPath);
    loc.create(1,true,command.getUniqueName());
    loc.addFormat(info);
    loc.save();
    return new CreatePrivateTemplateAnswer(command,true,null,templateInstallFolder + command.getUniqueName() + "String_Node_Str",info.virtualSize,info.size,command.getUniqueName(),ImageFormat.QCOW2);
  }
 catch (  final InternalErrorException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final IOException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final ConfigurationException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
catch (  final CloudRuntimeException e) {
    return new CreatePrivateTemplateAnswer(command,false,e.toString());
  }
 finally {
    if (secondaryStorage != null) {
      storagePoolMgr.deleteStoragePool(secondaryStorage.getType(),secondaryStorage.getUuid());
    }
  }
}