Program: 106154
Project: 106154
Buggy source:
@Override public Answer createVolumeFromSnapshot(CopyCommand cmd){
  try {
    DataTO srcData=cmd.getSrcTO();
    SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
    DataTO destData=cmd.getDestTO();
    PrimaryDataStoreTO pool=(PrimaryDataStoreTO)destData.getDataStore();
    DataStoreTO imageStore=srcData.getDataStore();
    VolumeObjectTO volume=snapshot.getVolume();
    if (!(imageStore instanceof NfsTO)) {
      return new CopyCmdAnswer("String_Node_Str");
    }
    NfsTO nfsImageStore=(NfsTO)imageStore;
    String snapshotFullPath=snapshot.getPath();
    int index=snapshotFullPath.lastIndexOf("String_Node_Str");
    String snapshotPath=snapshotFullPath.substring(0,index);
    String snapshotName=snapshotFullPath.substring(index + 1);
    KVMStoragePool secondaryPool=storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl() + File.separator + snapshotPath);
    KVMPhysicalDisk snapshotDisk=secondaryPool.getPhysicalDisk(snapshotName);
    if (volume.getFormat() == ImageFormat.RAW) {
      snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
    }
 else     if (volume.getFormat() == ImageFormat.QCOW2) {
      snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
    }
    String primaryUuid=pool.getUuid();
    KVMStoragePool primaryPool=storagePoolMgr.getStoragePool(pool.getPoolType(),primaryUuid);
    String volUuid=UUID.randomUUID().toString();
    KVMPhysicalDisk disk=storagePoolMgr.copyPhysicalDisk(snapshotDisk,volUuid,primaryPool);
    VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(disk.getName());
    newVol.setSize(disk.getVirtualSize());
    if (primaryPool.getType() == StoragePoolType.RBD) {
      newVol.setFormat(ImageFormat.RAW);
    }
    return new CopyCmdAnswer(newVol);
  }
 catch (  CloudRuntimeException e) {
    return new CopyCmdAnswer(e.toString());
  }
}

Fixed version (ground truth):
@Override public Answer createVolumeFromSnapshot(CopyCommand cmd){
  try {
    DataTO srcData=cmd.getSrcTO();
    SnapshotObjectTO snapshot=(SnapshotObjectTO)srcData;
    DataTO destData=cmd.getDestTO();
    PrimaryDataStoreTO pool=(PrimaryDataStoreTO)destData.getDataStore();
    DataStoreTO imageStore=srcData.getDataStore();
    VolumeObjectTO volume=snapshot.getVolume();
    if (!(imageStore instanceof NfsTO)) {
      return new CopyCmdAnswer("String_Node_Str");
    }
    NfsTO nfsImageStore=(NfsTO)imageStore;
    String snapshotFullPath=snapshot.getPath();
    int index=snapshotFullPath.lastIndexOf("String_Node_Str");
    String snapshotPath=snapshotFullPath.substring(0,index);
    String snapshotName=snapshotFullPath.substring(index + 1);
    KVMStoragePool secondaryPool=storagePoolMgr.getStoragePoolByURI(nfsImageStore.getUrl() + File.separator + snapshotPath);
    KVMPhysicalDisk snapshotDisk=secondaryPool.getPhysicalDisk(snapshotName);
    if (volume.getFormat() == ImageFormat.RAW) {
      snapshotDisk.setFormat(PhysicalDiskFormat.RAW);
    }
 else     if (volume.getFormat() == ImageFormat.QCOW2) {
      snapshotDisk.setFormat(PhysicalDiskFormat.QCOW2);
    }
    String primaryUuid=pool.getUuid();
    KVMStoragePool primaryPool=storagePoolMgr.getStoragePool(pool.getPoolType(),primaryUuid);
    String volUuid=UUID.randomUUID().toString();
    KVMPhysicalDisk disk=storagePoolMgr.copyPhysicalDisk(snapshotDisk,volUuid,primaryPool,cmd.getWaitInMillSeconds());
    VolumeObjectTO newVol=new VolumeObjectTO();
    newVol.setPath(disk.getName());
    newVol.setSize(disk.getVirtualSize());
    if (primaryPool.getType() == StoragePoolType.RBD) {
      newVol.setFormat(ImageFormat.RAW);
    }
    return new CopyCmdAnswer(newVol);
  }
 catch (  CloudRuntimeException e) {
    return new CopyCmdAnswer(e.toString());
  }
}