Program: 115935
Project: 115935
Buggy source:
public void addInstanceContext(String instanceId,Cluster cluster,boolean hasScalingDependents,boolean groupScalingEnabledSubtree) throws PolicyValidationException, PartitionValidationException {
  ClusterLevelNetworkPartitionContext networkPartitionContext=null;
  ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
  String deploymentPolicyName=AutoscalerUtil.getDeploymentPolicyIdByAlias(cluster.getAppId(),AutoscalerUtil.getAliasFromClusterId(clusterId));
  DeploymentPolicy deploymentPolicy;
  try {
    deploymentPolicy=CloudControllerServiceClient.getInstance().getDeploymentPolicy(deploymentPolicyName);
  }
 catch (  Exception e) {
    String msg=String.format("String_Node_Str",deploymentPolicyName);
    log.error(msg,e);
    throw new AutoScalerException(msg,e);
  }
  if (networkPartitionCtxts.containsKey(clusterInstance.getNetworkPartitionId())) {
    networkPartitionContext=this.networkPartitionCtxts.get(clusterInstance.getNetworkPartitionId());
  }
 else {
    NetworkPartitionRef[] networkPartitionRefs=deploymentPolicy.getNetworkPartitionsRef();
    NetworkPartitionRef networkPartitionRef=null;
    if (networkPartitionRefs != null && networkPartitionRefs.length != 0) {
      for (      NetworkPartitionRef i : networkPartitionRefs) {
        if (i.getId().equals(clusterInstance.getNetworkPartitionId())) {
          networkPartitionRef=i;
        }
      }
    }
    networkPartitionContext=new ClusterLevelNetworkPartitionContext(networkPartitionRef.getId(),networkPartitionRef.getPartitionAlgo(),0);
  }
  if (clusterInstance.getPartitionId() != null) {
    networkPartitionContext=addPartition(clusterInstance,cluster,networkPartitionContext,null,hasScalingDependents,groupScalingEnabledSubtree);
  }
 else {
    networkPartitionContext=parseDeploymentPolicy(clusterInstance,cluster,networkPartitionContext,hasScalingDependents,groupScalingEnabledSubtree);
  }
  if (!networkPartitionCtxts.containsKey(clusterInstance.getNetworkPartitionId())) {
    this.networkPartitionCtxts.put(clusterInstance.getNetworkPartitionId(),networkPartitionContext);
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterInstance.getInstanceId(),clusterInstance.getNetworkPartitionId()));
    }
  }
}

Fixed version (ground truth):
public void addInstanceContext(String instanceId,Cluster cluster,boolean hasScalingDependents,boolean groupScalingEnabledSubtree) throws PolicyValidationException, PartitionValidationException {
  ClusterLevelNetworkPartitionContext networkPartitionContext=null;
  ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
  String deploymentPolicyName=AutoscalerUtil.getDeploymentPolicyIdByAlias(cluster.getAppId(),AutoscalerUtil.getAliasFromClusterId(clusterId));
  DeploymentPolicy deploymentPolicy;
  try {
    deploymentPolicy=CloudControllerServiceClient.getInstance().getDeploymentPolicy(deploymentPolicyName);
  }
 catch (  Exception e) {
    String msg=String.format("String_Node_Str",deploymentPolicyName);
    log.error(msg,e);
    throw new AutoScalerException(msg,e);
  }
  if (networkPartitionCtxts.containsKey(clusterInstance.getNetworkPartitionId())) {
    networkPartitionContext=this.networkPartitionCtxts.get(clusterInstance.getNetworkPartitionId());
  }
 else {
    NetworkPartitionRef[] networkPartitionRefs=deploymentPolicy.getNetworkPartitionsRef();
    NetworkPartitionRef networkPartitionRef=null;
    if (networkPartitionRefs != null && networkPartitionRefs.length != 0) {
      for (      NetworkPartitionRef i : networkPartitionRefs) {
        if (i.getId().equals(clusterInstance.getNetworkPartitionId())) {
          networkPartitionRef=i;
        }
      }
    }
    if (networkPartitionRef == null) {
      networkPartitionContext=new ClusterLevelNetworkPartitionContext(clusterInstance.getNetworkPartitionId());
    }
 else {
      networkPartitionContext=new ClusterLevelNetworkPartitionContext(networkPartitionRef.getId(),networkPartitionRef.getPartitionAlgo(),0);
    }
  }
  if (clusterInstance.getPartitionId() != null) {
    networkPartitionContext=addPartition(clusterInstance,cluster,networkPartitionContext,null,hasScalingDependents,groupScalingEnabledSubtree);
  }
 else {
    networkPartitionContext=parseDeploymentPolicy(clusterInstance,cluster,networkPartitionContext,hasScalingDependents,groupScalingEnabledSubtree);
  }
  if (!networkPartitionCtxts.containsKey(clusterInstance.getNetworkPartitionId())) {
    this.networkPartitionCtxts.put(clusterInstance.getNetworkPartitionId(),networkPartitionContext);
    if (log.isInfoEnabled()) {
      log.info(String.format("String_Node_Str" + "String_Node_Str",clusterInstance.getInstanceId(),clusterInstance.getNetworkPartitionId()));
    }
  }
}