Program: 115439
Project: 115439
Buggy source:
public synchronized void monitor(){
  try {
    for (    NetworkPartitionContext networkPartitionContext : getNetworkPartitionCtxts()) {
      final Collection<InstanceContext> clusterInstanceContexts=networkPartitionContext.getInstanceIdToInstanceContextMap().values();
      for (      final InstanceContext pInstanceContext : clusterInstanceContexts) {
        final ClusterInstanceContext instanceContext=(ClusterInstanceContext)pInstanceContext;
        final ClusterInstance instance=(ClusterInstance)this.instanceIdToInstanceMap.get(instanceContext.getId());
        if ((instance.getStatus().getCode() <= ClusterStatus.Active.getCode()) || (instance.getStatus() == ClusterStatus.Inactive && !hasStartupDependents) && !this.hasFaultyMember) {
          Runnable monitoringRunnable=new Runnable(){
            @Override public void run(){
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",getAppId(),getClusterId()));
              }
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              String paritionAlgo=instanceContext.getPartitionAlgorithm();
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
              instanceContext.setMinCheckFactHandle(evaluate(instanceContext.getMinCheckKnowledgeSession(),instanceContext.getMinCheckFactHandle(),instanceContext));
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
              instanceContext.setMaxCheckFactHandle(evaluate(instanceContext.getMaxCheckKnowledgeSession(),instanceContext.getMaxCheckFactHandle(),instanceContext));
              boolean rifReset=instanceContext.isRifReset();
              boolean memoryConsumptionReset=instanceContext.isMemoryConsumptionReset();
              boolean loadAverageReset=instanceContext.isLoadAverageReset();
              boolean averageRequestServedPerInstanceReset=instanceContext.isAverageRequestServedPerInstanceReset();
              if (rifReset || memoryConsumptionReset || loadAverageReset) {
                ClusterContext clusterContext=ClusterMonitor.this.clusterContext;
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",getAppId());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",rifReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",memoryConsumptionReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",loadAverageReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",clusterContext.getAutoscalePolicy());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",averageRequestServedPerInstanceReset);
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str" + rifReset + "String_Node_Str"+ "String_Node_Str"+ memoryConsumptionReset+ "String_Node_Str"+ "String_Node_Str"+ loadAverageReset+ "String_Node_Str"+ "String_Node_Str"+ clusterId+ "String_Node_Str"+ "String_Node_Str"+ instanceContext.getId());
                }
                instanceContext.setScaleCheckFactHandle(evaluate(instanceContext.getScaleCheckKnowledgeSession(),instanceContext.getScaleCheckFactHandle(),instanceContext));
                instanceContext.setRifReset(false);
                instanceContext.setMemoryConsumptionReset(false);
                instanceContext.setLoadAverageReset(false);
              }
 else               if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
            }
          }
;
          executorService.execute(monitoringRunnable);
        }
        if (instance.getStatus() == ClusterStatus.Terminating) {
          if (instanceContext.getActiveMembers() > 0) {
            InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForCluster(clusterId,instance.getInstanceId());
            moveMembersToTerminatingPending(networkPartitionContext.getId(),instance.getInstanceId());
          }
          if (instanceContext.getPendingMemberCount() > 0) {
            terminatePendingMembers(networkPartitionContext.getId(),instance.getInstanceId());
          }
        }
        for (        final ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
          Runnable monitoringRunnable=new Runnable(){
            @Override public void run(){
              instanceContext.getObsoleteCheckKnowledgeSession().setGlobal("String_Node_Str",clusterId);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",partitionContext.getPartitionId(),instanceContext.getId(),clusterId));
              }
              instanceContext.setObsoleteCheckFactHandle(evaluate(instanceContext.getObsoleteCheckKnowledgeSession(),instanceContext.getObsoleteCheckFactHandle(),partitionContext));
              if (partitionContext.isObsoletePartition() && partitionContext.getTerminationPendingMembers().size() == 0 && partitionContext.getObsoletedMembers().size() == 0) {
                instanceContext.removePartitionCtxt(partitionContext.getPartition().getId());
              }
            }
          }
;
          executorService.execute(monitoringRunnable);
        }
      }
    }
  }
 catch (  RejectedExecutionException ignore) {
    log.warn("String_Node_Str" + getClusterId());
  }
}

