Program: 116052
Project: 116052
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);
    }
    boolean hasScalingDependents=false;
    if (parentMonitor.getScalingDependencies() != null) {
      for (      ScalingDependentList scalingDependentList : parentMonitor.getScalingDependencies()) {
        if (scalingDependentList.getScalingDependentListComponents().contains("String_Node_Str" + clusterId.substring(0,clusterId.indexOf('.')))) {
          hasScalingDependents=true;
        }
      }
    }
    boolean groupScalingEnabledSubtree=false;
    if (parentMonitor instanceof GroupMonitor) {
      GroupMonitor groupMonitor=(GroupMonitor)parentMonitor;
      groupScalingEnabledSubtree=findIfChildIsInGroupScalingEnabledSubTree(groupMonitor);
    }
    AbstractClusterMonitor clusterMonitor=ClusterMonitorFactory.getMonitor(cluster,hasScalingDependents,groupScalingEnabledSubtree);
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    ((VMClusterMonitor)clusterMonitor).createClusterInstance(parentInstanceIds,cluster);
    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);
    }
    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);
    }
    AbstractClusterMonitor clusterMonitor=ClusterMonitorFactory.getMonitor(cluster,hasScalingDependents,groupScalingEnabledSubtree);
    clusterMonitor.setParent(parentMonitor);
    clusterMonitor.setId(clusterId);
    if (parentMonitor.hasStartupDependents() || (context.hasStartupDependents() && context.hasChild())) {
      clusterMonitor.setHasStartupDependents(true);
    }
 else {
      clusterMonitor.setHasStartupDependents(false);
    }
    ((VMClusterMonitor)clusterMonitor).createClusterInstance(parentInstanceIds,cluster);
    AutoscalerContext.getInstance().addClusterMonitor(clusterMonitor);
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}