Program: 14135
Project: 14135
Buggy source:
public AttachVolumeResponseType AttachVolume(AttachVolumeType request) throws EucalyptusCloudException {
  AttachVolumeResponseType reply=(AttachVolumeResponseType)request.getReply();
  final String deviceName=request.getDevice();
  final String volumeId=normalizeVolumeIdentifier(request.getVolumeId());
  final String instanceId=normalizeInstanceIdentifier(request.getInstanceId());
  final Context ctx=Contexts.lookup();
  if (deviceName == null || !validateDeviceName(deviceName)) {
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + deviceName + "String_Node_Str");
  }
  VmInstance vm=null;
  try {
    vm=RestrictedTypes.doPrivileged(instanceId,VmInstance.class);
  }
 catch (  final NoSuchElementException e) {
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getInstanceId() + "String_Node_Str");
  }
catch (  Exception ex) {
    LOG.debug(ex,ex);
    throw new EucalyptusCloudException(ex.getMessage(),ex);
  }
  if (MigrationState.isMigrating(vm)) {
    throw Exceptions.toUndeclared("String_Node_Str" + vm.getInstanceId() + "String_Node_Str"+ vm.getMigrationTask());
  }
  AccountFullName ownerFullName=ctx.getUserFullName().asAccountFullName();
  Volume volume=null;
  try {
    volume=Volumes.lookup(ownerFullName,volumeId);
  }
 catch (  final NoSuchElementException ex) {
    try {
      volume=Volumes.lookup(null,volumeId);
    }
 catch (    NoSuchElementException e) {
      throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getVolumeId() + "String_Node_Str");
    }
  }
  if (!RestrictedTypes.filterPrivileged().apply(volume)) {
    throw new EucalyptusCloudException("String_Node_Str" + volumeId + "String_Node_Str"+ ctx.getUser().getName());
  }
  try {
    vm.lookupVolumeAttachmentByDevice(deviceName);
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getDevice());
  }
 catch (  NoSuchElementException ex1) {
  }
  if (Iterables.any(VmInstances.lookupEphemeralDevices(instanceId),new Predicate<VmEphemeralAttachment>(){
    @Override public boolean apply(    VmEphemeralAttachment device){
      return deviceName.endsWith(device.getShortDeviceName());
    }
  }
))   throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getDevice());
  try {
    VmInstances.lookupVolumeAttachment(volumeId);
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + volumeId);
  }
 catch (  NoSuchElementException ex1) {
  }
  Partition volPartition=Partitions.lookupByName(volume.getPartition());
  ServiceConfiguration sc=Topology.lookup(Storage.class,volPartition);
  ServiceConfiguration scVm=Topology.lookup(Storage.class,vm.lookupPartition());
  if (!sc.equals(scVm)) {
    throw new EucalyptusCloudException("String_Node_Str" + volumeId);
  }
  if (VmState.STOPPED.equals(vm.getState())) {
    String rootDevice=vm.getBootRecord().getMachine().getRootDeviceName();
    if (rootDevice.equals(deviceName)) {
      vm.addPermanentVolume(deviceName,volume,Boolean.TRUE);
    }
 else {
      vm.addPermanentVolume(deviceName,volume,Boolean.FALSE);
    }
  }
 else {
    ServiceConfiguration ccConfig=Topology.lookup(ClusterController.class,vm.lookupPartition());
    GetVolumeTokenResponseType scGetTokenResponse;
    try {
      GetVolumeTokenType req=new GetVolumeTokenType(volume.getDisplayName());
      scGetTokenResponse=AsyncRequests.sendSync(sc,req);
    }
 catch (    Exception e) {
      LOG.warn("String_Node_Str" + volume.getDisplayName(),e);
      throw new EucalyptusCloudException(e.getMessage(),e);
    }
    String token=StorageProperties.formatVolumeAttachmentTokenForTransfer(scGetTokenResponse.getToken(),volume.getDisplayName());
    final ClusterAttachVolumeType attachVolume=new ClusterAttachVolumeType();
    attachVolume.setInstanceId(request.getInstanceId());
    attachVolume.setVolumeId(request.getVolumeId());
    attachVolume.setDevice(request.getDevice());
    attachVolume.setRemoteDevice(token);
    vm.addTransientVolume(deviceName,token,volume);
    final VolumeAttachCallback cb=new VolumeAttachCallback(attachVolume);
    AsyncRequests.newRequest(cb).dispatch(ccConfig);
  }
  EventRecord.here(VolumeManager.class,EventClass.VOLUME,EventType.VOLUME_ATTACH).withDetails(volume.getOwner().toString(),volume.getDisplayName(),"String_Node_Str",vm.getInstanceId()).withDetails("String_Node_Str",vm.getPartition().toString()).info();
  reply.setAttachedVolume(new AttachedVolume(volume.getDisplayName(),vm.getInstanceId(),request.getDevice()));
  Volumes.fireUsageEvent(volume,VolumeEvent.forVolumeAttach(vm.getInstanceUuid(),volume.getDisplayName()));
  return reply;
}

