Program: 116607
Project: 116607
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    private boolean initialized;
    @Override protected void onEvent(    Event event){
      if (!initialized) {
        try {
          TopologyManager.acquireReadLock();
          for (          Service service : TopologyManager.getTopology().getServices()) {
            for (            Cluster cluster : service.getClusters()) {
              if (clusterHasActiveMembers(cluster)) {
                LoadBalancerContextUtil.addClusterAgainstHostNames(cluster);
              }
 else {
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str");
                }
              }
            }
          }
          initialized=true;
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          TopologyManager.releaseReadLock();
        }
      }
    }
    private boolean clusterHasActiveMembers(    Cluster cluster){
      for (      Member member : cluster.getMembers()) {
        if (member.getStatus() == MemberStatus.Activated) {
          return true;
        }
      }
      return false;
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        if (LoadBalancerContext.getInstance().getClusterIdClusterMap().containsCluster(memberActivatedEvent.getClusterId())) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId()));
          }
          return;
        }
        Service service=TopologyManager.getTopology().getService(memberActivatedEvent.getServiceName());
        if (service != null) {
          Cluster cluster=service.getCluster(memberActivatedEvent.getClusterId());
          if (cluster != null) {
            LoadBalancerContextUtil.addClusterAgainstHostNames(cluster);
          }
 else {
            if (log.isErrorEnabled()) {
              log.error(String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId()));
            }
          }
        }
 else {
          if (log.isErrorEnabled()) {
            log.error(String.format("String_Node_Str",memberActivatedEvent.getServiceName()));
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        ClusterRemovedEvent clusterRemovedEvent=(ClusterRemovedEvent)event;
        Cluster cluster=LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterRemovedEvent.getClusterId());
        if (cluster != null) {
          LoadBalancerContextUtil.removeClusterAgainstHostNames(cluster.getClusterId());
        }
 else {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId()));
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ServiceRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        ServiceRemovedEvent serviceRemovedEvent=(ServiceRemovedEvent)event;
        Service service=TopologyManager.getTopology().getService(serviceRemovedEvent.getServiceName());
        if (service != null) {
          for (          Cluster cluster : service.getClusters()) {
            LoadBalancerContextUtil.removeClusterAgainstHostNames(cluster.getClusterId());
          }
        }
 else {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",serviceRemovedEvent.getServiceName()));
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
}

Fixed version (ground truth):
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    private boolean initialized;
    @Override protected void onEvent(    Event event){
      if (!initialized) {
        try {
          TopologyManager.acquireReadLock();
          for (          Service service : TopologyManager.getTopology().getServices()) {
            for (            Cluster cluster : service.getClusters()) {
              if (clusterHasActiveMembers(cluster)) {
                LoadBalancerContextUtil.addClusterAgainstHostNames(cluster);
              }
 else {
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str");
                }
              }
              for (              Member member : cluster.getMembers()) {
                if (member.getStatus() == MemberStatus.Activated) {
                  addMemberIpsToMemberIpHostnameMap(cluster,member);
                }
              }
            }
          }
          initialized=true;
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          TopologyManager.releaseReadLock();
        }
      }
    }
    private boolean clusterHasActiveMembers(    Cluster cluster){
      for (      Member member : cluster.getMembers()) {
        if (member.getStatus() == MemberStatus.Activated) {
          return true;
        }
      }
      return false;
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        Service service=TopologyManager.getTopology().getService(memberActivatedEvent.getServiceName());
        if (service == null) {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",memberActivatedEvent.getServiceName()));
          }
          return;
        }
        Cluster cluster=service.getCluster(memberActivatedEvent.getClusterId());
        if (cluster == null) {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId()));
          }
          return;
        }
        Member member=cluster.getMember(memberActivatedEvent.getMemberId());
        if (member == null) {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",memberActivatedEvent.getServiceName(),memberActivatedEvent.getClusterId(),memberActivatedEvent.getMemberId()));
          }
          return;
        }
        addMemberIpsToMemberIpHostnameMap(cluster,member);
        if (LoadBalancerContext.getInstance().getClusterIdClusterMap().containsCluster(member.getClusterId())) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",member.getServiceName(),member.getClusterId()));
          }
          return;
        }
        LoadBalancerContextUtil.addClusterAgainstHostNames(cluster);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberMaintenanceModeEvent memberMaintenanceModeEvent=(MemberMaintenanceModeEvent)event;
        Member member=findMember(memberMaintenanceModeEvent.getServiceName(),memberMaintenanceModeEvent.getClusterId(),memberMaintenanceModeEvent.getMemberId());
        if (member != null) {
          removeMemberIpsFromMemberIpHostnameMap(member);
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberSuspendedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberSuspendedEvent memberSuspendedEvent=(MemberSuspendedEvent)event;
        Member member=findMember(memberSuspendedEvent.getServiceName(),memberSuspendedEvent.getClusterId(),memberSuspendedEvent.getMemberId());
        if (member != null) {
          removeMemberIpsFromMemberIpHostnameMap(member);
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberTerminatedEvent memberTerminatedEvent=(MemberTerminatedEvent)event;
        Member member=findMember(memberTerminatedEvent.getServiceName(),memberTerminatedEvent.getClusterId(),memberTerminatedEvent.getMemberId());
        if (member != null) {
          removeMemberIpsFromMemberIpHostnameMap(member);
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        ClusterRemovedEvent clusterRemovedEvent=(ClusterRemovedEvent)event;
        Cluster cluster=LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterRemovedEvent.getClusterId());
        if (cluster != null) {
          for (          Member member : cluster.getMembers()) {
            removeMemberIpsFromMemberIpHostnameMap(member);
          }
          LoadBalancerContextUtil.removeClusterAgainstHostNames(cluster.getClusterId());
        }
 else {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",clusterRemovedEvent.getServiceName(),clusterRemovedEvent.getClusterId()));
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ServiceRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        ServiceRemovedEvent serviceRemovedEvent=(ServiceRemovedEvent)event;
        Service service=TopologyManager.getTopology().getService(serviceRemovedEvent.getServiceName());
        if (service != null) {
          for (          Cluster cluster : service.getClusters()) {
            for (            Member member : cluster.getMembers()) {
              removeMemberIpsFromMemberIpHostnameMap(member);
            }
            LoadBalancerContextUtil.removeClusterAgainstHostNames(cluster.getClusterId());
          }
        }
 else {
          if (log.isWarnEnabled()) {
            log.warn(String.format("String_Node_Str",serviceRemovedEvent.getServiceName()));
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
}