Program: 49713
Project: 49713
Buggy source:
private void finalizeArrangement(PartitionInfo[] currentState,PartitionInfo[] newState,int replicaCount,List<MigrationRequestTask> scheduledTasksList,List<MigrationRequestTask> immediateTasksList){
  final int partitionCount=currentState.length;
  final List<MigrationRequestTask> partitionMigrationTasks=new LinkedList<MigrationRequestTask>();
  for (int partitionId=0; partitionId < partitionCount; partitionId++) {
    PartitionInfo currentPartition=currentState[partitionId];
    PartitionInfo newPartition=newState[partitionId];
    boolean lost=false;
    for (int replicaIndex=0; replicaIndex < PartitionInfo.MAX_REPLICA_COUNT; replicaIndex++) {
      Address currentOwner=currentPartition.getReplicaAddress(replicaIndex);
      Address newOwner=newPartition.getReplicaAddress(replicaIndex);
      MigrationRequestTask migrationRequestTask=null;
      if (currentOwner != null && newOwner != null && !currentOwner.equals(newOwner)) {
        migrationRequestTask=new MigrationRequestTask(partitionId,currentOwner,newOwner,replicaIndex,true);
      }
 else       if (currentOwner == null && newOwner != null) {
        if ((currentOwner=currentPartition.getOwner()) == null) {
          lost=true;
        }
        boolean selfCopy=false;
        ListIterator<MigrationRequestTask> iter=partitionMigrationTasks.listIterator(partitionMigrationTasks.size());
        while (iter.hasPrevious()) {
          MigrationRequestTask task=iter.previous();
          if (newOwner.equals(task.getFromAddress())) {
            selfCopy=true;
            task.setSelfCopyReplicaIndex(replicaIndex);
            break;
          }
        }
        if (!selfCopy) {
          migrationRequestTask=new MigrationRequestTask(partitionId,currentOwner,newOwner,replicaIndex,false);
        }
      }
 else       if (currentOwner != null && newOwner == null) {
        logger.log(Level.WARNING,"String_Node_Str" + "String_Node_Str" + partitionId + "String_Node_Str"+ replicaIndex+ "String_Node_Str"+ currentOwner);
        immediateTasksList.add(new MigrationRequestTask(partitionId,currentOwner,null,replicaIndex,false));
      }
      if (migrationRequestTask != null) {
        partitionMigrationTasks.add(migrationRequestTask);
        boolean immediate=false;
        if (replicaIndex == 0 && currentPartition.getOwner() != null && currentPartition.getOwner().equals(newPartition.getReplicaAddress(1))) {
          immediate=true;
        }
 else         if (replicaIndex == 1 && currentPartition.getReplicaAddress(1) == null) {
          immediate=true;
        }
        if (immediate) {
          immediateTasksList.add(migrationRequestTask);
        }
 else {
          scheduledTasksList.add(migrationRequestTask);
        }
      }
    }
    partitionMigrationTasks.clear();
    if (lost) {
      logger.log(Level.FINEST,"String_Node_Str" + currentPartition + "String_Node_Str");
    }
  }
  arrangeScheduledTasks(scheduledTasksList);
}

Fixed version (ground truth):
private void finalizeArrangement(PartitionInfo[] currentState,PartitionInfo[] newState,List<MigrationRequestTask> lostPartitionTasksList,List<MigrationRequestTask> immediateTasksList,List<MigrationRequestTask> scheduledTasksList){
  final int partitionCount=currentState.length;
  final List<MigrationRequestTask> partitionMigrationTasks=new LinkedList<MigrationRequestTask>();
  for (int partitionId=0; partitionId < partitionCount; partitionId++) {
    PartitionInfo currentPartition=currentState[partitionId];
    PartitionInfo newPartition=newState[partitionId];
    boolean lost=false;
    for (int replicaIndex=0; replicaIndex < PartitionInfo.MAX_REPLICA_COUNT; replicaIndex++) {
      Address currentOwner=currentPartition.getReplicaAddress(replicaIndex);
      Address newOwner=newPartition.getReplicaAddress(replicaIndex);
      MigrationRequestTask migrationRequestTask=null;
      if (currentOwner != null && newOwner != null && !currentOwner.equals(newOwner)) {
        migrationRequestTask=new MigrationRequestTask(partitionId,currentOwner,newOwner,replicaIndex,true);
      }
 else       if (currentOwner == null && newOwner != null) {
        currentOwner=currentPartition.getOwner();
        boolean selfCopy=false;
        ListIterator<MigrationRequestTask> iter=partitionMigrationTasks.listIterator(partitionMigrationTasks.size());
        while (iter.hasPrevious()) {
          MigrationRequestTask task=iter.previous();
          if (newOwner.equals(task.getFromAddress())) {
            selfCopy=true;
            task.setSelfCopyReplicaIndex(replicaIndex);
            break;
          }
        }
        if (!selfCopy) {
          migrationRequestTask=new MigrationRequestTask(partitionId,currentOwner,newOwner,replicaIndex,false);
        }
      }
 else       if (currentOwner != null && newOwner == null) {
        logger.log(Level.WARNING,"String_Node_Str" + "String_Node_Str" + partitionId + "String_Node_Str"+ replicaIndex+ "String_Node_Str"+ currentOwner);
        immediateTasksList.add(new MigrationRequestTask(partitionId,currentOwner,null,replicaIndex,false));
      }
      if (migrationRequestTask != null) {
        partitionMigrationTasks.add(migrationRequestTask);
        if (replicaIndex == 0 && currentOwner == null) {
          lostPartitionTasksList.add(migrationRequestTask);
        }
 else         if (replicaIndex == 0 && currentOwner != null && currentOwner.equals(newPartition.getReplicaAddress(1))) {
          immediateTasksList.add(migrationRequestTask);
        }
 else         if (replicaIndex == 1 && currentPartition.getReplicaAddress(1) == null) {
          immediateTasksList.add(migrationRequestTask);
        }
 else {
          scheduledTasksList.add(migrationRequestTask);
        }
      }
    }
    partitionMigrationTasks.clear();
  }
  arrangeScheduledTasks(scheduledTasksList);
}