Program: 116580
Project: 116580
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        if (!topologyInitialized) {
          topologyInitialized=true;
          TopologyManager.acquireReadLock();
          for (          Application application : TopologyManager.getTopology().getApplications()) {
            startApplicationMonitor(application);
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationCreatedEvent applicationCreatedEvent=(ApplicationCreatedEvent)event;
      TopologyManager.acquireReadLock();
      try {
        startApplicationMonitor(applicationCreatedEvent.getApplication());
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String appId=clusterActivatedEvent.getAppId();
      String clusterId=clusterActivatedEvent.getClusterId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      Monitor monitor=appMonitor.findParentMonitorOfCluster(clusterId);
      monitor.notify();
      StatusChecker.getInstance().onClusterStatusChange(clusterId,appId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationRemovedEvent applicationCreatedEvent=(ApplicationRemovedEvent)event;
      TopologyManager.acquireReadLock();
      try {
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        String memberId=memberReadyToShutdownEvent.getMemberId();
        if (asCtx.monitorExist(clusterId)) {
          monitor=asCtx.getMonitor(clusterId);
        }
 else         if (asCtx.lbMonitorExist(clusterId)) {
          monitor=asCtx.getLBMonitor(clusterId);
        }
 else {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        NetworkPartitionContext nwPartitionCtxt;
        nwPartitionCtxt=monitor.getNetworkPartitionCtxt(memberReadyToShutdownEvent.getNetworkPartitionId());
        String partitionId=monitor.getPartitionOfMember(memberId);
        PartitionContext partitionCtxt=nwPartitionCtxt.getPartitionCtxt(partitionId);
        CloudControllerClient ccClient=CloudControllerClient.getInstance();
        ccClient.terminate(memberId);
        partitionCtxt.removeActiveMemberById(memberId);
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId,partitionId,clusterId));
        }
      }
 catch (      TerminationException e) {
        log.error(e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterMaintenanceModeEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event);
        ClusterMaintenanceModeEvent e=(ClusterMaintenanceModeEvent)event;
        TopologyManager.acquireReadLock();
        Service service=TopologyManager.getTopology().getService(e.getServiceName());
        Cluster cluster=service.getCluster(e.getClusterId());
        if (AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getMonitor(e.getClusterId()).setStatus(e.getStatus());
        }
 else         if (AutoscalerContext.getInstance().lbMonitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getLBMonitor(e.getClusterId()).setStatus(e.getStatus());
        }
 else {
          log.error("String_Node_Str" + cluster.toString());
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterRemovedEvent e=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLock();
        String clusterId=e.getClusterId();
        String deploymentPolicy=e.getDeploymentPolicy();
        AbstractClusterMonitor monitor;
        if (e.isLbCluster()) {
          DeploymentPolicy depPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicy);
          if (depPolicy != null) {
            List<NetworkPartitionLbHolder> lbHolders=PartitionManager.getInstance().getNetworkPartitionLbHolders(depPolicy);
            for (            NetworkPartitionLbHolder networkPartitionLbHolder : lbHolders) {
              boolean isRemoved=networkPartitionLbHolder.removeLbClusterId(clusterId);
              if (isRemoved) {
                log.info("String_Node_Str" + clusterId + "String_Node_Str"+ networkPartitionLbHolder.getNetworkPartitionId());
              }
              if (log.isDebugEnabled()) {
                log.debug(networkPartitionLbHolder);
              }
            }
          }
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        if (monitor != null) {
          monitor.destroy();
          log.info(String.format("String_Node_Str",clusterId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.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();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        String memberId=e.getMemberId();
        partitionContext.removeMemberStatsContext(memberId);
        if (partitionContext.removeTerminationPendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removePendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removeActiveMemberById(memberId)) {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
 else {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent e=(MemberActivatedEvent)event;
        String memberId=e.getMemberId();
        PartitionContext partitionContext=null;
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
      }
 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 e=(MemberMaintenanceModeEvent)event;
        String memberId=e.getMemberId();
        String partitionId=e.getPartitionId();
        String networkPartitionId=e.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=e.getClusterId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(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.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
}

Fixed version (ground truth):
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        if (!topologyInitialized) {
          topologyInitialized=true;
          for (          Application application : TopologyManager.getTopology().getApplications()) {
            startApplicationMonitor(application);
          }
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationCreatedEvent applicationCreatedEvent=(ApplicationCreatedEvent)event;
      TopologyManager.acquireReadLock();
      try {
        startApplicationMonitor(applicationCreatedEvent.getApplication());
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String appId=clusterActivatedEvent.getAppId();
      String clusterId=clusterActivatedEvent.getClusterId();
      ApplicationMonitor appMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
      Monitor monitor=appMonitor.findParentMonitorOfCluster(clusterId);
      monitor.notify();
      StatusChecker.getInstance().onClusterStatusChange(clusterId,appId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ApplicationRemovedEvent applicationCreatedEvent=(ApplicationRemovedEvent)event;
      TopologyManager.acquireReadLock();
      try {
      }
  finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        String memberId=memberReadyToShutdownEvent.getMemberId();
        if (asCtx.monitorExist(clusterId)) {
          monitor=asCtx.getMonitor(clusterId);
        }
 else         if (asCtx.lbMonitorExist(clusterId)) {
          monitor=asCtx.getLBMonitor(clusterId);
        }
 else {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        NetworkPartitionContext nwPartitionCtxt;
        nwPartitionCtxt=monitor.getNetworkPartitionCtxt(memberReadyToShutdownEvent.getNetworkPartitionId());
        String partitionId=monitor.getPartitionOfMember(memberId);
        PartitionContext partitionCtxt=nwPartitionCtxt.getPartitionCtxt(partitionId);
        CloudControllerClient ccClient=CloudControllerClient.getInstance();
        ccClient.terminate(memberId);
        partitionCtxt.removeActiveMemberById(memberId);
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId,partitionId,clusterId));
        }
      }
 catch (      TerminationException e) {
        log.error(e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterMaintenanceModeEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event);
        ClusterMaintenanceModeEvent e=(ClusterMaintenanceModeEvent)event;
        TopologyManager.acquireReadLock();
        Service service=TopologyManager.getTopology().getService(e.getServiceName());
        Cluster cluster=service.getCluster(e.getClusterId());
        if (AutoscalerContext.getInstance().monitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getMonitor(e.getClusterId()).setStatus(e.getStatus());
        }
 else         if (AutoscalerContext.getInstance().lbMonitorExist((cluster.getClusterId()))) {
          AutoscalerContext.getInstance().getLBMonitor(e.getClusterId()).setStatus(e.getStatus());
        }
 else {
          log.error("String_Node_Str" + cluster.toString());
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterRemovedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        ClusterRemovedEvent e=(ClusterRemovedEvent)event;
        TopologyManager.acquireReadLock();
        String clusterId=e.getClusterId();
        String deploymentPolicy=e.getDeploymentPolicy();
        AbstractClusterMonitor monitor;
        if (e.isLbCluster()) {
          DeploymentPolicy depPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicy);
          if (depPolicy != null) {
            List<NetworkPartitionLbHolder> lbHolders=PartitionManager.getInstance().getNetworkPartitionLbHolders(depPolicy);
            for (            NetworkPartitionLbHolder networkPartitionLbHolder : lbHolders) {
              boolean isRemoved=networkPartitionLbHolder.removeLbClusterId(clusterId);
              if (isRemoved) {
                log.info("String_Node_Str" + clusterId + "String_Node_Str"+ networkPartitionLbHolder.getNetworkPartitionId());
              }
              if (log.isDebugEnabled()) {
                log.debug(networkPartitionLbHolder);
              }
            }
          }
          monitor=AutoscalerContext.getInstance().removeLbMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().removeMonitor(clusterId);
        }
        if (monitor != null) {
          monitor.destroy();
          log.info(String.format("String_Node_Str",clusterId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.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();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(clusterId)) {
          monitor=AutoscalerContext.getInstance().getMonitor(clusterId);
        }
 else {
          monitor=AutoscalerContext.getInstance().getLBMonitor(clusterId);
        }
        NetworkPartitionContext networkPartitionContext=monitor.getNetworkPartitionCtxt(networkPartitionId);
        PartitionContext partitionContext=networkPartitionContext.getPartitionCtxt(partitionId);
        String memberId=e.getMemberId();
        partitionContext.removeMemberStatsContext(memberId);
        if (partitionContext.removeTerminationPendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removePendingMember(memberId)) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
          }
        }
 else         if (partitionContext.removeActiveMemberById(memberId)) {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
 else {
          log.warn(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        TopologyManager.acquireReadLock();
        MemberActivatedEvent e=(MemberActivatedEvent)event;
        String memberId=e.getMemberId();
        PartitionContext partitionContext=null;
        partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
        if (log.isInfoEnabled()) {
          log.info(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.movePendingMemberToActiveMembers(memberId);
      }
 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 e=(MemberMaintenanceModeEvent)event;
        String memberId=e.getMemberId();
        String partitionId=e.getPartitionId();
        String networkPartitionId=e.getNetworkPartitionId();
        PartitionContext partitionContext;
        String clusterId=e.getClusterId();
        AbstractClusterMonitor monitor;
        if (AutoscalerContext.getInstance().monitorExist(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.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",memberId));
        }
        partitionContext.moveActiveMemberToTerminationPendingMembers(memberId);
      }
 catch (      Exception e) {
        log.error("String_Node_Str",e);
      }
 finally {
        TopologyManager.releaseReadLock();
      }
    }
  }
);
}