Program: 25578
Project: 25578
Buggy source:
private void cloneCollection(final DBCollection fromCollection,final DBCollection toCollection) throws IllegalArgumentException {
  LOG.debug("String_Node_Str",fromCollection.count(),fromCollection.getFullName(),toCollection.getFullName());
  final ProcessTimer timer=new ProcessTimer(15000);
  final int maxDocumentsPerBulkInsert=10000;
  long count=0;
  final DBObject query=new BasicDBObject();
  BulkWriteOperation bulk=toCollection.initializeUnorderedBulkOperation();
  try (DBCursor cursor=fromCollection.find(query)){
    DBObject document;
    while (cursor.hasNext()) {
      document=cursor.next();
      count++;
      if (count % maxDocumentsPerBulkInsert == 0) {
        bulk.execute();
        bulk=toCollection.initializeUnorderedBulkOperation();
        if (timer.hasIntervalPassed()) {
          LOG.debug("String_Node_Str",count);
        }
      }
 else {
        bulk.insert(document);
      }
    }
    if (count % maxDocumentsPerBulkInsert > 0) {
      bulk.execute();
    }
  }
   LOG.debug("String_Node_Str",count,fromCollection.getFullName(),toCollection.getFullName());
}

Fixed version (ground truth):
private void cloneCollection(final DBCollection fromCollection,final DBCollection toCollection) throws IllegalStateException {
  final long fromCount=fromCollection.count();
  long toCount;
  final String fromFullName=fromCollection.getFullName();
  final String toFullName=toCollection.getFullName();
  LOG.debug("String_Node_Str",fromCount,fromFullName,toFullName);
  final ProcessTimer timer=new ProcessTimer(15000);
  final int maxDocumentsPerBulkInsert=10000;
  long count=0;
  final DBObject query=new BasicDBObject();
  BulkWriteOperation bulk=toCollection.initializeOrderedBulkOperation();
  try (DBCursor cursor=fromCollection.find(query)){
    BulkWriteResult result;
    long insertedCount;
    DBObject document;
    while (cursor.hasNext()) {
      document=cursor.next();
      bulk.insert(document);
      count++;
      if (count % maxDocumentsPerBulkInsert == 0) {
        result=bulk.execute(WriteConcern.ACKNOWLEDGED);
        insertedCount=result.getInsertedCount();
        if (insertedCount != maxDocumentsPerBulkInsert) {
          throw new IllegalStateException("String_Node_Str" + insertedCount + "String_Node_Str"+ maxDocumentsPerBulkInsert+ "String_Node_Str"+ count);
        }
        bulk=toCollection.initializeOrderedBulkOperation();
        if (timer.hasIntervalPassed()) {
          LOG.debug("String_Node_Str",count);
        }
      }
    }
    if (count % maxDocumentsPerBulkInsert > 0) {
      result=bulk.execute(WriteConcern.ACKNOWLEDGED);
      insertedCount=result.getInsertedCount();
      final long expectedCount=count % maxDocumentsPerBulkInsert;
      if (insertedCount != expectedCount) {
        throw new IllegalStateException("String_Node_Str" + insertedCount + "String_Node_Str"+ expectedCount+ "String_Node_Str"+ count);
      }
    }
    toCount=toCollection.count();
    if (toCount != fromCount) {
      throw new IllegalStateException("String_Node_Str" + toCount + "String_Node_Str"+ fromCount+ "String_Node_Str");
    }
  }
   LOG.debug("String_Node_Str",toCount,fromFullName,toFullName);
}