Buggy code:
public class KafkaSpout extends BaseRichSpout { public static class ZooMeta implements Serializable { String id ; long offset ; public ZooMeta ( ) { } public ZooMeta ( String id , long offset ) { } } public static class MessageAndRealOffset { public Message msg ; public long offset ; public MessageAndRealOffset ( Message msg , long offset ) { } } static enum EmitState { EMITTED_MORE_LEFT , EMITTED_END , NO_EMITTED ; } public static final Logger LOG = Logger . getLogger ( KafkaSpout . class ) ; static class KafkaMessageId { public int partition ; public long offset ; public KafkaMessageId ( int partition , long offset ) { } } protected class PartitionManager { Long _emittedToOffset ; SortedSet < Long > _pending = new TreeSet < Long > ( ) ; Long _committedTo ; int _partition ; LinkedList < KafkaSpout . MessageAndRealOffset > _waitingToEmit = new LinkedList < KafkaSpout . MessageAndRealOffset > ( ) ; public PartitionManager ( int partition ) { } public KafkaSpout . EmitState next ( ) { } private void fill ( ) { } public void ack ( Long offset ) { } public void fail ( Long offset ) { } public void commit ( ) { } private String committedPath ( ) { } } String _uuid = UUID . randomUUID ( ) . toString ( ) ; SpoutConfig _spoutConfig ; SpoutOutputCollector _collector ; TransactionalState _state ; KafkaPartitionConnections _partitions ; Map < Integer , KafkaSpout . PartitionManager > _managers = new HashMap < Integer , KafkaSpout . PartitionManager > ( ) ; long _lastUpdateMs = 0 ; int _currPartitionIndex = 0 ; List < Integer > _managedPartitions = new ArrayList < Integer > ( ) ; public KafkaSpout ( SpoutConfig spoutConf ) { } @ Override public void open ( Map conf , TopologyContext context , SpoutOutputCollector collector ) { _collector = collector ; Map stateConf = new HashMap ( conf ) ; List < String > zkServers = _spoutConfig . zkServers ; if ( zkServers == null ) zkServers = ( ( List < String > ) ( conf . get ( STORM_ZOOKEEPER_SERVERS ) ) ) ; Integer zkPort = _spoutConfig . zkPort ; if ( zkPort == null ) zkPort = ( ( Number ) ( conf . get ( STORM_ZOOKEEPER_PORT ) ) ) . intValue ( ) ; String zkRoot = _spoutConfig . zkRoot ; stateConf . put ( TRANSACTIONAL_ZOOKEEPER_SERVERS , zkServers ) ; stateConf . put ( TRANSACTIONAL_ZOOKEEPER_PORT , zkPort ) ; stateConf . put ( TRANSACTIONAL_ZOOKEEPER_ROOT , zkRoot ) ; Config componentConf = new Config ( ) ; componentConf . registerSerialization ( KafkaSpout . ZooMeta . class ) ; _state = TransactionalState . newUserState ( stateConf , _spoutConfig . id , componentConf ) ; if ( ( _spoutConfig . hosts ) == null ) { _partitions = new ZkKafkaPartitionConnections ( _spoutConfig ) ; } else { _partitions = new KafkaPartitionConnections ( _spoutConfig ) ; } <START_BUG> int totalPartitions = ( _spoutConfig . partitionsPerHost ) * ( _spoutConfig . hosts . size ( ) ) ; <END_BUG> int numTasks = context . getComponentTasks ( context . getThisComponentId ( ) ) . size ( ) ; for ( int p = context . getThisTaskIndex ( ) ; p < totalPartitions ; p += numTasks ) { _managedPartitions . add ( p ) ; _managers . put ( p , new KafkaSpout . PartitionManager ( p ) ) ; } } @ Override public void nextTuple ( ) { } @ Override public void ack ( Object msgId ) { } @ Override public void fail ( Object msgId ) { } @ Override public void deactivate ( ) { } @ Override public void declareOutputFields ( OutputFieldsDeclarer declarer ) { } private void commit ( ) { } public static void main ( String [ ] args ) { } }

Fix:
int totalPartitions = ( _spoutConfig . partitionsPerHost ) * ( _partitions . getNumberOfHosts ( ) ) ;