Program: 113502
Project: 113502
Buggy source:
/** 
 * Polls MRC regularly to discover if replication is complete. Blocks until this event happens.
 * @param fileIDList
 * @throws Exception
 */
public List<FileInformation> waitForReplicationToComplete(List<FileInformation> fileInfos) throws OSDDrainException {
  List<FileInformation> finishedFileInfos=new LinkedList<FileInformation>();
  List<FileInformation> toBeRemovedFileInfos=new LinkedList<FileInformation>();
  while (!fileInfos.isEmpty()) {
    for (    FileInformation fileInfo : fileInfos) {
      String fileID=fileInfo.fileID;
      FileCredentials fc=fileInfo.fileCredentials;
      Replica replica=fileInfo.newReplica;
      boolean isReplicated=true;
      StripingPolicyImpl sp=StripingPolicyImpl.getPolicy(replica,0);
      long lastObjectNo=sp.getObjectNoForOffset(fc.getXlocs().getReadOnlyFileSize() - 1);
      int osdRelPos=0;
      for (      String osdUUID : replica.getOsdUuidsList()) {
        RPCResponse<ObjectList> r=null;
        ObjectSet oSet=null;
        try {
          InetSocketAddress osdAddress=new ServiceUUID(osdUUID,resolver).getAddress();
          r=osdClient.xtreemfs_internal_get_object_set(osdAddress,password,userCreds,fc,fileID);
          ObjectList ol=r.get();
          byte[] serializedBitSet=ol.getSet().toByteArray();
          oSet=new ObjectSet(sp.getWidth(),osdRelPos,serializedBitSet);
        }
 catch (        Exception e) {
          if (Logging.isDebug()) {
            Logging.logError(Logging.LEVEL_WARN,this,e);
          }
          List<FileInformation> allInfos=new LinkedList<FileInformation>();
          allInfos.addAll(fileInfos);
          allInfos.addAll(finishedFileInfos);
          throw new OSDDrainException(e.getMessage(),ErrorState.WAIT_FOR_REPLICATION,finishedFileInfos,allInfos);
        }
 finally {
          if (r != null) {
            r.freeBuffers();
          }
        }
        for (long objNo=osdRelPos; objNo <= lastObjectNo; objNo+=sp.getWidth()) {
          if (oSet.contains(objNo) == false)           isReplicated=false;
        }
      }
      if (isReplicated) {
        toBeRemovedFileInfos.add(fileInfo);
        finishedFileInfos.add(fileInfo);
      }
    }
    fileInfos.removeAll(toBeRemovedFileInfos);
    toBeRemovedFileInfos.clear();
    if (fileInfos.isEmpty())     return finishedFileInfos;
    Logging.logMessage(Logging.LEVEL_INFO,Category.tool,this,"String_Node_Str");
    try {
      Thread.sleep(10000);
    }
 catch (    Exception e) {
    }
  }
  return finishedFileInfos;
}

Fixed version (ground truth):
/** 
 * Polls MRC regularly to discover if replication is complete. Blocks until this event happens.
 * @param fileIDList
 * @throws Exception
 */
public List<FileInformation> waitForReplicationToComplete(List<FileInformation> fileInfos) throws OSDDrainException {
  List<FileInformation> finishedFileInfos=new LinkedList<FileInformation>();
  List<FileInformation> toBeRemovedFileInfos=new LinkedList<FileInformation>();
  while (!fileInfos.isEmpty()) {
    for (    FileInformation fileInfo : fileInfos) {
      String fileID=fileInfo.fileID;
      FileCredentials fc=fileInfo.fileCredentials;
      Replica replica=fileInfo.newReplica;
      boolean isReplicated=true;
      StripingPolicyImpl sp=StripingPolicyImpl.getPolicy(replica,0);
      long lastObjectNo=sp.getObjectNoForOffset(fc.getXlocs().getReadOnlyFileSize() - 1);
      int osdRelPos=0;
      for (      String osdUUID : replica.getOsdUuidsList()) {
        RPCResponse<ObjectList> r=null;
        ObjectSet oSet=null;
        try {
          InetSocketAddress osdAddress=new ServiceUUID(osdUUID,resolver).getAddress();
          r=osdClient.xtreemfs_internal_get_object_set(osdAddress,password,userCreds,fc,fileID);
          ObjectList ol=r.get();
          byte[] serializedBitSet=ol.getSet().toByteArray();
          oSet=new ObjectSet(sp.getWidth(),osdRelPos,serializedBitSet);
        }
 catch (        Exception e) {
          if (Logging.isDebug()) {
            Logging.logError(Logging.LEVEL_WARN,this,e);
          }
          List<FileInformation> allInfos=new LinkedList<FileInformation>();
          allInfos.addAll(fileInfos);
          allInfos.addAll(finishedFileInfos);
          throw new OSDDrainException(e.getMessage(),ErrorState.WAIT_FOR_REPLICATION,finishedFileInfos,allInfos);
        }
 finally {
          if (r != null) {
            r.freeBuffers();
          }
        }
        for (long objNo=osdRelPos; objNo <= lastObjectNo; objNo+=sp.getWidth()) {
          if (oSet.contains(objNo) == false)           isReplicated=false;
        }
      }
      if (isReplicated) {
        toBeRemovedFileInfos.add(fileInfo);
        finishedFileInfos.add(fileInfo);
      }
    }
    fileInfos.removeAll(toBeRemovedFileInfos);
    toBeRemovedFileInfos.clear();
    if (fileInfos.isEmpty())     return finishedFileInfos;
    Logging.logMessage(Logging.LEVEL_INFO,Category.tool,this,"String_Node_Str");
    try {
      Thread.sleep(5000);
    }
 catch (    Exception e) {
    }
  }
  return finishedFileInfos;
}