Buggy code:
public class KafkaUtils { public static final Logger LOG = LoggerFactory . getLogger ( KafkaUtils . class ) ; private static final int NO_OFFSET = - 5 ; public static IBrokerReader makeBrokerReader ( Map stormConf , KafkaConfig conf ) { } public static long getOffset ( SimpleConsumer consumer , String topic , int partition , KafkaConfig config ) { } public static long getOffset ( SimpleConsumer consumer , String topic , int partition , long startOffsetTime ) { } public static class KafkaOffsetMetric implements IMetric { Map < Partition , Long > _partitionToOffset = new HashMap < Partition , Long > ( ) ; Set < Partition > _partitions ; String _topic ; DynamicPartitionConnections _connections ; public KafkaOffsetMetric ( String topic , DynamicPartitionConnections connections ) { } public void setLatestEmittedOffset ( Partition partition , long offset ) { } @ Override public Object getValueAndReset ( ) { try { long totalSpoutLag = 0 ; long totalEarliestTimeOffset = 0 ; long totalLatestTimeOffset = 0 ; long totalLatestEmittedOffset = 0 ; HashMap ret = new HashMap ( ) ; if ( ( ( _partitions ) != null ) && ( ( _partitions . size ( ) ) == ( _partitionToOffset . size ( ) ) ) ) { for ( Map . Entry < Partition , Long > e : _partitionToOffset . entrySet ( ) ) { Partition partition = e . getKey ( ) ; SimpleConsumer consumer = _connections . getConnection ( partition ) ; if ( consumer == null ) { KafkaUtils . LOG . warn ( "partitionToOffset<seq2seq4repair_space>contains<seq2seq4repair_space>partition<seq2seq4repair_space>not<seq2seq4repair_space>found<seq2seq4repair_space>in<seq2seq4repair_space>_connections.<seq2seq4repair_space>Stale<seq2seq4repair_space>partition<seq2seq4repair_space>data?" ) ; return null ; } long latestTimeOffset = KafkaUtils . getOffset ( consumer , _topic , partition . partition , OffsetRequest . LatestTime ( ) ) ; long earliestTimeOffset = KafkaUtils . getOffset ( consumer , _topic , partition . partition , OffsetRequest . EarliestTime ( ) ) ; <START_BUG> if ( latestTimeOffset == 0 ) { <END_BUG> KafkaUtils . LOG . warn ( ( "No<seq2seq4repair_space>data<seq2seq4repair_space>found<seq2seq4repair_space>in<seq2seq4repair_space>Kafka<seq2seq4repair_space>Partition<seq2seq4repair_space>" + ( partition . getId ( ) ) ) ) ; return null ; } long latestEmittedOffset = e . getValue ( ) ; long spoutLag = latestTimeOffset - latestEmittedOffset ; ret . put ( ( ( ( partition . getId ( ) ) + "//" ) + "spoutLag" ) , spoutLag ) ; ret . put ( ( ( ( partition . getId ( ) ) + "//" ) + "earliestTimeOffset" ) , earliestTimeOffset ) ; ret . put ( ( ( ( partition . getId ( ) ) + "//" ) + "latestTimeOffset" ) , latestTimeOffset ) ; ret . put ( ( ( ( partition . getId ( ) ) + "//" ) + "latestEmittedOffset" ) , latestEmittedOffset ) ; totalSpoutLag += spoutLag ; totalEarliestTimeOffset += earliestTimeOffset ; totalLatestTimeOffset += latestTimeOffset ; totalLatestEmittedOffset += latestEmittedOffset ; } ret . put ( "totalSpoutLag" , totalSpoutLag ) ; ret . put ( "totalEarliestTimeOffset" , totalEarliestTimeOffset ) ; ret . put ( "totalLatestTimeOffset" , totalLatestTimeOffset ) ; ret . put ( "totalLatestEmittedOffset" , totalLatestEmittedOffset ) ; return ret ; } else { KafkaUtils . LOG . info ( "Metrics<seq2seq4repair_space>Tick:<seq2seq4repair_space>Not<seq2seq4repair_space>enough<seq2seq4repair_space>data<seq2seq4repair_space>to<seq2seq4repair_space>calculate<seq2seq4repair_space>spout<seq2seq4repair_space>lag." ) ; } } catch ( Throwable t ) { KafkaUtils . LOG . warn ( "Metrics<seq2seq4repair_space>Tick:<seq2seq4repair_space>Exception<seq2seq4repair_space>when<seq2seq4repair_space>computing<seq2seq4repair_space>kafkaOffset<seq2seq4repair_space>metric." , t ) ; } return null ; } public void refreshPartitions ( Set < Partition > partitions ) { } } public static ByteBufferMessageSet fetchMessages ( KafkaConfig config , SimpleConsumer consumer , Partition partition , long offset ) { } public static Iterable < List < Object > > generateTuples ( KafkaConfig kafkaConfig , Message msg ) { } public static List < Partition > calculatePartitionsForTask ( GlobalPartitionInformation partitionInformation , int totalTasks , int taskIndex ) { } private static void logPartitionMapping ( int totalTasks , int taskIndex , List < Partition > taskPartitions ) { } public static String taskId ( int taskIndex , int totalTasks ) { } }

Fix:
if ( ( latestTimeOffset == 0 ) || ( earliestTimeOffset == 0 ) ) {