Program: 116304
Project: 116304
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.PolicyValidationException
 * @throws org.apache.stratos.autoscaler.exception.PartitionValidationException
 */
public static AbstractClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,ClusterChildContext context,String appId) 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.hasScalingDependents() || (context.hasScalingDependents())) {
      clusterMonitor.setHasScalingDependents(true);
    }
 else {
      clusterMonitor.setHasScalingDependents(false);
    }
    if (cluster.getStatus() != clusterMonitor.getStatus()) {
      clusterMonitor.setStatus(cluster.getStatus());
    }
 else {
      if (!cluster.hasMembers()) {
        StatusChecker.getInstance().onMemberStatusChange(clusterId);
      }
    }
    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.PolicyValidationException
 * @throws org.apache.stratos.autoscaler.exception.PartitionValidationException
 */
public static AbstractClusterMonitor getClusterMonitor(ParentComponentMonitor parentMonitor,ClusterChildContext context,String appId) 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.isGroupScalingEnabled() || (context.isGroupScalingEnabled())) {
      clusterMonitor.setGroupScalingEnabled(true);
    }
 else {
      clusterMonitor.setGroupScalingEnabled(false);
    }
    if (cluster.getStatus() != clusterMonitor.getStatus()) {
      clusterMonitor.setStatus(cluster.getStatus());
    }
 else {
      if (!cluster.hasMembers()) {
        StatusChecker.getInstance().onMemberStatusChange(clusterId);
      }
    }
    return clusterMonitor;
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}