Program: 116358
Project: 116358
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,ClusterContext 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);
    if (parentMonitor.isDependent() || (context.isDependent() && context.hasChild())) {
      clusterMonitor.setHasDependent(true);
    }
 else {
      clusterMonitor.setHasDependent(false);
    }
    if (cluster.getStatus() != clusterMonitor.getStatus()) {
      clusterMonitor.setStatus(cluster.getStatus());
    }
    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,ClusterContext 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);
    if (parentMonitor.isDependent() || (context.isDependent() && context.hasChild())) {
      clusterMonitor.setHasDependent(true);
    }
 else {
      clusterMonitor.setHasDependent(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);
  }
}