Program: 8167
Project: 8167
Buggy source:
protected ZKLoadRebalanceListener registerConsumerInternal(final ZKLoadRebalanceListener loadBalanceListener) throws UnknownHostException, InterruptedException, Exception {
  final ZKGroupDirs dirs=this.metaZookeeper.new ZKGroupDirs(loadBalanceListener.consumerConfig.getGroup());
  final String topicString=this.getTopicsString(loadBalanceListener.topicSubcriberRegistry);
  if (this.zkClient == null) {
    loadBalanceListener.fetchManager.stopFetchRunner();
    loadBalanceListener.fetchManager.resetFetchState();
    for (    final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
      final SubscriberInfo subInfo=loadBalanceListener.topicSubcriberRegistry.get(topic);
      ConcurrentHashMap<Partition,TopicPartitionRegInfo> topicPartRegInfoMap=loadBalanceListener.topicRegistry.get(topic);
      if (topicPartRegInfoMap == null) {
        topicPartRegInfoMap=new ConcurrentHashMap<Partition,TopicPartitionRegInfo>();
        loadBalanceListener.topicRegistry.put(topic,topicPartRegInfoMap);
      }
      final Partition partition=new Partition(loadBalanceListener.consumerConfig.getPartition());
      final long offset=loadBalanceListener.consumerConfig.getOffset();
      final TopicPartitionRegInfo regInfo=new TopicPartitionRegInfo(topic,partition,offset);
      topicPartRegInfoMap.put(partition,regInfo);
      loadBalanceListener.fetchManager.addFetchRequest(new FetchRequest(new Broker(0,loadBalanceListener.consumerConfig.getServerUrl()),0L,regInfo,subInfo.getMaxSize()));
    }
    loadBalanceListener.fetchManager.startFetchRunner();
  }
 else {
    ZkUtils.createEphemeralPathExpectConflict(this.zkClient,dirs.consumerRegistryDir + "String_Node_Str" + loadBalanceListener.consumerIdString,topicString);
    this.zkClient.subscribeChildChanges(dirs.consumerRegistryDir,loadBalanceListener);
    for (    final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
      final String partitionPath=this.metaZookeeper.brokerTopicsPath + "String_Node_Str" + topic;
      ZkUtils.makeSurePersistentPathExists(this.zkClient,partitionPath);
      this.zkClient.subscribeChildChanges(partitionPath,loadBalanceListener);
    }
    this.zkClient.subscribeStateChanges(new ZKSessionExpireListenner(loadBalanceListener));
    loadBalanceListener.syncedRebalance();
  }
  return loadBalanceListener;
}

Fixed version (ground truth):
protected ZKLoadRebalanceListener registerConsumerInternal(final ZKLoadRebalanceListener loadBalanceListener) throws UnknownHostException, InterruptedException, Exception {
  final ZKGroupDirs dirs=this.metaZookeeper.new ZKGroupDirs(loadBalanceListener.consumerConfig.getGroup());
  final String topicString=this.getTopicsString(loadBalanceListener.topicSubcriberRegistry);
  if (this.zkClient == null) {
    loadBalanceListener.fetchManager.stopFetchRunner();
    loadBalanceListener.fetchManager.resetFetchState();
    for (    final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
      final SubscriberInfo subInfo=loadBalanceListener.topicSubcriberRegistry.get(topic);
      ConcurrentHashMap<Partition,TopicPartitionRegInfo> topicPartRegInfoMap=loadBalanceListener.topicRegistry.get(topic);
      if (topicPartRegInfoMap == null) {
        topicPartRegInfoMap=new ConcurrentHashMap<Partition,TopicPartitionRegInfo>();
        loadBalanceListener.topicRegistry.put(topic,topicPartRegInfoMap);
      }
      final Partition partition=new Partition(loadBalanceListener.consumerConfig.getPartition());
      final long offset=loadBalanceListener.consumerConfig.getOffset();
      final TopicPartitionRegInfo regInfo=new TopicPartitionRegInfo(topic,partition,offset);
      topicPartRegInfoMap.put(partition,regInfo);
      loadBalanceListener.fetchManager.addFetchRequest(new FetchRequest(new Broker(0,loadBalanceListener.consumerConfig.getServerUrl()),0L,regInfo,subInfo.getMaxSize()));
    }
    loadBalanceListener.fetchManager.startFetchRunner();
  }
 else {
    ZkUtils.createEphemeralPathExpectConflict(this.zkClient,dirs.consumerRegistryDir + "String_Node_Str" + loadBalanceListener.consumerIdString,topicString);
    this.zkClient.subscribeChildChanges(dirs.consumerRegistryDir,loadBalanceListener);
    for (    final String topic : loadBalanceListener.topicSubcriberRegistry.keySet()) {
      final String partitionPath=this.metaZookeeper.brokerTopicsSubPath + "String_Node_Str" + topic;
      ZkUtils.makeSurePersistentPathExists(this.zkClient,partitionPath);
      this.zkClient.subscribeChildChanges(partitionPath,loadBalanceListener);
    }
    this.zkClient.subscribeStateChanges(new ZKSessionExpireListenner(loadBalanceListener));
    loadBalanceListener.syncedRebalance();
  }
  return loadBalanceListener;
}