Program: 115600
Project: 115600
Buggy source:
/** 
 * Updates ClusterContext for given cluster
 * @param parentMonitor parent of the monitor
 * @param context       the child-context from the startup-dependency tree
 * @return ClusterMonitor - Updated ClusterContext
 * @throws PolicyValidationException    policy validation error
 * @throws PartitionValidationException partition validation error
 */
public static ClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,ClusterChildContext context,List<String> parentInstanceIds) throws PolicyValidationException, PartitionValidationException, TopologyInConsistentException {
  String clusterId=context.getId();
  String serviceName=context.getServiceName();
  Cluster cluster;
  TopologyManager.acquireReadLockForCluster(serviceName,clusterId);
  try {
    Topology topology=TopologyManager.getTopology();
    Service service=topology.getService(serviceName);
    if (service == null) {
      String msg=String.format("String_Node_Str",serviceName);
      throw new RuntimeException(msg);
    }
    cluster=service.getCluster(clusterId);
    if (cluster == null) {
      String msg=String.format("String_Node_Str",serviceName,clusterId);
      throw new RuntimeException(msg);
    }
    String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(parentMonitor.appId,AutoscalerUtil.getAliasFromClusterId(clusterId));
    DeploymentPolicy deploymentPolicy;
    try {
      deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId);
    }
 catch (    Exception e) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",deploymentPolicyId);
      log.error(msg,e);
      throw new RuntimeException(msg,e);
    }
    List<PartitionRef> partitionList=new ArrayList<PartitionRef>();
    for (    NetworkPartitionRef networkPartitionRef : deploymentPolicy.getNetworkPartitionRefs()) {
      if (networkPartitionRef != null) {
        Collections.addAll(partitionList,networkPartitionRef.getPartitionRefs());
        try {
          CloudControllerServiceClient.getInstance().validateNetworkPartitionOfDeploymentPolicy(serviceName,networkPartitionRef.getId());
        }
 catch (        Exception e) {
          String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionRef.getId());
          log.error(msg,e);
          throw new RuntimeException(msg,e);
        }
      }
    }
    boolean hasScalingDependents=false;
    if (parentMonitor.getScalingDependencies() != null) {
      for (      ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()) {
        if (scalingDependentList.getScalingDependentListComponents().contains(clusterId)) {
          hasScalingDependents=true;
        }
      }
    }
    boolean groupScalingEnabledSubtree=false;
    if (parentMonitor instanceof GroupMonitor) {
      GroupMonitor groupMonitor=(GroupMonitor)parentMonitor;
      groupScalingEnabledSubtree=findIfChildIsInGroupScalingEnabledSubTree(groupMonitor);
    }
    ClusterMonitor clusterMonitor=new ClusterMonitor(cluster,hasScalingDependents,groupScalingEnabledSubtree,deploymentPolicyId);
    Properties props=cluster.getProperties();
    if (props != null) {
      clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(IS_PRIMARY)));
    }
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    clusterMonitor.createClusterInstances(parentInstanceIds,cluster);
    AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
    log.info("String_Node_Str" + clusterMonitor.toString());
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}

Fixed version (ground truth):
/** 
 * Updates ClusterContext for given cluster
 * @param parentMonitor parent of the monitor
 * @param context       the child-context from the startup-dependency tree
 * @return ClusterMonitor - Updated ClusterContext
 * @throws PolicyValidationException    policy validation error
 * @throws PartitionValidationException partition validation error
 */
public static ClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,ClusterChildContext context,List<String> parentInstanceIds) throws PolicyValidationException, PartitionValidationException, TopologyInConsistentException {
  String clusterId=context.getId();
  String serviceName=context.getServiceName();
  Cluster cluster;
  TopologyManager.acquireReadLockForCluster(serviceName,clusterId);
  try {
    Topology topology=TopologyManager.getTopology();
    Service service=topology.getService(serviceName);
    if (service == null) {
      String msg=String.format("String_Node_Str",serviceName);
      throw new RuntimeException(msg);
    }
    cluster=service.getCluster(clusterId);
    if (cluster == null) {
      String msg=String.format("String_Node_Str",serviceName,clusterId);
      throw new RuntimeException(msg);
    }
    Collection<Instance> instances=parentMonitor.getInstances();
    for (    Instance instance : instances) {
      if (!parentInstanceIds.contains(instance.getInstanceId())) {
        parentInstanceIds.add(instance.getInstanceId());
      }
    }
    String deploymentPolicyId=AutoscalerUtil.getDeploymentPolicyIdByAlias(parentMonitor.appId,AutoscalerUtil.getAliasFromClusterId(clusterId));
    DeploymentPolicy deploymentPolicy;
    try {
      deploymentPolicy=PolicyManager.getInstance().getDeploymentPolicy(deploymentPolicyId);
    }
 catch (    Exception e) {
      String msg=String.format("String_Node_Str" + "String_Node_Str",deploymentPolicyId);
      log.error(msg,e);
      throw new RuntimeException(msg,e);
    }
    List<PartitionRef> partitionList=new ArrayList<PartitionRef>();
    for (    NetworkPartitionRef networkPartitionRef : deploymentPolicy.getNetworkPartitionRefs()) {
      if (networkPartitionRef != null) {
        Collections.addAll(partitionList,networkPartitionRef.getPartitionRefs());
        try {
          CloudControllerServiceClient.getInstance().validateNetworkPartitionOfDeploymentPolicy(serviceName,networkPartitionRef.getId());
        }
 catch (        Exception e) {
          String msg=String.format("String_Node_Str" + "String_Node_Str",networkPartitionRef.getId());
          log.error(msg,e);
          throw new RuntimeException(msg,e);
        }
      }
    }
    boolean hasScalingDependents=false;
    if (parentMonitor.getScalingDependencies() != null) {
      for (      ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()) {
        if (scalingDependentList.getScalingDependentListComponents().contains(clusterId)) {
          hasScalingDependents=true;
        }
      }
    }
    boolean groupScalingEnabledSubtree=false;
    if (parentMonitor instanceof GroupMonitor) {
      GroupMonitor groupMonitor=(GroupMonitor)parentMonitor;
      groupScalingEnabledSubtree=findIfChildIsInGroupScalingEnabledSubTree(groupMonitor);
    }
    ClusterMonitor clusterMonitor=new ClusterMonitor(cluster,hasScalingDependents,groupScalingEnabledSubtree,deploymentPolicyId);
    Properties props=cluster.getProperties();
    if (props != null) {
      clusterMonitor.setHasPrimary(Boolean.parseBoolean(cluster.getProperties().getProperty(IS_PRIMARY)));
    }
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    clusterMonitor.createClusterInstances(parentInstanceIds,cluster);
    AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
    log.info("String_Node_Str" + clusterMonitor.toString());
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}