Program: 115584
Project: 115584
Buggy source:
public synchronized void monitor(){
  try {
    for (    ClusterLevelNetworkPartitionContext 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()));
              }
              List<String> primaryMemberListInClusterInstance=new ArrayList<String>();
              for (              ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
                for (                MemberContext memberContext : partitionContext.getActiveMembers()) {
                  if (isPrimaryMember(memberContext)) {
                    primaryMemberListInClusterInstance.add(memberContext.getMemberId());
                  }
                }
                for (                MemberContext memberContext : partitionContext.getPendingMembers()) {
                  if (isPrimaryMember(memberContext)) {
                    primaryMemberListInClusterInstance.add(memberContext.getMemberId());
                  }
                }
              }
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance.size());
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",hasPrimary);
              String paritionAlgo=instanceContext.getPartitionAlgorithm();
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str",instanceContext.getId() + "String_Node_Str" + clusterId));
              }
              instanceContext.setMinCheckFactHandle(evaluate(instanceContext.getMinCheckKnowledgeSession(),instanceContext.getMinCheckFactHandle(),instanceContext));
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance.size());
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",hasPrimary);
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str",instanceContext.getId() + "String_Node_Str" + 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) {
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str" + rifReset + "String_Node_Str"+ memoryConsumptionReset+ "String_Node_Str"+ loadAverageReset+ "String_Node_Str"+ clusterId);
                }
                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",hasPrimary);
                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",primaryMemberListInClusterInstance);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str",instanceContext.getId()));
                  log.debug("String_Node_Str" + primaryMemberListInClusterInstance);
                }
                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);
        }
        for (        final ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
          Runnable monitoringRunnable=new Runnable(){
            @Override public void run(){
              instanceContext.getObsoleteCheckKnowledgeSession().setGlobal("String_Node_Str",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 (    ClusterLevelNetworkPartitionContext 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()));
              }
              List<String> primaryMemberListInClusterInstance=new ArrayList<String>();
              for (              ClusterLevelPartitionContext partitionContext : instanceContext.getPartitionCtxts()) {
                for (                MemberContext memberContext : partitionContext.getActiveMembers()) {
                  if (isPrimaryMember(memberContext)) {
                    primaryMemberListInClusterInstance.add(memberContext.getMemberId());
                  }
                }
                for (                MemberContext memberContext : partitionContext.getPendingMembers()) {
                  if (isPrimaryMember(memberContext)) {
                    primaryMemberListInClusterInstance.add(memberContext.getMemberId());
                  }
                }
              }
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance.size());
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",hasPrimary);
              String paritionAlgo=instanceContext.getPartitionAlgorithm();
              instanceContext.getMinCheckKnowledgeSession().setGlobal("String_Node_Str",paritionAlgo);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str",instanceContext.getId() + "String_Node_Str" + clusterId));
              }
              instanceContext.setMinCheckFactHandle(evaluate(instanceContext.getMinCheckKnowledgeSession(),instanceContext.getMinCheckFactHandle(),instanceContext));
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance.size());
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",getClusterId());
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",hasPrimary);
              instanceContext.getMaxCheckKnowledgeSession().setGlobal("String_Node_Str",primaryMemberListInClusterInstance);
              if (log.isDebugEnabled()) {
                log.debug(String.format("String_Node_Str",instanceContext.getId() + "String_Node_Str" + 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) {
                if (log.isDebugEnabled()) {
                  log.debug("String_Node_Str" + rifReset + "String_Node_Str"+ memoryConsumptionReset+ "String_Node_Str"+ loadAverageReset+ "String_Node_Str"+ clusterId);
                }
                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",hasPrimary);
                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",primaryMemberListInClusterInstance);
                if (log.isDebugEnabled()) {
                  log.debug(String.format("String_Node_Str",instanceContext.getId()));
                  log.debug("String_Node_Str" + primaryMemberListInClusterInstance);
                }
                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);
              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());
  }
}