Program: 37473
Project: 37473
Buggy source:
/** 
 * zhuamdeMacBook-Pro:logs zhuam$ [2018-05-28 15:26:41,394] INFO [Admin Manager on Broker 0]:  Error processing create topic request for topic test01 with arguments (numPartitions=3, replicationFactor=2, replicasAssignments={}, configs={}) (kafka.server.AdminManager) org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 2 larger than available brokers: 1.
 */
private void initializeOfKafka(Map<String,TopicCfg> topicCfgMap) throws Exception {
  if (topicCfgMap == null || topicCfgMap.isEmpty()) {
    return;
  }
  StringBuffer servers=new StringBuffer();
  List<String> nodes=this.getNodes();
  for (int i=0; i < nodes.size(); i++) {
    String str=nodes.get(i);
    String[] node=str.split("String_Node_Str");
    servers.append(node[0]).append("String_Node_Str").append(node[1]);
    if (i < nodes.size() - 1) {
      servers.append("String_Node_Str");
    }
  }
  KafkaAdmin kafkaAdmin=null;
  try {
    kafkaAdmin=KafkaAdmin.create(servers.toString());
    Map<String,TopicDescription> remoteTopics=kafkaAdmin.getTopicAndDescriptions();
    Collection<Node> clusterNodes=kafkaAdmin.getClusterNodes();
    for (    TopicCfg topicCfg : topicCfgMap.values()) {
      String topicName=topicCfg.getName();
      short replicationFactor=topicCfg.getReplicationFactor();
      int partitionNum=topicCfg.getPartitions();
      TopicDescription topicDescription=remoteTopics.get(topicName);
      if (topicDescription != null) {
        int oldPartitionNum=topicDescription.partitions().size();
        if (partitionNum > oldPartitionNum) {
          kafkaAdmin.addPartitionsForTopic(topicName,partitionNum);
          topicDescription=kafkaAdmin.getDescriptionByTopicName(topicName);
        }
      }
 else {
        if (clusterNodes == null || replicationFactor > clusterNodes.size()) {
          throw new Exception("String_Node_Str" + topicName + "String_Node_Str");
        }
        kafkaAdmin.createTopic(topicName,partitionNum,replicationFactor);
        topicDescription=kafkaAdmin.getDescriptionByTopicName(topicName);
      }
      if (topicDescription == null) {
        throw new Exception("String_Node_Str" + topicName + "String_Node_Str");
      }
      String name=topicDescription.name();
      boolean internal=topicDescription.isInternal();
      int partitionSize=topicDescription.partitions().size();
      BrokerPartition[] newPartitions=new BrokerPartition[partitionSize];
      for (int i=0; i < partitionSize; i++) {
        TopicPartitionInfo partitionInfo=topicDescription.partitions().get(i);
        int partition=partitionInfo.partition();
        Node leader=partitionInfo.leader();
        BrokerNode newLeader=new BrokerNode(leader.id(),leader.host(),leader.port());
        List<Node> replicas=partitionInfo.replicas();
        BrokerNode[] newReplicas=new BrokerNode[replicas.size()];
        for (int j=0; j < replicas.size(); j++) {
          newReplicas[j]=new BrokerNode(replicas.get(j).id(),replicas.get(j).host(),replicas.get(j).port());
        }
        BrokerPartition newPartition=new BrokerPartition(partition,newLeader,newReplicas);
        newPartitions[i]=newPartition;
      }
      topicCfg.setRunningInfo(new BrokerRunningInfo(name,internal,newPartitions));
    }
  }
 catch (  Throwable e) {
    throw e;
  }
 finally {
    if (kafkaAdmin != null)     kafkaAdmin.close();
  }
}

Fixed version (ground truth):
/** 
 * zhuamdeMacBook-Pro:logs zhuam$ [2018-05-28 15:26:41,394] INFO [Admin Manager on Broker 0]:  Error processing create topic request for topic test01 with arguments (numPartitions=3, replicationFactor=2, replicasAssignments={}, configs={}) (kafka.server.AdminManager) org.apache.kafka.common.errors.InvalidReplicationFactorException: Replication factor: 2 larger than available brokers: 1.
 */
private void initializeOfKafka(Map<String,TopicCfg> topicCfgMap) throws Exception, org.apache.kafka.common.errors.TimeoutException {
  if (topicCfgMap == null || topicCfgMap.isEmpty()) {
    return;
  }
  StringBuffer servers=new StringBuffer();
  List<String> nodes=this.getNodes();
  for (int i=0; i < nodes.size(); i++) {
    String str=nodes.get(i);
    String[] node=str.split("String_Node_Str");
    servers.append(node[0]).append("String_Node_Str").append(node[1]);
    if (i < nodes.size() - 1) {
      servers.append("String_Node_Str");
    }
  }
  KafkaAdmin kafkaAdmin=null;
  try {
    kafkaAdmin=KafkaAdmin.create(servers.toString());
    Map<String,TopicDescription> remoteTopics=kafkaAdmin.getTopicAndDescriptions();
    Collection<Node> clusterNodes=kafkaAdmin.getClusterNodes();
    for (    TopicCfg topicCfg : topicCfgMap.values()) {
      String topicName=topicCfg.getName();
      short replicationFactor=topicCfg.getReplicationFactor();
      int partitionNum=topicCfg.getPartitions();
      TopicDescription topicDescription=remoteTopics.get(topicName);
      if (topicDescription != null) {
        int oldPartitionNum=topicDescription.partitions().size();
        if (partitionNum > oldPartitionNum) {
          kafkaAdmin.addPartitionsForTopic(topicName,partitionNum);
          topicDescription=kafkaAdmin.getDescriptionByTopicName(topicName);
        }
      }
 else {
        if (clusterNodes == null || replicationFactor > clusterNodes.size()) {
          throw new Exception("String_Node_Str" + topicName + "String_Node_Str");
        }
        kafkaAdmin.createTopic(topicName,partitionNum,replicationFactor);
        topicDescription=kafkaAdmin.getDescriptionByTopicName(topicName);
      }
      if (topicDescription == null) {
        throw new Exception("String_Node_Str" + topicName + "String_Node_Str");
      }
      String name=topicDescription.name();
      boolean internal=topicDescription.isInternal();
      int partitionSize=topicDescription.partitions().size();
      BrokerPartition[] newPartitions=new BrokerPartition[partitionSize];
      for (int i=0; i < partitionSize; i++) {
        TopicPartitionInfo partitionInfo=topicDescription.partitions().get(i);
        int partition=partitionInfo.partition();
        Node leader=partitionInfo.leader();
        BrokerNode newLeader=new BrokerNode(leader.id(),leader.host(),leader.port());
        List<Node> replicas=partitionInfo.replicas();
        BrokerNode[] newReplicas=new BrokerNode[replicas.size()];
        for (int j=0; j < replicas.size(); j++) {
          newReplicas[j]=new BrokerNode(replicas.get(j).id(),replicas.get(j).host(),replicas.get(j).port());
        }
        BrokerPartition newPartition=new BrokerPartition(partition,newLeader,newReplicas);
        newPartitions[i]=newPartition;
      }
      topicCfg.setRunningInfo(new BrokerRunningInfo(name,internal,newPartitions));
    }
  }
 catch (  Throwable e) {
    throw new Exception("String_Node_Str" + servers.toString(),e);
  }
 finally {
    if (kafkaAdmin != null)     kafkaAdmin.close();
  }
}