Program: 14149
Project: 14149
Buggy source:
private void setupVolumeMessages() throws NoSuchElementException, MetadataException, ExecutionException {
  if (this.allocInfo.getBootSet().getMachine() instanceof BlockStorageImageInfo) {
    List<BlockDeviceMappingItemType> instanceDeviceMappings=new ArrayList<BlockDeviceMappingItemType>(this.allocInfo.getRequest().getBlockDeviceMapping());
    final ServiceConfiguration sc=Topology.lookup(Storage.class,this.cluster.getConfiguration().lookupPartition());
    final BlockStorageImageInfo imgInfo=((BlockStorageImageInfo)this.allocInfo.getBootSet().getMachine());
    final String rootDevName=imgInfo.getRootDeviceName();
    Long volSizeBytes=imgInfo.getImageSizeBytes();
    for (    final BlockDeviceMappingItemType blockDevMapping : Iterables.filter(instanceDeviceMappings,findEbsRootOptionalSnapshot(rootDevName))) {
      if (blockDevMapping.getEbs().getVolumeSize() != null) {
        volSizeBytes=BYTES_PER_GB * blockDevMapping.getEbs().getVolumeSize();
      }
    }
    int rootVolSizeInGb=(int)Math.ceil(((double)volSizeBytes) / BYTES_PER_GB);
    for (    final ResourceToken token : this.allocInfo.getAllocationTokens()) {
      final VmInstance vm=VmInstances.lookup(token.getInstanceId());
      if (!vm.getBootRecord().hasPersistentVolumes()) {
        for (        final BlockDeviceMappingItemType mapping : instanceDeviceMappings) {
          if (Images.isEbsMapping(mapping)) {
            LOG.debug("String_Node_Str" + vm.getDisplayName() + "String_Node_Str"+ mapping.getDeviceName()+ "String_Node_Str");
            int volumeSize=mapping.getEbs().getVolumeSize() != null ? mapping.getEbs().getVolumeSize() : -1;
            if (volumeSize <= 0) {
              if (mapping.getEbs().getSnapshotId() != null) {
                final Snapshot originalSnapshot=Snapshots.lookup(null,ResourceIdentifiers.tryNormalize().apply(mapping.getEbs().getSnapshotId()));
                volumeSize=originalSnapshot.getVolumeSize();
              }
 else               volumeSize=rootVolSizeInGb;
            }
            final UserFullName fullName=this.allocInfo.getOwnerFullName();
            final String snapshotId=ResourceIdentifiers.tryNormalize().apply(mapping.getEbs().getSnapshotId());
            final int volSize=volumeSize;
            final BaseMessage request=this.allocInfo.getRequest();
            final Callable<Volume> createVolume=new Callable<Volume>(){
              public Volume call() throws Exception {
                return Volumes.createStorageVolume(sc,fullName,snapshotId,volSize,request);
              }
            }
;
            final Volume volume;
            try {
              volume=Threads.enqueue(Eucalyptus.class,ClusterAllocator.class,createVolume).get();
            }
 catch (            InterruptedException e) {
              throw Exceptions.toUndeclared("String_Node_Str",e);
            }
            final Boolean isRootDevice=mapping.getDeviceName().equals(rootDevName);
            if (mapping.getEbs().getDeleteOnTermination()) {
              vm.addPersistentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
 else {
              vm.addPermanentVolume(mapping.getDeviceName(),volume,isRootDevice);
            }
            if (isRootDevice) {
              token.setRootVolume(volume);
            }
 else {
              token.getEbsVolumes().put(mapping.getDeviceName(),volume);
            }
          }
 else           if (mapping.getVirtualName() != null) {
            vm.addEphemeralAttachment(mapping.getDeviceName(),mapping.getVirtualName());
            token.getEphemeralDisks().put(mapping.getDeviceName(),mapping.getVirtualName());
          }
        }
      }
 else {
        boolean foundRoot=false;
        for (        VmVolumeAttachment attachment : vm.getBootRecord().getPersistentVolumes()) {
          final Volume volume=Volumes.lookup(null,attachment.getVolumeId());
          if (attachment.getIsRootDevice() || attachment.getDevice().equals(rootDevName)) {
            token.setRootVolume(volume);
            foundRoot=true;
          }
 else {
            token.getEbsVolumes().put(attachment.getDevice(),volume);
          }
        }
        if (!foundRoot) {
          LOG.error("String_Node_Str");
          throw new MetadataException("String_Node_Str");
        }
        for (        VmEphemeralAttachment attachment : vm.getBootRecord().getEphemeralStorage()) {
          token.getEphemeralDisks().put(attachment.getDevice(),attachment.getEphemeralId());
        }
      }
    }
  }
}

Fixed version (ground truth):
private void setupVolumeMessages() throws NoSuchElementException, MetadataException, ExecutionException {
  if (this.allocInfo.getBootSet().getMachine() instanceof BlockStorageImageInfo) {
    List<BlockDeviceMappingItemType> instanceDeviceMappings=new ArrayList<BlockDeviceMappingItemType>(this.allocInfo.getRequest().getBlockDeviceMapping());
    final ServiceConfiguration sc=Topology.lookup(Storage.class,this.cluster.getConfiguration().lookupPartition());
    final BlockStorageImageInfo imgInfo=((BlockStorageImageInfo)this.allocInfo.getBootSet().getMachine());
    final String rootDevName=imgInfo.getRootDeviceName();
    Long volSizeBytes=imgInfo.getImageSizeBytes();
    for (    final BlockDeviceMappingItemType blockDevMapping : Iterables.filter(instanceDeviceMappings,findEbsRootOptionalSnapshot(rootDevName))) {
      if (blockDevMapping.getEbs().getVolumeSize() != null) {
        volSizeBytes=BYTES_PER_GB * blockDevMapping.getEbs().getVolumeSize();
      }
    }
    int rootVolSizeInGb=(int)Math.ceil(((double)volSizeBytes) / BYTES_PER_GB);
    for (    final ResourceToken token : this.allocInfo.getAllocationTokens()) {
      final VmInstance vm=VmInstances.lookup(token.getInstanceId());
      if (!vm.getBootRecord().hasPersistentVolumes()) {
        if (!instanceDeviceMappings.isEmpty()) {
          for (          final BlockDeviceMappingItemType mapping : instanceDeviceMappings) {
            if (Images.isEbsMapping(mapping)) {
              LOG.debug("String_Node_Str" + vm.getDisplayName() + "String_Node_Str"+ mapping.getDeviceName()+ "String_Node_Str");
              int volumeSize=mapping.getEbs().getVolumeSize() != null ? mapping.getEbs().getVolumeSize() : -1;
              if (volumeSize <= 0) {
                if (mapping.getEbs().getSnapshotId() != null) {
                  final Snapshot originalSnapshot=Snapshots.lookup(null,ResourceIdentifiers.tryNormalize().apply(mapping.getEbs().getSnapshotId()));
                  volumeSize=originalSnapshot.getVolumeSize();
                }
 else                 volumeSize=rootVolSizeInGb;
              }
              final UserFullName fullName=this.allocInfo.getOwnerFullName();
              final String snapshotId=ResourceIdentifiers.tryNormalize().apply(mapping.getEbs().getSnapshotId());
              final int volSize=volumeSize;
              final BaseMessage request=this.allocInfo.getRequest();
              final Callable<Volume> createVolume=new Callable<Volume>(){
                public Volume call() throws Exception {
                  return Volumes.createStorageVolume(sc,fullName,snapshotId,volSize,request);
                }
              }
;
              final Volume volume;
              try {
                volume=Threads.enqueue(Eucalyptus.class,ClusterAllocator.class,createVolume).get();
              }
 catch (              InterruptedException e) {
                throw Exceptions.toUndeclared("String_Node_Str",e);
              }
              final Boolean isRootDevice=mapping.getDeviceName().equals(rootDevName);
              if (mapping.getEbs().getDeleteOnTermination()) {
                vm.addPersistentVolume(mapping.getDeviceName(),volume,isRootDevice);
              }
 else {
                vm.addPermanentVolume(mapping.getDeviceName(),volume,isRootDevice);
              }
              if (isRootDevice) {
                token.setRootVolume(volume);
              }
 else {
                token.getEbsVolumes().put(mapping.getDeviceName(),volume);
              }
            }
 else             if (mapping.getVirtualName() != null) {
              vm.addEphemeralAttachment(mapping.getDeviceName(),mapping.getVirtualName());
              token.getEphemeralDisks().put(mapping.getDeviceName(),mapping.getVirtualName());
            }
          }
        }
 else {
          LOG.error("String_Node_Str" + vm.getInstanceId() + "String_Node_Str");
          throw new MetadataException("String_Node_Str" + vm.getInstanceId() + "String_Node_Str");
        }
      }
 else {
        boolean foundRoot=false;
        for (        VmVolumeAttachment attachment : vm.getBootRecord().getPersistentVolumes()) {
          final Volume volume=Volumes.lookup(null,attachment.getVolumeId());
          if (attachment.getIsRootDevice() || attachment.getDevice().equals(rootDevName)) {
            token.setRootVolume(volume);
            foundRoot=true;
          }
 else {
            token.getEbsVolumes().put(attachment.getDevice(),volume);
          }
        }
        if (!foundRoot) {
          LOG.error("String_Node_Str" + vm.getInstanceId() + "String_Node_Str");
          throw new MetadataException("String_Node_Str" + vm.getInstanceId() + "String_Node_Str");
        }
        for (        VmEphemeralAttachment attachment : vm.getBootRecord().getEphemeralStorage()) {
          token.getEphemeralDisks().put(attachment.getDevice(),attachment.getEphemeralId());
        }
      }
    }
  }
}