Program: 89122
Project: 89122
Buggy source:
protected Pair<String,String> createVDIFromSnapshot(long userId,SnapshotVO snapshot,StoragePoolVO pool){
  String vdiUUID=null;
  Long snapshotId=snapshot.getId();
  Long volumeId=snapshot.getVolumeId();
  String primaryStoragePoolNameLabel=pool.getUuid();
  Long dcId=snapshot.getDataCenterId();
  String secondaryStoragePoolUrl=_snapMgr.getSecondaryStorageURL(snapshot);
  long accountId=snapshot.getAccountId();
  String backedUpSnapshotUuid=snapshot.getBackupSnapshotId();
  snapshot=_snapshotDao.findById(snapshotId);
  if (snapshot.getVersion().trim().equals("String_Node_Str")) {
    VolumeVO volume=_volsDao.findByIdIncludingRemoved(volumeId);
    if (volume == null) {
      throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str"+ volumeId+ "String_Node_Str");
    }
    if (volume.getTemplateId() == null) {
      _snapshotDao.updateSnapshotVersion(volumeId,"String_Node_Str","String_Node_Str");
    }
 else {
      VMTemplateVO template=_templateDao.findByIdIncludingRemoved(volume.getTemplateId());
      if (template == null) {
        throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str"+ volume.getTemplateId()+ "String_Node_Str");
      }
      Long templateId=template.getId();
      Long tmpltAccountId=template.getAccountId();
      if (!_snapshotDao.lockInLockTable(snapshotId.toString(),10)) {
        throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str");
      }
      UpgradeSnapshotCommand cmd=new UpgradeSnapshotCommand(null,secondaryStoragePoolUrl,dcId,accountId,volumeId,templateId,tmpltAccountId,null,snapshot.getBackupSnapshotId(),snapshot.getName(),"String_Node_Str");
      Answer answer=null;
      try {
        answer=sendToPool(pool,cmd);
      }
 catch (      StorageUnavailableException e) {
      }
 finally {
        _snapshotDao.unlockFromLockTable(snapshotId.toString());
      }
      if ((answer != null) && answer.getResult()) {
        _snapshotDao.updateSnapshotVersion(volumeId,"String_Node_Str","String_Node_Str");
      }
 else {
        return new Pair<String,String>(null,"String_Node_Str" + snapshot.getId());
      }
    }
  }
  String basicErrMsg="String_Node_Str" + snapshot.getName() + "String_Node_Str"+ pool;
  try {
    if (snapshot.getSwiftId() != null) {
      _snapshotMgr.downloadSnapshotsFromSwift(snapshot);
    }
    CreateVolumeFromSnapshotCommand createVolumeFromSnapshotCommand=new CreateVolumeFromSnapshotCommand(primaryStoragePoolNameLabel,secondaryStoragePoolUrl,dcId,accountId,volumeId,backedUpSnapshotUuid,snapshot.getName(),_createVolumeFromSnapshotWait);
    CreateVolumeFromSnapshotAnswer answer;
    if (!_snapshotDao.lockInLockTable(snapshotId.toString(),10)) {
      throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str");
    }
    answer=(CreateVolumeFromSnapshotAnswer)sendToPool(pool,createVolumeFromSnapshotCommand);
    if (answer != null && answer.getResult()) {
      vdiUUID=answer.getVdi();
    }
 else {
      s_logger.error(basicErrMsg + "String_Node_Str" + ((answer == null) ? "String_Node_Str" : answer.getDetails()));
      throw new CloudRuntimeException(basicErrMsg);
    }
  }
 catch (  StorageUnavailableException e) {
    s_logger.error(basicErrMsg);
  }
 finally {
    if (snapshot.getSwiftId() != null) {
      _snapshotMgr.deleteSnapshotsDirForVolume(secondaryStoragePoolUrl,dcId,accountId,volumeId);
    }
    _snapshotDao.unlockFromLockTable(snapshotId.toString());
  }
  return new Pair<String,String>(vdiUUID,basicErrMsg);
}