Fixed version (ground truth):
public synchronized void monitor(){
  try {
    for (    NetworkPartitionContext networkPartitionContext : getNetworkPartitionCtxts()) {
      final Collection<InstanceContext> clusterInstanceContexts=networkPartitionContext.getInstanceIdToInstanceContextMap().values();
      for (      final InstanceContext pInstanceContext : clusterInstanceContexts) {
        final ClusterInstanceContext instanceContext=(ClusterInstanceContext)pInstanceContext;
        final ClusterInstance instance=(ClusterInstance)this.instanceIdToInstanceMap.get(instanceContext.getId());
        if ((instance.getStatus().getCode() <= ClusterStatus.Active.getCode()) || (instance.getStatus() == ClusterStatus.Inactive && !hasStartupDependents) && !this.hasFaultyMember) {
          Runnable monitoringRunnable=new Runnable(){
            @Override public void run(){
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",getAppId(),getClusterId()));
              }
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              String paritionAlgo=instanceContext.getPartitionAlgorithm();
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",scalingDecisionPublisher);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
              instanceContext.setMinCheckFactHandle(evaluate(instanceContext.getMinCheckKnowledgeSession(),instanceContext.getMinCheckFactHandle(),instanceContext));
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
              instanceContext.setMaxCheckFactHandle(evaluate(instanceContext.getMaxCheckKnowledgeSession(),instanceContext.getMaxCheckFactHandle(),instanceContext));
              boolean rifReset=instanceContext.isRifReset();
              boolean memoryConsumptionReset=instanceContext.isMemoryConsumptionReset();
              boolean loadAverageReset=instanceContext.isLoadAverageReset();
              boolean averageRequestServedPerInstanceReset=instanceContext.isAverageRequestServedPerInstanceReset();
              if (rifReset || memoryConsumptionReset || loadAverageReset) {
                ClusterContext clusterContext=ClusterMonitor.this.clusterContext;
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",getAppId());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",rifReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",memoryConsumptionReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",loadAverageReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",clusterContext.getAutoscalePolicy());
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",averageRequestServedPerInstanceReset);
                instanceContext.getScaleCheckKnowledgeSession().setGlobal("String_Node_Str",scalingDecisionPublisher);
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str" + rifReset + "String_Node_Str"+ "String_Node_Str"+ memoryConsumptionReset+ "String_Node_Str"+ "String_Node_Str"+ loadAverageReset+ "String_Node_Str"+ "String_Node_Str"+ clusterId+ "String_Node_Str"+ "String_Node_Str"+ instanceContext.getId());
                }
                instanceContext.setScaleCheckFactHandle(evaluate(instanceContext.getScaleCheckKnowledgeSession(),instanceContext.getScaleCheckFactHandle(),instanceContext));
                instanceContext.setRifReset(false);
                instanceContext.setMemoryConsumptionReset(false);
                instanceContext.setLoadAverageReset(false);
              }
 else               if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",instanceContext.getId(),clusterId));
              }
            }
          }
;
          executorService.execute(monitoringRunnable);
        }
        if (instance.getStatus() == ClusterStatus.Terminating) {
          if (instanceContext.getActiveMembers() > 0) {
            InstanceNotificationPublisher.getInstance().sendInstanceCleanupEventForCluster(clusterId,instance.getInstanceId());
            moveMembersToTerminatingPending(networkPartitionContext.getId(),instance.getInstanceId());
          }
          if (instanceContext.getPendingMemberCount() > 0) {
            terminatePendingMembers(networkPartitionContext.getId(),instance.getInstanceId());
          }
        }
        for (        final ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
          Runnable monitoringRunnable=new Runnable(){
            @Override public void run(){
              instanceContext.getObsoleteCheckKnowledgeSession().setGlobal("String_Node_Str",clusterId);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str" + "String_Node_Str",partitionContext.getPartitionId(),instanceContext.getId(),clusterId));
              }
              instanceContext.setObsoleteCheckFactHandle(evaluate(instanceContext.getObsoleteCheckKnowledgeSession(),instanceContext.getObsoleteCheckFactHandle(),partitionContext));
              if (partitionContext.isObsoletePartition() && partitionContext.getTerminationPendingMembers().size() == 0 && partitionContext.getObsoletedMembers().size() == 0) {
                instanceContext.removePartitionCtxt(partitionContext.getPartition().getId());
              }
            }
          }
;
          executorService.execute(monitoringRunnable);
        }
      }
    }
  }
 catch (  RejectedExecutionException ignore) {
    log.warn("String_Node_Str" + getClusterId());
  }
}