Program: 116714
Project: 116714
Buggy source:
private TopologyMessageProcessorChain createEventProcessorChain(){
  TopologyMessageProcessorChain processorChain=new TopologyMessageProcessorChain();
  processorChain.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        for (        Service service : TopologyManager.getTopology().getServices()) {
          for (          Cluster cluster : service.getClusters()) {
            Thread th;
            if (cluster.isLbCluster()) {
              th=new Thread(new LBClusterMonitorAdder(cluster));
            }
 else {
              th=new Thread(new ClusterMonitorAdder(cluster));
            }
            th.start();
            if (log.isDebugEnabled()) {
              log.debug(String.format("String_Node_Str",cluster.getClusterId()));
            }
          }
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterCreatedEvent e=(ClusterCreatedEvent)event;
        TopologyManager.acquireReadLock();
        Service service=TopologyManager.getTopology().getService(e.getServiceName());
        Cluster cluster=service.getCluster(e.getClusterId());
        if (cluster.isLbCluster()) {
          Thread th=new Thread(new LBClusterMonitorAdder(cluster));
          th.start();
        }
 else {
          Thread th=new Thread(new ClusterMonitorAdder(cluster));
          th.start();
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterRemovedEvent e=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLock();
        String serviceName=e.getServiceName();
        String clusterId=e.getClusterId();
        AbstractMonitor monitor;
        if (e.isLbCluster()) {
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        monitor.destroy();
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str",clusterId));
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  processorChain.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberTerminatedEvent e=(MemberTerminatedEvent)event;
        String networkPartitionId=e.getNetworkPartitionId();
        String clusterId=e.getClusterId();
        String partitionId=e.getPartitionId();
        AbstractMonitor monitor;
        if (AutoscalerContext.getInstance().moniterExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        partitionContext.removeMemberStatsContext(e.getMemberId());
        if (!partitionContext.removeTerminationPendingMember(e.getMemberId())) {
          if (log.isErrorEnabled()) {
            log.error(String.format("String_Node_Str",e.getMemberId()));
          }
        }
 else         if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str",e.getMemberId()));
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent e=(MemberActivatedEvent)event;
        String memberId=e.getMemberId();
        String partitionId=e.getPartitionId();
        String networkPartitionId=e.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=e.getClusterId();
        AbstractMonitor monitor;
        if (AutoscalerContext.getInstance().moniterExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ServiceRemovedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  return processorChain;
}

Fixed version (ground truth):
private TopologyMessageProcessorChain createEventProcessorChain(){
  TopologyMessageProcessorChain processorChain=new TopologyMessageProcessorChain();
  processorChain.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        for (        Service service : TopologyManager.getTopology().getServices()) {
          for (          Cluster cluster : service.getClusters()) {
            Thread th;
            if (cluster.isLbCluster()) {
              th=new Thread(new LBClusterMonitorAdder(cluster));
            }
 else {
              th=new Thread(new ClusterMonitorAdder(cluster));
            }
            th.start();
            if (log.isDebugEnabled()) {
              log.debug(String.format("String_Node_Str",cluster.getClusterId()));
            }
          }
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterCreatedEvent e=(ClusterCreatedEvent)event;
        TopologyManager.acquireReadLock();
        Service service=TopologyManager.getTopology().getService(e.getServiceName());
        Cluster cluster=service.getCluster(e.getClusterId());
        if (cluster.isLbCluster()) {
          Thread th=new Thread(new LBClusterMonitorAdder(cluster));
          th.start();
        }
 else {
          Thread th=new Thread(new ClusterMonitorAdder(cluster));
          th.start();
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterRemovedEvent e=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLock();
        String serviceName=e.getServiceName();
        String clusterId=e.getClusterId();
        AbstractMonitor monitor;
        if (e.isLbCluster()) {
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        monitor.destroy();
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str",clusterId));
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  processorChain.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberTerminatedEvent e=(MemberTerminatedEvent)event;
        String networkPartitionId=e.getNetworkPartitionId();
        String clusterId=e.getClusterId();
        String partitionId=e.getPartitionId();
        AbstractMonitor monitor;
        if (AutoscalerContext.getInstance().moniterExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        partitionContext.removeMemberStatsContext(e.getMemberId());
        if (!partitionContext.removeTerminationPendingMember(e.getMemberId())) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str",e.getMemberId()));
          }
        }
 else         if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str",e.getMemberId()));
        }
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent e=(MemberActivatedEvent)event;
        String memberId=e.getMemberId();
        String partitionId=e.getPartitionId();
        String networkPartitionId=e.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=e.getClusterId();
        AbstractMonitor monitor;
        if (AutoscalerContext.getInstance().moniterExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
          partitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId).getPartitionCtxt(partitionId);
        }
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  processorChain.addEventListener(new ServiceRemovedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  return processorChain;
}