Program: 116543
Project: 116543
Buggy source:
/** 
 * Updates ClusterContext for given cluster
 * @param cluster
 * @return ClusterMonitor - Updated ClusterContext
 * @throws PolicyValidationException
 * @throws PartitionValidationException
 */
public static ClusterMonitor getClusterMonitor(Cluster cluster) throws PolicyValidationException, PartitionValidationException {
  if (null == cluster) {
    return null;
  }
  String autoscalePolicyName=cluster.getAutoscalePolicyName();
  String deploymentPolicyName=cluster.getDeploymentPolicyName();
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + deploymentPolicyName);
    log.debug("String_Node_Str" + autoscalePolicyName);
  }
  AutoscalePolicy policy=PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
  DeploymentPolicy deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyName);
  if (deploymentPolicy == null) {
    String msg="String_Node_Str" + deploymentPolicyName;
    log.error(msg);
    throw new PolicyValidationException(msg);
  }
  Partition[] allPartitions=deploymentPolicy.getAllPartitions();
  if (allPartitions == null) {
    String msg="String_Node_Str" + deploymentPolicyName;
    log.error(msg);
    throw new PolicyValidationException(msg);
  }
  CloudControllerClient.getInstance().validateDeploymentPolicy(cluster.getServiceName(),deploymentPolicy);
  ClusterMonitor clusterMonitor=new ClusterMonitor(cluster.getClusterId(),cluster.getServiceName(),deploymentPolicy,policy);
  clusterMonitor.setStatus(Status.Created);
  for (  PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroups()) {
    NetworkPartitionContext networkPartitionContext=new NetworkPartitionContext(partitionGroup.getId(),partitionGroup.getPartitionAlgo(),partitionGroup.getPartitions());
    for (    Partition partition : partitionGroup.getPartitions()) {
      PartitionContext partitionContext=new PartitionContext(partition);
      partitionContext.setServiceName(cluster.getServiceName());
      partitionContext.setProperties(cluster.getProperties());
      partitionContext.setNetworkPartitionId(partitionGroup.getId());
      for (      Member member : cluster.getMembers()) {
        String memberId=member.getMemberId();
        if (member.getPartitionId().equalsIgnoreCase(partition.getId())) {
          MemberContext memberContext=new MemberContext();
          memberContext.setClusterId(member.getClusterId());
          memberContext.setMemberId(memberId);
          memberContext.setPartition(partition);
          memberContext.setProperties(convertMemberPropsToMemberContextProps(member.getProperties()));
          if (MemberStatus.Activated.equals(member.getStatus())) {
            partitionContext.addActiveMember(memberContext);
          }
 else           if (MemberStatus.Created.equals(member.getStatus()) || MemberStatus.Starting.equals(member.getStatus())) {
            partitionContext.addPendingMember(memberContext);
          }
 else           if (MemberStatus.Suspended.equals(member.getStatus())) {
          }
          partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
          if (log.isInfoEnabled()) {
            log.info(String.format("String_Node_Str",memberId));
          }
        }
      }
      networkPartitionContext.addPartitionContext(partitionContext);
      if (log.isInfoEnabled()) {
        log.info(String.format("String_Node_Str",partitionContext.getPartitionId()));
      }
    }
    clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str",networkPartitionContext.getId()));
    }
  }
  if (cluster.getProperties() != null) {
    clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(Constants.IS_PRIMARY)));
  }
  log.info("String_Node_Str" + clusterMonitor.toString());
  return clusterMonitor;
}

Fixed version (ground truth):
/** 
 * Updates ClusterContext for given cluster
 * @param cluster
 * @return ClusterMonitor - Updated ClusterContext
 * @throws PolicyValidationException
 * @throws PartitionValidationException
 */
public static ClusterMonitor getClusterMonitor(Cluster cluster) throws PolicyValidationException, PartitionValidationException {
  if (null == cluster) {
    return null;
  }
  String autoscalePolicyName=cluster.getAutoscalePolicyName();
  String deploymentPolicyName=cluster.getDeploymentPolicyName();
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + deploymentPolicyName);
    log.debug("String_Node_Str" + autoscalePolicyName);
  }
  AutoscalePolicy policy=PolicyManager.getInstance().getAutoscalePolicy(autoscalePolicyName);
  DeploymentPolicy deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyName);
  if (deploymentPolicy == null) {
    String msg="String_Node_Str" + deploymentPolicyName;
    log.error(msg);
    throw new PolicyValidationException(msg);
  }
  Partition[] allPartitions=deploymentPolicy.getAllPartitions();
  if (allPartitions == null) {
    String msg="String_Node_Str" + deploymentPolicyName;
    log.error(msg);
    throw new PolicyValidationException(msg);
  }
  CloudControllerClient.getInstance().validateDeploymentPolicy(cluster.getServiceName(),deploymentPolicy);
  ClusterMonitor clusterMonitor=new ClusterMonitor(cluster.getClusterId(),cluster.getServiceName(),deploymentPolicy,policy);
  clusterMonitor.setAppId(cluster.getAppId());
  clusterMonitor.setStatus(Status.Created);
  for (  PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroups()) {
    NetworkPartitionContext networkPartitionContext=new NetworkPartitionContext(partitionGroup.getId(),partitionGroup.getPartitionAlgo(),partitionGroup.getPartitions());
    for (    Partition partition : partitionGroup.getPartitions()) {
      PartitionContext partitionContext=new PartitionContext(partition);
      partitionContext.setServiceName(cluster.getServiceName());
      partitionContext.setProperties(cluster.getProperties());
      partitionContext.setNetworkPartitionId(partitionGroup.getId());
      for (      Member member : cluster.getMembers()) {
        String memberId=member.getMemberId();
        if (member.getPartitionId().equalsIgnoreCase(partition.getId())) {
          MemberContext memberContext=new MemberContext();
          memberContext.setClusterId(member.getClusterId());
          memberContext.setMemberId(memberId);
          memberContext.setPartition(partition);
          memberContext.setProperties(convertMemberPropsToMemberContextProps(member.getProperties()));
          if (MemberStatus.Activated.equals(member.getStatus())) {
            partitionContext.addActiveMember(memberContext);
          }
 else           if (MemberStatus.Created.equals(member.getStatus()) || MemberStatus.Starting.equals(member.getStatus())) {
            partitionContext.addPendingMember(memberContext);
          }
 else           if (MemberStatus.Suspended.equals(member.getStatus())) {
          }
          partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
          if (log.isInfoEnabled()) {
            log.info(String.format("String_Node_Str",memberId));
          }
        }
      }
      networkPartitionContext.addPartitionContext(partitionContext);
      if (log.isInfoEnabled()) {
        log.info(String.format("String_Node_Str",partitionContext.getPartitionId()));
      }
    }
    clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str",networkPartitionContext.getId()));
    }
  }
  if (cluster.getProperties() != null) {
    clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(Constants.IS_PRIMARY)));
  }
  log.info("String_Node_Str" + clusterMonitor.toString());
  return clusterMonitor;
}