Buggy code:
public class ViperBolt extends BaseRichBolt { private static final long serialVersionUID = 8693720878488229181L ; public static Logger LOG = LoggerFactory . getLogger ( ViperBolt . class ) ; private Fields outFields ; protected OutputCollector collector ; private boolean keepStats ; private boolean statsWritten = false ; private String statsPath ; private CountStat countStat ; private AvgStat costStat ; private CountStat invocationsStat ; protected BoltFunction f ; protected int thisTaskIndex ; protected int thisTask ; protected String id ; private int counter = 0 ; private int tuples_processed_in_this_invocation = 0 ; private boolean stillNeedToConfigure = true ; TopologyContext context ; String streamId ; private boolean useInternalQueues ; private SharedChannelsScaleGate sharedChannels ; private String channelID ; public ViperBolt ( Fields outFields , BoltFunction boltFunction ) { } @ SuppressWarnings ( { "rawtypes" } ) public void prepare ( Map stormConf , TopologyContext context , OutputCollector collector ) { } @ SuppressWarnings ( "rawtypes" ) protected void childPrepare ( Map stormConf , TopologyContext context , OutputCollector collector ) { } protected void emit ( Tuple input , Values t ) { } protected void emitFlush ( Tuple t ) { } private void process ( Tuple t ) { } public Map < String , Object > getComponentConfiguration ( ) { } protected boolean isTickTuple ( Tuple tuple ) { } @ SuppressWarnings ( "unchecked" ) private void takeFromInternalBuffer ( ) { } public void execute ( Tuple input ) { if ( stillNeedToConfigure ) { ViperBolt . LOG . info ( "!!!<seq2seq4repair_space>Calling<seq2seq4repair_space>execute<seq2seq4repair_space>on<seq2seq4repair_space>a<seq2seq4repair_space>bolt<seq2seq4repair_space>that<seq2seq4repair_space>still<seq2seq4repair_space>needs<seq2seq4repair_space>to<seq2seq4repair_space>complete<seq2seq4repair_space>configuration<seq2seq4repair_space>!!!" ) ; while ( stillNeedToConfigure ) { Utils . sleep ( 100 ) ; } } long start = System . nanoTime ( ) ; if ( keepStats ) invocationsStat . increase ( 1 ) ; tuples_processed_in_this_invocation = 0 ; if ( ( useInternalQueues ) && ( isTickTuple ( input ) ) ) takeFromInternalBuffer ( ) ; if ( ! ( isTickTuple ( input ) ) ) { TupleType ttype = ( ( TupleType ) ( input . getValueByField ( "type" ) ) ) ; if ( ttype . equals ( REGULAR ) ) { process ( input ) ; } else if ( ttype . equals ( FLUSH ) ) { ViperBolt . LOG . info ( ( ( ( ( ( "ViperBolt<seq2seq4repair_space>" + ( id ) ) + "<seq2seq4repair_space>received<seq2seq4repair_space>FLUSH<seq2seq4repair_space>from<seq2seq4repair_space>" ) + ( input . getSourceComponent ( ) ) ) + ":" ) + ( input . getSourceTask ( ) ) ) ) ; List < Values > result = f . receivedFlush ( input ) ; if ( result != null ) { for ( Values t : result ) { if ( t != null ) { emit ( input , t ) ; if ( keepStats ) { countStat . increase ( 1 ) ; } } } ViperBolt . LOG . info ( ( ( ( ( "ViperBolt<seq2seq4repair_space>" + ( id ) ) + "<seq2seq4repair_space>received<seq2seq4repair_space>" ) + ( counter ) ) + "<seq2seq4repair_space>tuples<seq2seq4repair_space>before<seq2seq4repair_space>sending<seq2seq4repair_space>FLUSH" ) ) ; emitFlush ( input ) ; if ( ( keepStats ) && ( ! ( statsWritten ) ) ) { statsWritten = true ; Utils . sleep ( 2000 ) ; countStat . stopStats ( ) ; costStat . stopStats ( ) ; invocationsStat . stopStats ( ) ; countStat . writeStats ( ) ; costStat . writeStats ( ) ; invocationsStat . writeStats ( ) ; keepStats = false ; if ( this . useInternalQueues ) sharedChannels . turnOff ( ) ; } } } } <START_BUG> if ( keepStats ) { <END_BUG> costStat . add ( ( ( ( System . nanoTime ( ) ) - start ) // ( tuples_processed_in_this_invocation ) ) ) ; } } public void declareOutputFields ( OutputFieldsDeclarer declarer ) { } }

Fix:
if ( ( keepStats ) && ( ( tuples_processed_in_this_invocation ) > 0 ) ) {