Buggy code:
public class FeatureTokenSpanFnDataVocabTrie < D extends Datum < L > , L > extends FeatureTokenSpanFnDataVocab < D , L > { private Trie < String , Double > forwardTrie ; private Trie < String , Double > backwardTrie ; public FeatureTokenSpanFnDataVocabTrie ( ) { } public FeatureTokenSpanFnDataVocabTrie ( Context < D , L > context ) { } @ Override public boolean init ( FeaturizedDataSet < D , L > dataSet ) { final CounterTable < String > counter = new CounterTable < String > ( ) ; if ( ( this . initMode ) == ( InitMode . BY_DATUM ) ) { dataSet . map ( new Fn < D , Boolean > ( ) { @ Override public Boolean apply ( D datum ) { Map < String , Integer > gramsForDatum = applyFnToDatum ( datum ) ; for ( String gram : gramsForDatum . keySet ( ) ) { counter . incrementCount ( gram ) ; } return true ; } } ) ; } else { final java . util . Map < String , Set < String > > gramsToDocuments = new ConcurrentHashMap < String , Set < String > > ( ) ; dataSet . map ( new Fn < D , Boolean > ( ) { @ Override public Boolean apply ( D datum ) { Map < String , Integer > gramsForDatum = applyFnToDatum ( datum ) ; String documentName = FeatureTokenSpanFnDataVocabTrie . this . tokenExtractor . extract ( datum ) [ 0 ] . getDocument ( ) . getName ( ) ; for ( String gram : gramsForDatum . keySet ( ) ) { synchronized ( this ) { <START_BUG> if ( ! ( gramsToDocuments . containsKey ( gram ) ) ) ; <END_BUG> gramsToDocuments . put ( gram , new HashSet < String > ( ) ) ; gramsToDocuments . get ( gram ) . add ( documentName ) ; } } return true ; } } ) ; for ( java . util . Map . Entry < String , Set < String > > entry : gramsToDocuments . entrySet ( ) ) { counter . incrementCount ( entry . getKey ( ) , entry . getValue ( ) . size ( ) ) ; } } counter . removeCountsLessThan ( this . minFeatureOccurrence ) ; this . vocabulary = new edu . cmu . ml . rtw . generic . util . BidirectionalLookupTable < String , Integer > ( counter . buildIndex ( ) ) ; java . util . Map < String , Integer > counts = counter . getCounts ( ) ; double N = dataSet . size ( ) ; for ( java . util . Map . Entry < String , Integer > entry : counts . entrySet ( ) ) { int id = this . vocabulary . get ( entry . getKey ( ) ) ; double idf = Math . log ( ( N // ( 1.0 + ( entry . getValue ( ) ) ) ) ) ; this . idfs . put ( id , idf ) ; this . forwardTrie . put ( entry . getKey ( ) , idf ) ; this . backwardTrie . put ( new StringBuilder ( entry . getKey ( ) ) . reverse ( ) . toString ( ) , idf ) ; } return true ; } @ Override protected < T extends Datum < Boolean > > Feature < T , Boolean > makeBinaryHelper ( Context < T , Boolean > context , LabelIndicator < L > labelIndicator , Feature < T , Boolean > binaryFeature ) { } @ Override protected boolean cloneHelper ( Feature < D , L > clone ) { } @ Override protected boolean fromParseInternalHelper ( AssignmentList internalAssignments ) { } @ Override public Feature < D , L > makeInstance ( Context < D , L > context ) { } @ Override public String getGenericName ( ) { } public Set < String > getVocabularyTermsPrefixedBy ( String prefix ) { } public Set < String > getVocabularyTermsSuffixedBy ( String suffix ) { } }

Fix:
if ( ! ( gramsToDocuments . containsKey ( gram ) ) )