Program: 116330
Project: 116330
Buggy source:
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        log.info("String_Node_Str" + event.getClass());
        ApplicationHolder.acquireReadLock();
        try {
          Applications applications=ApplicationHolder.getApplications();
          if (applications != null) {
            for (            Application application : applications.getApplications().values()) {
              if (allClustersInitialized(application)) {
                startApplicationMonitor(application.getUniqueIdentifier());
              }
 else {
                log.error("String_Node_Str" + "String_Node_Str");
              }
            }
            topologyInitialized=true;
          }
 else {
            log.info("String_Node_Str");
          }
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationClustersCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationClustersCreatedEvent applicationClustersCreatedEvent=(ApplicationClustersCreatedEvent)event;
        String appId=applicationClustersCreatedEvent.getAppId();
        try {
          ApplicationHolder.acquireReadLock();
          startApplicationMonitor(appId);
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
 catch (      ClassCastException e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String clusterId=clusterActivatedEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterResetEvent clusterResetEvent=(ClusterResetEvent)event;
      String clusterId=clusterResetEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.destroy();
      monitor.setStatus(ClusterStatus.Created);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInactivateEvent clusterInactivateEvent=(ClusterInactivateEvent)event;
      String clusterId=clusterInactivateEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Inactive);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatingEvent clusterTerminatingEvent=(ClusterTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      if (monitor.getStatus() == ClusterStatus.Active) {
        monitor.setStatus(ClusterStatus.Terminating);
        InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId);
      }
 else {
        monitor.setStatus(ClusterStatus.Terminating);
        monitor.terminateAllMembers();
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatedEvent clusterTerminatedEvent=(ClusterTerminatedEvent)event;
      String clusterId=clusterTerminatedEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Terminated);
      monitor.destroy();
      AutoscalerContext.getInstance().removeClusterMonitor(clusterId);
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberTerminatedEvent memberTerminatedEvent=(MemberTerminatedEvent)event;
        String clusterId=memberTerminatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberTerminatedEvent(memberTerminatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        String clusterId=memberActivatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberActivatedEvent(memberActivatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberMaintenanceModeEvent maintenanceModeEvent=(MemberMaintenanceModeEvent)event;
        String clusterId=maintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberMaintenanceModeEvent(maintenanceModeEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
}

Fixed version (ground truth):
private void addEventListeners(){
  topologyEventReceiver.addEventListener(new CompleteTopologyEventListener(){
    @Override protected void onEvent(    Event event){
      if (!topologyInitialized) {
        log.info("String_Node_Str" + event.getClass());
        ApplicationHolder.acquireReadLock();
        try {
          Applications applications=ApplicationHolder.getApplications();
          if (applications != null) {
            for (            Application application : applications.getApplications().values()) {
              if (allClustersInitialized(application)) {
                startApplicationMonitor(application.getUniqueIdentifier());
              }
 else {
                log.error("String_Node_Str" + "String_Node_Str");
              }
            }
            topologyInitialized=true;
          }
 else {
            log.info("String_Node_Str");
          }
        }
 catch (        Exception e) {
          log.error("String_Node_Str",e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ApplicationClustersCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        log.info("String_Node_Str" + event.getClass());
        ApplicationClustersCreatedEvent applicationClustersCreatedEvent=(ApplicationClustersCreatedEvent)event;
        String appId=applicationClustersCreatedEvent.getAppId();
        try {
          ApplicationHolder.acquireReadLock();
          startApplicationMonitor(appId);
        }
 catch (        Exception e) {
          String msg="String_Node_Str" + e.getLocalizedMessage();
          log.error(msg,e);
        }
 finally {
          ApplicationHolder.releaseReadLock();
        }
      }
 catch (      ClassCastException e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterActivatedEvent clusterActivatedEvent=(ClusterActivatedEvent)event;
      String clusterId=clusterActivatedEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Active);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterResetEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterResetEvent clusterResetEvent=(ClusterResetEvent)event;
      String clusterId=clusterResetEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.destroy();
      monitor.setStatus(ClusterStatus.Created);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterCreatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterInActivateEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterInactivateEvent clusterInactivateEvent=(ClusterInactivateEvent)event;
      String clusterId=clusterInactivateEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Inactive);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatingEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatingEvent clusterTerminatingEvent=(ClusterTerminatingEvent)event;
      String clusterId=clusterTerminatingEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      if (monitor.getStatus() == ClusterStatus.Active) {
        monitor.setStatus(ClusterStatus.Terminating);
        InstanceNotificationPublisher.sendInstanceCleanupEventForCluster(clusterId);
      }
 else {
        monitor.setStatus(ClusterStatus.Terminating);
        monitor.terminateAllMembers();
      }
      StatusChecker.getInstance().onMemberTermination(clusterId);
    }
  }
);
  topologyEventReceiver.addEventListener(new ClusterTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      log.info("String_Node_Str" + event.getClass());
      ClusterTerminatedEvent clusterTerminatedEvent=(ClusterTerminatedEvent)event;
      String clusterId=clusterTerminatedEvent.getClusterId();
      AutoscalerContext asCtx=AutoscalerContext.getInstance();
      AbstractClusterMonitor monitor;
      monitor=asCtx.getClusterMonitor(clusterId);
      if (null == monitor) {
        if (log.isDebugEnabled()) {
          log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
        }
        return;
      }
      monitor.setStatus(ClusterStatus.Terminated);
      monitor.destroy();
      AutoscalerContext.getInstance().removeClusterMonitor(clusterId);
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberReadyToShutdownEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberReadyToShutdownEvent memberReadyToShutdownEvent=(MemberReadyToShutdownEvent)event;
        String clusterId=memberReadyToShutdownEvent.getClusterId();
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        AbstractClusterMonitor monitor;
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberReadyToShutdownEvent(memberReadyToShutdownEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberStartedEventListener(){
    @Override protected void onEvent(    Event event){
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberTerminatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberTerminatedEvent memberTerminatedEvent=(MemberTerminatedEvent)event;
        String clusterId=memberTerminatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberTerminatedEvent(memberTerminatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberActivatedEventListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberActivatedEvent memberActivatedEvent=(MemberActivatedEvent)event;
        String clusterId=memberActivatedEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberActivatedEvent(memberActivatedEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
  topologyEventReceiver.addEventListener(new MemberMaintenanceListener(){
    @Override protected void onEvent(    Event event){
      try {
        MemberMaintenanceModeEvent maintenanceModeEvent=(MemberMaintenanceModeEvent)event;
        String clusterId=maintenanceModeEvent.getClusterId();
        AbstractClusterMonitor monitor;
        AutoscalerContext asCtx=AutoscalerContext.getInstance();
        monitor=asCtx.getClusterMonitor(clusterId);
        if (null == monitor) {
          if (log.isDebugEnabled()) {
            log.debug(String.format("String_Node_Str" + "String_Node_Str",clusterId));
          }
          return;
        }
        monitor.handleMemberMaintenanceModeEvent(maintenanceModeEvent);
      }
 catch (      Exception e) {
        String msg="String_Node_Str" + e.getLocalizedMessage();
        log.error(msg,e);
      }
    }
  }
);
}