Buggy code:
public class FeatureTokenSpanFnDataVocab < D extends Datum < L > , L > extends Feature < D , L > { public enum Scale { INDICATOR , NORMALIZED_LOG , NORMALIZED_TFIDF ; } public enum InitMode { BY_DATUM , BY_DOCUMENT ; } protected BidirectionalLookupTable < String , Integer > vocabulary ; protected Map < Integer , Double > idfs ; protected int minFeatureOccurrence ; protected TokenSpanExtractor < D , L > tokenExtractor ; protected FeatureTokenSpanFnDataVocab . Scale scale ; protected Fn < TokenSpan , String > fn ; protected FeatureTokenSpanFnDataVocab . InitMode initMode ; protected String [ ] parameterNames = new String [ ] { "minFeatureOccurrence" , "tokenExtractor" , "scale" , "fn" , "initMode" } ; public FeatureTokenSpanFnDataVocab ( ) { } public FeatureTokenSpanFnDataVocab ( Context < D , L > context ) { } @ Override public boolean init ( FeaturizedDataSet < D , L > dataSet ) { final CounterTable < String > counter = new CounterTable < String > ( ) ; if ( ( this . initMode ) == ( FeatureTokenSpanFnDataVocab . InitMode . BY_DATUM ) ) { dataSet . map ( new ThreadMapper . 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 Map < String , Set < String > > gramsToDocuments = new ConcurrentHashMap < String , Set < String > > ( ) ; dataSet . map ( new ThreadMapper . Fn < D , Boolean > ( ) { @ Override public Boolean apply ( D datum ) { Map < String , Integer > gramsForDatum = applyFnToDatum ( datum ) ; String documentName = FeatureTokenSpanFnDataVocab . 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 ( Map . Entry < String , Set < String > > entry : gramsToDocuments . entrySet ( ) ) { counter . incrementCount ( entry . getKey ( ) , entry . getValue ( ) . size ( ) ) ; } } counter . removeCountsLessThan ( this . minFeatureOccurrence ) ; this . vocabulary = new BidirectionalLookupTable < String , Integer > ( counter . buildIndex ( ) ) ; Map < String , Integer > counts = counter . getCounts ( ) ; double N = dataSet . size ( ) ; for ( Map . Entry < String , Integer > entry : counts . entrySet ( ) ) { this . idfs . put ( this . vocabulary . get ( entry . getKey ( ) ) , Math . log ( ( N // ( 1.0 + ( entry . getValue ( ) ) ) ) ) ) ; } return true ; } public Map < String , Integer > applyFnToDatum ( D datum ) { } public FeatureTokenSpanFnDataVocab . Scale getScale ( ) { } @ Override public Map < Integer , Double > computeVector ( D datum , int offset , Map < Integer , Double > vector ) { } public Integer getVocabularyIndex ( String term ) { } @ Override public String getVocabularyTerm ( int index ) { } @ Override protected boolean setVocabularyTerm ( int index , String term ) { } @ Override public int getVocabularySize ( ) { } @ Override public String [ ] getParameterNames ( ) { } @ Override public Obj getParameterValue ( String parameter ) { } @ Override public boolean setParameterValue ( String parameter , Obj parameterValue ) { } @ Override protected < T extends Datum < Boolean > > Feature < T , Boolean > makeBinaryHelper ( Context < T , Boolean > context , LabelIndicator < L > labelIndicator , Feature < T , Boolean > binaryFeature ) { } @ Override protected boolean fromParseInternalHelper ( AssignmentList internalAssignments ) { } @ Override protected AssignmentList toParseInternalHelper ( AssignmentList internalAssignments ) { } @ Override public Feature < D , L > makeInstance ( Context < D , L > context ) { } @ Override public String getGenericName ( ) { } @ Override protected boolean cloneHelper ( Feature < D , L > clone ) { } }

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