Program: 116180
Project: 116180
Buggy source:
/** 
 * Updates ClusterContext for given cluster
 * @param parentMonitor parent of the monitor
 * @param context
 * @return ClusterMonitor - Updated ClusterContext
 * @throws org.apache.stratos.autoscaler.exception.policy.PolicyValidationException
 * @throws org.apache.stratos.autoscaler.exception.partition.PartitionValidationException
 */
public static AbstractClusterMonitor 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();
    if (topology.serviceExists(serviceName)) {
      Service service=topology.getService(serviceName);
      if (service.clusterExists(clusterId)) {
        cluster=service.getCluster(clusterId);
      }
 else {
        String msg="String_Node_Str" + clusterId + "String_Node_Str"+ "String_Node_Str"+ serviceName;
        throw new TopologyInConsistentException(msg);
      }
    }
 else {
      String msg="String_Node_Str" + serviceName + "String_Node_Str";
      throw new TopologyInConsistentException(msg);
    }
    AbstractClusterMonitor clusterMonitor=ClusterMonitorFactory.getMonitor(cluster);
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    if (parentMonitor.hasGroupScalingDependent() || (context.isGroupScalingEnabled())) {
      clusterMonitor.setHasGroupScalingDependent(true);
    }
 else {
      clusterMonitor.setHasGroupScalingDependent(false);
    }
    for (    String parentInstanceId : parentInstanceIds) {
      Instance instance=parentMonitor.getInstance(parentInstanceId);
      String partitionId=null;
      if (instance instanceof GroupInstance) {
        partitionId=((GroupInstance)instance).getPartitionId();
      }
      if (instance != null) {
        ClusterInstance clusterInstance=cluster.getInstanceContexts(parentInstanceId);
        if (clusterInstance != null) {
          if (cluster.isKubernetesCluster()) {
            clusterMonitor.setClusterContext(ClusterContextFactory.getKubernetesClusterContext(clusterInstance.getInstanceId(),cluster));
          }
 else {
            VMClusterContext clusterContext;
            clusterContext=ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(),cluster);
            clusterMonitor.setClusterContext(clusterContext);
            clusterContext.addInstanceContext(parentInstanceId,cluster);
            if (clusterMonitor.getInstance(clusterInstance.getInstanceId()) == null) {
              clusterMonitor.addInstance(clusterInstance);
            }
          }
        }
 else {
          createClusterInstance(cluster.getServiceName(),clusterId,null,parentInstanceId,partitionId,instance.getNetworkPartitionId());
        }
      }
 else {
      }
      AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
    }
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}

Fixed version (ground truth):
/** 
 * Updates ClusterContext for given cluster
 * @param parentMonitor parent of the monitor
 * @param context
 * @return ClusterMonitor - Updated ClusterContext
 * @throws org.apache.stratos.autoscaler.exception.policy.PolicyValidationException
 * @throws org.apache.stratos.autoscaler.exception.partition.PartitionValidationException
 */
public static AbstractClusterMonitor 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();
    if (topology.serviceExists(serviceName)) {
      Service service=topology.getService(serviceName);
      if (service.clusterExists(clusterId)) {
        cluster=service.getCluster(clusterId);
      }
 else {
        String msg="String_Node_Str" + clusterId + "String_Node_Str"+ "String_Node_Str"+ serviceName;
        throw new TopologyInConsistentException(msg);
      }
    }
 else {
      String msg="String_Node_Str" + serviceName + "String_Node_Str";
      throw new TopologyInConsistentException(msg);
    }
    AbstractClusterMonitor clusterMonitor=ClusterMonitorFactory.getMonitor(cluster);
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    if (parentMonitor.hasGroupScalingDependent() || (context.isGroupScalingEnabled())) {
      clusterMonitor.setHasGroupScalingDependent(true);
    }
 else {
      clusterMonitor.setHasGroupScalingDependent(false);
    }
    for (    String parentInstanceId : parentInstanceIds) {
      Instance parentMonitorInstance=parentMonitor.getInstance(parentInstanceId);
      String partitionId=null;
      if (parentMonitorInstance instanceof GroupInstance) {
        partitionId=parentMonitorInstance.getPartitionId();
      }
      if (parentMonitorInstance != null) {
        ClusterInstance clusterInstance=cluster.getInstanceContexts(parentInstanceId);
        if (clusterInstance != null) {
          if (cluster.isKubernetesCluster()) {
            clusterMonitor.setClusterContext(ClusterContextFactory.getKubernetesClusterContext(clusterInstance.getInstanceId(),cluster));
          }
 else {
            VMClusterContext clusterContext;
            clusterContext=ClusterContextFactory.getVMClusterContext(clusterInstance.getInstanceId(),cluster);
            clusterMonitor.setClusterContext(clusterContext);
            clusterContext.addInstanceContext(parentInstanceId,cluster);
            if (clusterMonitor.getInstance(clusterInstance.getInstanceId()) == null) {
              clusterMonitor.addInstance(clusterInstance);
            }
          }
        }
 else {
          createClusterInstance(cluster.getServiceName(),clusterId,null,parentInstanceId,partitionId,parentMonitorInstance.getNetworkPartitionId());
        }
      }
 else {
      }
      AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
    }
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}