Buggy code:
public class VariantMongoDBWriter extends VariantDBWriter { public static final int CHUNK_SIZE_SMALL = 1000 ; public static final int CHUNK_SIZE_BIG = 10000 ; protected static Logger logger = LoggerFactory . getLogger ( VariantDBWriter . class ) ; private final VariantSource source ; private MongoCredentials credentials ; private MongoDataStore mongoDataStore ; private MongoDataStoreManager mongoDataStoreManager ; private MongoDBCollection variantMongoCollection ; private MongoDBCollection filesMongoCollection ; private String filesCollectionName ; private String variantsCollectionName ; @ Deprecated private MongoClient mongoClient ; @ Deprecated private DB db ; @ Deprecated private DBCollection filesCollection ; @ Deprecated private DBCollection variantsCollection ; @ Deprecated private Map < String , DBObject > mongoMap ; @ Deprecated private Map < String , DBObject > mongoFileMap ; private boolean includeStats ; @ Deprecated private boolean includeEffect ; private boolean includeSrc = true ; private boolean includeSamples ; private boolean compressDefaultGenotype = true ; private String defaultGenotype = null ; private Map < String , Integer > samplesIds ; @ Deprecated private List < String > samples ; @ Deprecated private Map < String , Integer > conseqTypes ; private DBObjectToVariantConverter variantConverter ; private DBObjectToVariantStatsConverter statsConverter ; private DBObjectToVariantSourceConverter sourceConverter ; private DBObjectToVariantSourceEntryConverter sourceEntryConverter ; private DBObjectToSamplesConverter sampleConverter ; private long numVariantsWritten ; private BulkWriteOperation bulk ; private int currentBulkSize = 0 ; private int bulkSize = 0 ; private long checkExistsTime = 0 ; private long checkExistsDBTime = 0 ; private long bulkTime = 0 ; public VariantMongoDBWriter ( final VariantSource source , MongoCredentials credentials ) { } public VariantMongoDBWriter ( final VariantSource source , MongoCredentials credentials , String variantsCollection , String filesCollection ) { } public VariantMongoDBWriter ( final VariantSource source , MongoCredentials credentials , String variantsCollection , String filesCollection , boolean includeSamples , boolean includeStats , @ Deprecated boolean includeEffect ) { } @ Override public boolean open ( ) { } @ Override public boolean pre ( ) { } @ Override public boolean write ( Variant variant ) { } @ Override public boolean write ( List < Variant > data ) { } @ Deprecated public boolean write_old ( List < Variant > data ) { } public boolean write_updateInsert ( List < Variant > data ) { } public boolean write_setOnInsert ( List < Variant > data ) { numVariantsWritten += data . size ( ) ; if ( ( ( numVariantsWritten ) % 1000 ) == 0 ) { VariantMongoDBWriter . logger . info ( ( "Num<seq2seq4repair_space>variants<seq2seq4repair_space>written<seq2seq4repair_space>" + ( numVariantsWritten ) ) ) ; } for ( Variant variant : data ) { variant . setAnnotation ( null ) ; String id = variantConverter . buildStorageId ( variant ) ; for ( VariantSourceEntry variantSourceEntry : variant . getSourceEntries ( ) . values ( ) ) { if ( ! ( variantSourceEntry . getFileId ( ) . equals ( source . getFileId ( ) ) ) ) { continue ; } <START_BUG> BasicDBObject update = new BasicDBObject ( ) . append ( "$push" , new BasicDBObject ( DBObjectToVariantConverter . FILES_FIELD , sourceEntryConverter . convertToStorageType ( variantSourceEntry ) ) ) . append ( "$setOnInsert" , variantConverter . convertToStorageType ( variant ) ) ; <END_BUG> if ( ( ( variant . getIds ( ) ) != null ) && ( ! ( variant . getIds ( ) . isEmpty ( ) ) ) ) { update . append ( "$addToSet" , new BasicDBObject ( DBObjectToVariantConverter . IDS_FIELD , new BasicDBObject ( "$each" , variant . getIds ( ) ) ) ) ; } bulk . find ( new BasicDBObject ( "_id" , id ) ) . upsert ( ) . updateOne ( update ) ; ( currentBulkSize ) ++ ; } } if ( ( currentBulkSize ) >= ( bulkSize ) ) { executeBulk ( ) ; } return true ; } @ Override @ Deprecated protected boolean buildBatchRaw ( List < Variant > data ) { } @ Override @ Deprecated protected boolean buildEffectRaw ( List < Variant > variants ) { } @ Deprecated private BasicDBObject getVariantEffectDBObject ( VariantEffect effect ) { } @ Override @ Deprecated protected boolean buildBatchIndex ( List < Variant > data ) { } @ Override @ Deprecated protected boolean writeBatch ( List < Variant > batch ) { } private boolean writeSourceSummary ( VariantSource source ) { } @ Override public boolean post ( ) { } @ Override public boolean close ( ) { } @ Override public final void includeStats ( boolean b ) { } public final void includeSrc ( boolean b ) { } @ Override public final void includeSamples ( boolean b ) { } @ Override @ Deprecated public final void includeEffect ( boolean b ) { } public void setCompressDefaultGenotype ( boolean compressDefaultGenotype ) { } public void setDefaultGenotype ( String defaultGenotype ) { } private void setConverters ( ) { } @ Deprecated private void addConsequenceType ( VariantEffect effect ) { } public void setBulkSize ( int bulkSize ) { } public void setSamplesIds ( Map < String , Integer > samplesIds ) { } private void executeBulk ( ) { } private void resetBulk ( ) { } }

Fix:
BasicDBObject update = new BasicDBObject ( ) . append ( "$addToSet" , new BasicDBObject ( DBObjectToVariantConverter . FILES_FIELD , sourceEntryConverter . convertToStorageType ( variantSourceEntry ) ) ) . append ( "$setOnInsert" , variantConverter . convertToStorageType ( variant ) ) ;