Fixed version (ground truth):
protected Pair<String,String> createVDIFromSnapshot(long userId,SnapshotVO snapshot,StoragePoolVO pool){
  String vdiUUID=null;
  Long snapshotId=snapshot.getId();
  Long volumeId=snapshot.getVolumeId();
  String primaryStoragePoolNameLabel=pool.getUuid();
  Long dcId=snapshot.getDataCenterId();
  String secondaryStoragePoolUrl=_snapMgr.getSecondaryStorageURL(snapshot);
  long accountId=snapshot.getAccountId();
  String backedUpSnapshotUuid=snapshot.getBackupSnapshotId();
  snapshot=_snapshotDao.findById(snapshotId);
  if (snapshot.getVersion().trim().equals("String_Node_Str")) {
    VolumeVO volume=_volsDao.findByIdIncludingRemoved(volumeId);
    if (volume == null) {
      throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str"+ volumeId+ "String_Node_Str");
    }
    if (volume.getTemplateId() == null) {
      _snapshotDao.updateSnapshotVersion(volumeId,"String_Node_Str","String_Node_Str");
    }
 else {
      VMTemplateVO template=_templateDao.findByIdIncludingRemoved(volume.getTemplateId());
      if (template == null) {
        throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str"+ volume.getTemplateId()+ "String_Node_Str");
      }
      Long templateId=template.getId();
      Long tmpltAccountId=template.getAccountId();
      if (!_snapshotDao.lockInLockTable(snapshotId.toString(),10)) {
        throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str");
      }
      UpgradeSnapshotCommand cmd=new UpgradeSnapshotCommand(null,secondaryStoragePoolUrl,dcId,accountId,volumeId,templateId,tmpltAccountId,null,snapshot.getBackupSnapshotId(),snapshot.getName(),"String_Node_Str");
      Answer answer=null;
      try {
        answer=sendToPool(pool,cmd);
      }
 catch (      StorageUnavailableException e) {
      }
 finally {
        _snapshotDao.unlockFromLockTable(snapshotId.toString());
      }
      if ((answer != null) && answer.getResult()) {
        _snapshotDao.updateSnapshotVersion(volumeId,"String_Node_Str","String_Node_Str");
      }
 else {
        return new Pair<String,String>(null,"String_Node_Str" + snapshot.getId());
      }
    }
  }
  String basicErrMsg="String_Node_Str" + snapshot.getName() + "String_Node_Str"+ pool;
  try {
    if (snapshot.getSwiftId() != null && snapshot.getSwiftId() != 0) {
      _snapshotMgr.downloadSnapshotsFromSwift(snapshot);
    }
    CreateVolumeFromSnapshotCommand createVolumeFromSnapshotCommand=new CreateVolumeFromSnapshotCommand(primaryStoragePoolNameLabel,secondaryStoragePoolUrl,dcId,accountId,volumeId,backedUpSnapshotUuid,snapshot.getName(),_createVolumeFromSnapshotWait);
    CreateVolumeFromSnapshotAnswer answer;
    if (!_snapshotDao.lockInLockTable(snapshotId.toString(),10)) {
      throw new CloudRuntimeException("String_Node_Str" + snapshotId + "String_Node_Str");
    }
    answer=(CreateVolumeFromSnapshotAnswer)sendToPool(pool,createVolumeFromSnapshotCommand);
    if (answer != null && answer.getResult()) {
      vdiUUID=answer.getVdi();
    }
 else {
      s_logger.error(basicErrMsg + "String_Node_Str" + ((answer == null) ? "String_Node_Str" : answer.getDetails()));
      throw new CloudRuntimeException(basicErrMsg);
    }
  }
 catch (  StorageUnavailableException e) {
    s_logger.error(basicErrMsg);
  }
 finally {
    if (snapshot.getSwiftId() != null) {
      _snapshotMgr.deleteSnapshotsDirForVolume(secondaryStoragePoolUrl,dcId,accountId,volumeId);
    }
    _snapshotDao.unlockFromLockTable(snapshotId.toString());
  }
  return new Pair<String,String>(vdiUUID,basicErrMsg);
}