Program: 15338
Project: 15338
Buggy source:
public CreateVolumeResponseType CreateVolume(final CreateVolumeType request) throws EucalyptusCloudException {
  Context ctx=Contexts.lookup();
  String action=PolicySpec.requestToAction(request);
  if (!ctx.hasAdministrativePrivileges()) {
    if (!Permissions.isAuthorized(PolicySpec.VENDOR_EC2,PolicySpec.EC2_RESOURCE_VOLUME,"String_Node_Str",ctx.getAccount(),action,ctx.getUser())) {
      throw new EucalyptusCloudException("String_Node_Str" + ctx.getUser().getName());
    }
    long volSize=0;
    try {
      volSize=Long.valueOf(request.getSize());
    }
 catch (    NumberFormatException e) {
      LOG.error("String_Node_Str" + request.getSize(),e);
      throw new EucalyptusCloudException(e);
    }
    if (!Permissions.canAllocate(PolicySpec.VENDOR_EC2,PolicySpec.EC2_RESOURCE_VOLUME,"String_Node_Str",action,ctx.getUser(),volSize)) {
      throw new EucalyptusCloudException("String_Node_Str" + ctx.getUser().getName());
    }
  }
  if ((request.getSnapshotId() == null && request.getSize() == null)) {
    throw new EucalyptusCloudException("String_Node_Str");
  }
  ServiceConfiguration sc=Partitions.lookupService(Storage.class,request.getAvailabilityZone());
  EntityWrapper<Volume> db=EntityWrapper.get(Volume.class);
  if (request.getSnapshotId() != null) {
    try {
      db.recast(Snapshot.class).getUnique(Snapshot.named(ctx.getUserFullName(),request.getSnapshotId()));
    }
 catch (    EucalyptusCloudException e) {
      LOG.debug(e,e);
      db.rollback();
      throw new EucalyptusCloudException("String_Node_Str" + request.getSnapshotId());
    }
  }
  String newId=null;
  Volume newVol=null;
  while (true) {
    newId=Crypto.generateId(ctx.getUserFullName().getAccountNumber(),ID_PREFIX);
    try {
      db.getUnique(Volume.named(null,newId));
    }
 catch (    EucalyptusCloudException e) {
      try {
        Integer newSize=new Integer(request.getSize() != null ? request.getSize() : "String_Node_Str");
        newVol=new Volume(ctx.getUserFullName(),newId,newSize,sc.getName(),sc.getPartition(),request.getSnapshotId());
        db.add(newVol);
        db.commit();
        break;
      }
 catch (      Throwable e1) {
        db.rollback();
        db=EntityWrapper.get(Volume.class);
      }
    }
  }
  newVol.setState(State.GENERATING);
  try {
    CreateStorageVolumeType req=new CreateStorageVolumeType(newId,request.getSize(),request.getSnapshotId(),null);
    req.regardingUserRequest(request);
    ServiceDispatcher.lookup(sc).send(req);
    try {
      ListenerRegistry.getInstance().fireEvent(new StorageEvent(StorageEvent.EventType.EbsVolume,true,newVol.getSize(),newVol.getOwnerUserId(),newVol.getOwnerAccountId(),newVol.getScName(),newVol.getPartition()));
    }
 catch (    EventFailedException ex) {
      LOG.error(ex,ex);
    }
  }
 catch (  EucalyptusCloudException e) {
    LOG.debug(e,e);
    try {
      db=EntityWrapper.get(Volume.class);
      Volume d=db.getUnique(Volume.named((UserFullName)newVol.getOwner(),newVol.getDisplayName()));
      db.delete(d);
      db.commit();
    }
 catch (    Throwable e1) {
      db.rollback();
      LOG.debug(e1,e1);
    }
    throw new EucalyptusCloudException("String_Node_Str" + e.getMessage());
  }
  CreateVolumeResponseType reply=(CreateVolumeResponseType)request.getReply();
  reply.setVolume(newVol.morph(new edu.ucsb.eucalyptus.msgs.Volume()));
  return reply;
}

Fixed version (ground truth):
public CreateVolumeResponseType CreateVolume(final CreateVolumeType request) throws EucalyptusCloudException {
  Context ctx=Contexts.lookup();
  String action=PolicySpec.requestToAction(request);
  if (!ctx.hasAdministrativePrivileges() && !Permissions.isAuthorized(PolicySpec.VENDOR_EC2,PolicySpec.EC2_RESOURCE_VOLUME,"String_Node_Str",ctx.getAccount(),action,ctx.getUser())) {
    throw new EucalyptusCloudException("String_Node_Str" + ctx.getUser().getName());
  }
  Long volSize=Long.parseLong(request.getSize());
  final String snapId=request.getSnapshotId();
  String partition=request.getAvailabilityZone();
  if (!ctx.hasAdministrativePrivileges() && !Permissions.canAllocate(PolicySpec.VENDOR_EC2,PolicySpec.EC2_RESOURCE_VOLUME,"String_Node_Str",action,ctx.getUser(),volSize)) {
    throw new EucalyptusCloudException("String_Node_Str" + ctx.getUser().getName());
  }
  if ((request.getSnapshotId() == null && request.getSize() == null)) {
    throw new EucalyptusCloudException("String_Node_Str");
  }
  final ServiceConfiguration sc=Partitions.lookupService(Storage.class,partition);
  if (snapId != null) {
    try {
      Snapshots.lookup(snapId);
    }
 catch (    ExecutionException ex) {
      throw new EucalyptusCloudException("String_Node_Str" + snapId);
    }
  }
  Exception lastEx=null;
  for (int i=0; i < VOL_CREATE_RETRIES; i++) {
    String newId=Crypto.generateId(ctx.getUserFullName().getAccountNumber(),ID_PREFIX);
    Integer newSize=new Integer(request.getSize() != null ? request.getSize() : "String_Node_Str");
    try {
      Volume newVol=Transactions.save(new Volume(ctx.getUserFullName(),newId,newSize,sc.getName(),sc.getPartition(),snapId),new Callback<Volume>(){
        @Override public void fire(        Volume t){
          t.setState(State.GENERATING);
          try {
            ListenerRegistry.getInstance().fireEvent(new StorageEvent(StorageEvent.EventType.EbsVolume,true,t.getSize(),t.getOwnerUserId(),t.getOwnerAccountId(),t.getScName(),t.getPartition()));
            CreateStorageVolumeType req=new CreateStorageVolumeType(t.getDisplayName(),t.getSize(),snapId,null).regardingUserRequest(request);
            ServiceDispatcher.lookup(sc).send(req);
          }
 catch (          Exception ex) {
            LOG.error("String_Node_Str" + t.toString(),ex);
            Transactions.join().delete(t);
          }
        }
      }
);
      CreateVolumeResponseType reply=request.getReply();
      reply.setVolume(newVol.morph(new edu.ucsb.eucalyptus.msgs.Volume()));
      return reply;
    }
 catch (    ExecutionException ex) {
      LOG.error(ex,ex);
      lastEx=ex;
    }
  }
  throw new EucalyptusCloudException("String_Node_Str" + VOL_CREATE_RETRIES + "String_Node_Str"+ lastEx,lastEx);
}