Buggy code:
public class SubtopologyBolt implements ITridentBatchBolt { DirectedGraph _graph ; Set < Node > _nodes ; Map < String , SubtopologyBolt . InitialReceiver > _roots = new HashMap ( ) ; Map < Node , Factory > _outputFactories = new HashMap ( ) ; Map < String , List < TridentProcessor > > _myTopologicallyOrdered = new HashMap ( ) ; Map < Node , String > _batchGroups ; public SubtopologyBolt ( DirectedGraph graph , Set < Node > nodes , Map < Node , String > batchGroups ) { } @ Override public void prepare ( Map conf , TopologyContext context , BatchOutputCollector batchCollector ) { int thisComponentNumTasks = context . getComponentTasks ( context . getThisComponentId ( ) ) . size ( ) ; for ( Node n : _nodes ) { if ( ( n . stateInfo ) != null ) { <START_BUG> State s = n . stateInfo . spec . stateFactory . makeState ( conf , context , context . getThisTaskIndex ( ) , thisComponentNumTasks ) ; <END_BUG> context . setTaskData ( n . stateInfo . id , s ) ; } } DirectedSubgraph < Node , Object > subgraph = new DirectedSubgraph ( _graph , _nodes , null ) ; TopologicalOrderIterator it = new TopologicalOrderIterator < Node , Object > ( subgraph ) ; int stateIndex = 0 ; while ( it . hasNext ( ) ) { Node n = ( ( Node ) ( it . next ( ) ) ) ; if ( n instanceof ProcessorNode ) { ProcessorNode pn = ( ( ProcessorNode ) ( n ) ) ; String batchGroup = _batchGroups . get ( n ) ; if ( ! ( _myTopologicallyOrdered . containsKey ( batchGroup ) ) ) { _myTopologicallyOrdered . put ( batchGroup , new ArrayList ( ) ) ; } _myTopologicallyOrdered . get ( batchGroup ) . add ( pn . processor ) ; List < String > parentStreams = new ArrayList ( ) ; List < Factory > parentFactories = new ArrayList ( ) ; for ( Node p : TridentUtils . getParents ( _graph , n ) ) { parentStreams . add ( p . streamId ) ; if ( _nodes . contains ( p ) ) { parentFactories . add ( _outputFactories . get ( p ) ) ; } else { if ( ! ( _roots . containsKey ( p . streamId ) ) ) { _roots . put ( p . streamId , new SubtopologyBolt . InitialReceiver ( p . streamId , getSourceOutputFields ( context , p . streamId ) ) ) ; } _roots . get ( p . streamId ) . addReceiver ( pn . processor ) ; parentFactories . add ( _roots . get ( p . streamId ) . getOutputFactory ( ) ) ; } } List < TupleReceiver > targets = new ArrayList ( ) ; boolean outgoingNode = false ; for ( Node cn : TridentUtils . getChildren ( _graph , n ) ) { if ( _nodes . contains ( cn ) ) { targets . add ( ( ( ProcessorNode ) ( cn ) ) . processor ) ; } else { outgoingNode = true ; } } if ( outgoingNode ) { targets . add ( new BridgeReceiver ( batchCollector ) ) ; } TridentContext triContext = new TridentContext ( pn . selfOutFields , parentFactories , parentStreams , targets , pn . streamId , stateIndex , batchCollector ) ; pn . processor . prepare ( conf , context , triContext ) ; _outputFactories . put ( n , pn . processor . getOutputFactory ( ) ) ; } stateIndex ++ ; } } private Fields getSourceOutputFields ( TopologyContext context , String sourceStream ) { } @ Override public void execute ( BatchInfo batchInfo , Tuple tuple ) { } @ Override public void finishBatch ( BatchInfo batchInfo ) { } @ Override public Object initBatchState ( String batchGroup , Object batchId ) { } @ Override public void cleanup ( ) { } @ Override public void declareOutputFields ( OutputFieldsDeclarer declarer ) { } @ Override public Map < String , Object > getComponentConfiguration ( ) { } protected class InitialReceiver { List < TridentProcessor > _receivers = new ArrayList ( ) ; RootFactory _factory ; ProjectionFactory _project ; String _stream ; public InitialReceiver ( String stream , Fields allFields ) { } public void receive ( ProcessorContext context , Tuple tuple ) { } public void addReceiver ( TridentProcessor p ) { } public Factory getOutputFactory ( ) { } } }

Fix:
State s = n . stateInfo . spec . stateFactory . makeState ( conf , context . getThisTaskIndex ( ) , thisComponentNumTasks ) ;