Program: 48696
Project: 48696
Buggy source:
private List<DiskSpec> evenSpliter(DiskSpec separable,List<AbstractDatastore> datastores){
  Collections.sort(datastores);
  int length=datastores.size() + 1;
  int[] free=new int[length];
  int[] partSum=new int[length];
  int iter=0;
  for (int i=0; i < length; i++) {
    if (i == 0) {
      free[0]=0;
      partSum[0]=0;
    }
 else {
      free[i]=datastores.get(i - 1).getFreeSpace();
      partSum[i]=iter + (free[i] - free[i - 1]) * (length - i);
      iter=partSum[i];
    }
  }
  if (partSum[length - 1] < separable.getSize()) {
    logger.error("String_Node_Str" + separable.toString());
    return null;
  }
  int index=Arrays.binarySearch(partSum,separable.getSize());
  if (index < 0)   index=-1 * (index + 1);
  index--;
  int remain=(index == 0) ? separable.getSize() : (separable.getSize() - partSum[index]);
  int ave=(remain + length - index - 2) / (length - index - 1);
  int[] allocation=new int[length - 1];
  for (int i=0; i < length - 1; i++) {
    if (i < index) {
      allocation[i]=free[i + 1];
    }
 else     if (remain > 0) {
      if (remain >= ave) {
        allocation[i]=free[index] + ave;
      }
 else {
        allocation[i]=free[index] + remain;
      }
      remain-=ave;
    }
 else {
      allocation[i]=free[index];
    }
  }
  index=0;
  List<DiskSpec> disks=new ArrayList<DiskSpec>();
  for (int i=0; i < length - 1; i++) {
    if (allocation[i] != 0) {
      DiskSpec subDisk=new DiskSpec(separable);
      subDisk.setSize(allocation[i]);
      subDisk.setSeparable(false);
      subDisk.setTargetDs(datastores.get(i).getName());
      subDisk.setName(separable.getName().split("String_Node_Str")[0] + index + "String_Node_Str");
      disks.add(subDisk);
      datastores.get(i).allocate(allocation[i]);
      index++;
    }
  }
  return disks;
}

Fixed version (ground truth):
private List<DiskSpec> evenSpliter(DiskSpec separable,List<AbstractDatastore> originDatastores){
  int minDiskSize=2;
  int maxNumDatastores=(separable.getSize() + minDiskSize - 1) / minDiskSize;
  Collections.sort(originDatastores);
  List<AbstractDatastore> datastores=new ArrayList<AbstractDatastore>();
  int numDatastores=0;
  for (  AbstractDatastore datastore : originDatastores) {
    if (datastore.getFreeSpace() < minDiskSize)     continue;
    datastores.add(datastore);
    numDatastores++;
    if (numDatastores == maxNumDatastores)     break;
  }
  int length=datastores.size() + 1;
  int[] free=new int[length];
  int[] partSum=new int[length];
  int iter=0;
  for (int i=0; i < length; i++) {
    if (i == 0) {
      free[0]=0;
      partSum[0]=0;
    }
 else {
      free[i]=datastores.get(i - 1).getFreeSpace();
      partSum[i]=iter + (free[i] - free[i - 1]) * (length - i);
      iter=partSum[i];
    }
  }
  if (partSum[length - 1] < separable.getSize()) {
    logger.error("String_Node_Str" + separable.toString());
    return null;
  }
  int index=Arrays.binarySearch(partSum,separable.getSize());
  if (index < 0)   index=-1 * (index + 1);
  index--;
  int remain=(index == 0) ? separable.getSize() : (separable.getSize() - partSum[index]);
  int ave=(remain + length - index - 2) / (length - index - 1);
  int[] allocation=new int[length - 1];
  for (int i=0; i < length - 1; i++) {
    if (i < index) {
      allocation[i]=free[i + 1];
    }
 else     if (remain > 0) {
      if (remain >= ave) {
        allocation[i]=free[index] + ave;
      }
 else {
        allocation[i]=free[index] + remain;
      }
      remain-=ave;
    }
 else {
      allocation[i]=free[index];
    }
  }
  index=0;
  List<DiskSpec> disks=new ArrayList<DiskSpec>();
  for (int i=0; i < length - 1; i++) {
    if (allocation[i] != 0) {
      DiskSpec subDisk=new DiskSpec(separable);
      subDisk.setSize(allocation[i]);
      subDisk.setSeparable(false);
      subDisk.setTargetDs(datastores.get(i).getName());
      subDisk.setName(separable.getName().split("String_Node_Str")[0] + index + "String_Node_Str");
      disks.add(subDisk);
      datastores.get(i).allocate(allocation[i]);
      index++;
    }
  }
  return disks;
}