Fixed version (ground truth):
public AttachVolumeResponseType AttachVolume(AttachVolumeType request) throws EucalyptusCloudException {
  AttachVolumeResponseType reply=(AttachVolumeResponseType)request.getReply();
  final String deviceName=request.getDevice();
  final String volumeId=normalizeVolumeIdentifier(request.getVolumeId());
  final String instanceId=normalizeInstanceIdentifier(request.getInstanceId());
  final Context ctx=Contexts.lookup();
  if (deviceName == null || !validateDeviceName(deviceName)) {
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + deviceName + "String_Node_Str");
  }
  VmInstance vm=null;
  try {
    vm=RestrictedTypes.doPrivileged(instanceId,VmInstance.class);
  }
 catch (  final NoSuchElementException e) {
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getInstanceId() + "String_Node_Str");
  }
catch (  Exception ex) {
    throw handleException(ex);
  }
  if (MigrationState.isMigrating(vm)) {
    throw Exceptions.toUndeclared("String_Node_Str" + vm.getInstanceId() + "String_Node_Str"+ vm.getMigrationTask());
  }
  AccountFullName ownerFullName=ctx.getUserFullName().asAccountFullName();
  Volume volume=null;
  try {
    volume=Volumes.lookup(ownerFullName,volumeId);
  }
 catch (  final NoSuchElementException ex) {
    try {
      volume=Volumes.lookup(null,volumeId);
    }
 catch (    NoSuchElementException e) {
      throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getVolumeId() + "String_Node_Str");
    }
  }
  if (!RestrictedTypes.filterPrivileged().apply(volume)) {
    throw new ClientUnauthorizedComputeException("String_Node_Str" + volumeId + "String_Node_Str"+ ctx.getUser().getName());
  }
  try {
    vm.lookupVolumeAttachmentByDevice(deviceName);
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getDevice());
  }
 catch (  NoSuchElementException ex1) {
  }
  if (Iterables.any(VmInstances.lookupEphemeralDevices(instanceId),new Predicate<VmEphemeralAttachment>(){
    @Override public boolean apply(    VmEphemeralAttachment device){
      return deviceName.endsWith(device.getShortDeviceName());
    }
  }
))   throw new ClientComputeException("String_Node_Str","String_Node_Str" + request.getDevice());
  try {
    VmInstances.lookupVolumeAttachment(volumeId);
    throw new ClientComputeException("String_Node_Str","String_Node_Str" + volumeId);
  }
 catch (  NoSuchElementException ex1) {
  }
  Partition volPartition=Partitions.lookupByName(volume.getPartition());
  ServiceConfiguration sc=Topology.lookup(Storage.class,volPartition);
  ServiceConfiguration scVm=Topology.lookup(Storage.class,vm.lookupPartition());
  if (!sc.equals(scVm)) {
    throw new EucalyptusCloudException("String_Node_Str" + volumeId);
  }
  if (VmState.STOPPED.equals(vm.getState())) {
    String rootDevice=vm.getBootRecord().getMachine().getRootDeviceName();
    if (rootDevice.equals(deviceName)) {
      vm.addPermanentVolume(deviceName,volume,Boolean.TRUE);
    }
 else {
      vm.addPermanentVolume(deviceName,volume,Boolean.FALSE);
    }
  }
 else {
    ServiceConfiguration ccConfig=Topology.lookup(ClusterController.class,vm.lookupPartition());
    GetVolumeTokenResponseType scGetTokenResponse;
    try {
      GetVolumeTokenType req=new GetVolumeTokenType(volume.getDisplayName());
      scGetTokenResponse=AsyncRequests.sendSync(sc,req);
    }
 catch (    Exception e) {
      LOG.warn("String_Node_Str" + volume.getDisplayName(),e);
      throw new EucalyptusCloudException(e.getMessage(),e);
    }
    String token=StorageProperties.formatVolumeAttachmentTokenForTransfer(scGetTokenResponse.getToken(),volume.getDisplayName());
    final ClusterAttachVolumeType attachVolume=new ClusterAttachVolumeType();
    attachVolume.setInstanceId(request.getInstanceId());
    attachVolume.setVolumeId(request.getVolumeId());
    attachVolume.setDevice(request.getDevice());
    attachVolume.setRemoteDevice(token);
    vm.addTransientVolume(deviceName,token,volume);
    final VolumeAttachCallback cb=new VolumeAttachCallback(attachVolume);
    AsyncRequests.newRequest(cb).dispatch(ccConfig);
  }
  EventRecord.here(VolumeManager.class,EventClass.VOLUME,EventType.VOLUME_ATTACH).withDetails(volume.getOwner().toString(),volume.getDisplayName(),"String_Node_Str",vm.getInstanceId()).withDetails("String_Node_Str",vm.getPartition().toString()).info();
  reply.setAttachedVolume(new AttachedVolume(volume.getDisplayName(),vm.getInstanceId(),request.getDevice()));
  Volumes.fireUsageEvent(volume,VolumeEvent.forVolumeAttach(vm.getInstanceUuid(),volume.getDisplayName()));
  return reply;
}