Program: 37647
Project: 37647
Buggy source:
/** 
 * This method handles when a partition seek/retrieve request was out of bounds. This happens in two scenarios: 1 - The offset is too old and was cleaned up / removed by the broker. 2 - The offset just plain does not exist. This is particularly nasty in that if the poll() was able to pull SOME messages from SOME partitions before the exception was thrown, those messages are considered "consumed" by KafkaClient, and there's no way to get them w/o seeking back to them for those partitions. This means when we roll back, we may replay some messages :/
 * @param outOfRangeException The exception that was raised by the consumer.
 */
private void handleOffsetOutOfRange(OffsetOutOfRangeException outOfRangeException){
  final Set<TopicPartition> outOfRangePartitions=outOfRangeException.partitions();
  Set<ConsumerPartition> allAssignedPartitions=getAssignedPartitions();
  for (  ConsumerPartition assignedConsumerPartition : allAssignedPartitions) {
    final TopicPartition assignedTopicPartition=new TopicPartition(assignedConsumerPartition.namespace(),assignedConsumerPartition.partition());
    if (outOfRangePartitions.contains(assignedTopicPartition)) {
      final long offset=outOfRangeException.offsetOutOfRangePartitions().get(assignedTopicPartition);
      logger.error("String_Node_Str",offset,assignedConsumerPartition);
      continue;
    }
    final long offset=partitionOffsetsManager.getLastStartedOffset(assignedConsumerPartition);
    logger.info("String_Node_Str",assignedConsumerPartition,offset);
    getKafkaConsumer().seek(assignedTopicPartition,offset);
  }
  resetPartitionsToEarliest(outOfRangePartitions);
}

Fixed version (ground truth):
/** 
 * This method handles when a partition seek/retrieve request was out of bounds. This happens in two scenarios: 1 - The offset is too old and was cleaned up / removed by the broker. 2 - The offset just plain does not exist. This is particularly nasty in that if the poll() was able to pull SOME messages from SOME partitions before the exception was thrown, those messages are considered "consumed" by KafkaClient, and there's no way to get them w/o seeking back to them for those partitions. This means when we roll back, we may replay some messages :/
 * @param outOfRangeException The exception that was raised by the consumer.
 */
private void handleOffsetOutOfRange(OffsetOutOfRangeException outOfRangeException){
  final Set<TopicPartition> outOfRangePartitions=outOfRangeException.partitions();
  Set<ConsumerPartition> allAssignedPartitions=getAssignedPartitions();
  for (  ConsumerPartition assignedConsumerPartition : allAssignedPartitions) {
    final TopicPartition assignedTopicPartition=new TopicPartition(assignedConsumerPartition.namespace(),assignedConsumerPartition.partition());
    if (outOfRangePartitions.contains(assignedTopicPartition)) {
      final long offset=outOfRangeException.offsetOutOfRangePartitions().get(assignedTopicPartition);
      logger.error("String_Node_Str",offset,assignedConsumerPartition);
      continue;
    }
    final long offset=partitionOffsetsManager.getLastStartedOffset(assignedConsumerPartition);
    if (offset == -1) {
      logger.info("String_Node_Str",assignedConsumerPartition,offset);
      resetPartitionsToEarliest(Collections.singletonList(assignedTopicPartition));
    }
 else {
      logger.info("String_Node_Str",assignedConsumerPartition,offset);
      getKafkaConsumer().seek(assignedTopicPartition,offset);
    }
  }
  resetPartitionsToEarliest(outOfRangePartitions);
}