nus-yam/ex-repair huggingface dataset:
Program: 116174
Project: 116174
Buggy source:
public static void handleGroupTerminatingEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  try {
    ApplicationHolder.acquireWriteLock();
    GroupInstance context=group.getInstanceContexts(instanceId);
    GroupStatus status=GroupStatus.Terminating;
    if (context != null) {
      if (context.isStateTransitionValid(status)) {
        updateGroupMonitor(appId,groupId,status,instanceId);
        ApplicationHolder.persistApplication(application);
        ApplicationsEventPublisher.sendGroupInstanceTerminatingEvent(appId,groupId,instanceId);
      }
 else {
        log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
      }
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
}

Fixed version (ground truth):
public static void handleGroupTerminatingEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  try {
    ApplicationHolder.acquireWriteLock();
    GroupInstance context=group.getInstanceContexts(instanceId);
    GroupStatus status=GroupStatus.Terminating;
    if (context != null) {
      if (context.isStateTransitionValid(status)) {
        context.setStatus(status);
        updateGroupMonitor(appId,groupId,status,instanceId);
        ApplicationHolder.persistApplication(application);
        ApplicationsEventPublisher.sendGroupInstanceTerminatingEvent(appId,groupId,instanceId);
      }
 else {
        log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
      }
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
}
Program: 116175
Project: 116175
Buggy source:
public static void handleApplicationInstanceTerminatedEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  if (!applications.applicationExists(appId)) {
    log.warn("String_Node_Str" + appId);
  }
 else {
    Application application=applications.getApplication(appId);
    Set<ClusterDataHolder> clusterData=application.getClusterDataRecursively();
    ApplicationStatus status=ApplicationStatus.Terminated;
    if (application.isStateTransitionValid(status,instanceId)) {
      application.setStatus(status,instanceId);
      updateApplicationMonitor(appId,status,instanceId);
      AutoscalerContext.getInstance().removeAppMonitor(appId);
      ApplicationHolder.removeApplication(appId);
      log.info("String_Node_Str" + appId);
      ApplicationsEventPublisher.sendApplicationInstanceTerminatedEvent(appId,clusterData);
    }
 else {
      log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,application.getInstanceContexts(instanceId).getStatus(),status));
    }
  }
}

Fixed version (ground truth):
public static void handleApplicationInstanceTerminatedEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  if (!applications.applicationExists(appId)) {
    log.warn("String_Node_Str" + appId);
  }
 else {
    Application application=applications.getApplication(appId);
    Set<ClusterDataHolder> clusterData=application.getClusterDataRecursively();
    ApplicationInstance instance=application.getInstanceContexts(instanceId);
    ApplicationStatus status=ApplicationStatus.Terminated;
    if (instance.isStateTransitionValid(status)) {
      instance.setStatus(status);
      application.removeInstance(instanceId);
      updateApplicationMonitor(appId,status,instanceId);
      if (application.getInstanceContextCount() == 0) {
        AutoscalerContext.getInstance().removeAppMonitor(appId);
        ApplicationHolder.removeApplication(appId);
        log.info("String_Node_Str" + appId);
      }
      ApplicationsEventPublisher.sendApplicationInstanceTerminatedEvent(appId,clusterData);
    }
 else {
      log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,application.getInstanceContexts(instanceId).getStatus(),status));
    }
  }
}
Program: 116176
Project: 116176
Buggy source:
public static GroupInstance handleGroupInstanceCreatedEvent(String appId,String groupId,String parentId,String networkPartitionId,String instanceId,String partitionId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  GroupInstance instance=null;
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return instance;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return instance;
  }
  GroupStatus status=GroupStatus.Created;
  if (!group.containsInstanceContext(instanceId)) {
    instance=new GroupInstance(groupId,instanceId);
    instance.setParentId(parentId);
    instance.setPartitionId(partitionId);
    instance.setNetworkPartitionId(networkPartitionId);
    instance.setStatus(status);
    group.addInstance(instanceId,instance);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendGroupInstanceCreatedEvent(appId,groupId,instance);
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
  return instance;
}

Fixed version (ground truth):
public static GroupInstance handleGroupInstanceCreatedEvent(String appId,String groupId,String parentId,String networkPartitionId,String instanceId,String partitionId){
  GroupInstance instance=null;
  ApplicationHolder.acquireWriteLock();
  try {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
    }
    Applications applications=ApplicationHolder.getApplications();
    Application application=applications.getApplication(appId);
    if (application == null) {
      log.warn(String.format("String_Node_Str",appId));
      return instance;
    }
    Group group=application.getGroupRecursively(groupId);
    if (group == null) {
      log.warn(String.format("String_Node_Str",groupId));
      return instance;
    }
    GroupStatus status=GroupStatus.Created;
    if (!group.containsInstanceContext(instanceId)) {
      instance=new GroupInstance(groupId,instanceId);
      instance.setParentId(parentId);
      instance.setPartitionId(partitionId);
      instance.setNetworkPartitionId(networkPartitionId);
      instance.setStatus(status);
      group.addInstance(instanceId,instance);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendGroupInstanceCreatedEvent(appId,groupId,instance);
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
  return instance;
}
Program: 116177
Project: 116177
Buggy source:
public static ApplicationInstance handleApplicationInstanceCreatedEvent(String appId,String instanceId,String networkPartitionId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return null;
  }
  ApplicationStatus status=ApplicationStatus.Created;
  ApplicationInstance applicationInstance=null;
  if (!application.containsInstanceContext(instanceId)) {
    applicationInstance=new ApplicationInstance(appId,instanceId);
    applicationInstance.setStatus(status);
    applicationInstance.setNetworkPartitionId(networkPartitionId);
    application.addInstance(instanceId,applicationInstance);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendApplicationInstanceCreatedEvent(appId,applicationInstance);
  }
 else {
    log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId));
  }
  return applicationInstance;
}

Fixed version (ground truth):
public static ApplicationInstance handleApplicationInstanceCreatedEvent(String appId,String instanceId,String networkPartitionId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId);
  }
  ApplicationInstance applicationInstance=null;
  ApplicationHolder.acquireWriteLock();
  try {
    Applications applications=ApplicationHolder.getApplications();
    Application application=applications.getApplication(appId);
    if (application == null) {
      log.warn(String.format("String_Node_Str",appId));
      return null;
    }
    if (!application.containsInstanceContext(instanceId)) {
      applicationInstance=new ApplicationInstance(appId,instanceId);
      applicationInstance.setNetworkPartitionId(networkPartitionId);
      application.addInstance(instanceId,applicationInstance);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendApplicationInstanceCreatedEvent(appId,applicationInstance);
    }
 else {
      log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId));
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
  return applicationInstance;
}
Program: 116178
Project: 116178
Buggy source:
public static void handleGroupInstanceActivatedEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  GroupInstance context=group.getInstanceContexts(instanceId);
  GroupStatus status=GroupStatus.Active;
  if (context != null) {
    if (context.isStateTransitionValid(status)) {
      updateGroupMonitor(appId,groupId,status,instanceId);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendGroupInstanceActivatedEvent(appId,groupId,instanceId);
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
    }
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
}

Fixed version (ground truth):
public static void handleGroupInstanceActivatedEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  GroupInstance context=group.getInstanceContexts(instanceId);
  GroupStatus status=GroupStatus.Active;
  if (context != null) {
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      updateGroupMonitor(appId,groupId,status,instanceId);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendGroupInstanceActivatedEvent(appId,groupId,instanceId);
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
    }
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
}
Program: 116179
Project: 116179
Buggy source:
public static void handleGroupInActivateEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  GroupInstance context=group.getInstanceContexts(instanceId);
  GroupStatus status=GroupStatus.Inactive;
  if (context != null) {
    if (context.isStateTransitionValid(status)) {
      updateGroupMonitor(appId,groupId,status,instanceId);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendGroupInstanceInActivateEvent(appId,groupId,instanceId);
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
    }
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
}

Fixed version (ground truth):
public static void handleGroupInActivateEvent(String appId,String groupId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return;
  }
  GroupInstance context=group.getInstanceContexts(instanceId);
  GroupStatus status=GroupStatus.Inactive;
  if (context != null) {
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      updateGroupMonitor(appId,groupId,status,instanceId);
      ApplicationHolder.persistApplication(application);
      ApplicationsEventPublisher.sendGroupInstanceInActivateEvent(appId,groupId,instanceId);
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ context.getStatus()+ "String_Node_Str"+ status);
    }
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
}
Program: 116181
Project: 116181
Buggy source:
public static void handleClusterInstanceCreated(String serviceType,String clusterId,String alias,String instanceId,String partitionId,String networkPartitionId){
  TopologyManager.acquireWriteLock();
  try {
    Topology topology=TopologyManager.getTopology();
    Service service=topology.getService(serviceType);
    if (service == null) {
      log.error("String_Node_Str" + serviceType + "String_Node_Str");
      return;
    }
    Cluster cluster=service.getCluster(clusterId);
    if (cluster == null) {
      log.error("String_Node_Str" + clusterId + "String_Node_Str"+ "String_Node_Str");
      return;
    }
    if (cluster.getInstanceContexts(instanceId) != null) {
      log.warn("String_Node_Str" + clusterId + "String_Node_Str"+ instanceId);
      return;
    }
    cluster.addInstanceContext(instanceId,new ClusterInstance(alias,clusterId,instanceId));
    TopologyManager.updateTopology(topology);
    ClusterInstanceCreatedEvent clusterInstanceCreatedEvent=new ClusterInstanceCreatedEvent(alias,serviceType,clusterId,instanceId,networkPartitionId);
    clusterInstanceCreatedEvent.setPartitionId(partitionId);
    TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}

Fixed version (ground truth):
public static void handleClusterInstanceCreated(String serviceType,String clusterId,String alias,String instanceId,String partitionId,String networkPartitionId){
  TopologyManager.acquireWriteLock();
  try {
    Topology topology=TopologyManager.getTopology();
    Service service=topology.getService(serviceType);
    if (service == null) {
      log.error("String_Node_Str" + serviceType + "String_Node_Str");
      return;
    }
    Cluster cluster=service.getCluster(clusterId);
    if (cluster == null) {
      log.error("String_Node_Str" + clusterId + "String_Node_Str"+ "String_Node_Str");
      return;
    }
    if (cluster.getInstanceContexts(instanceId) != null) {
      log.warn("String_Node_Str" + clusterId + "String_Node_Str"+ instanceId);
      return;
    }
    ClusterInstance clusterInstance=new ClusterInstance(alias,clusterId,instanceId);
    clusterInstance.setNetworkPartitionId(networkPartitionId);
    clusterInstance.setPartitionId(partitionId);
    cluster.addInstanceContext(instanceId,clusterInstance);
    TopologyManager.updateTopology(topology);
    ClusterInstanceCreatedEvent clusterInstanceCreatedEvent=new ClusterInstanceCreatedEvent(serviceType,clusterId,clusterInstance);
    clusterInstanceCreatedEvent.setPartitionId(partitionId);
    TopologyEventPublisher.sendClusterInstanceCreatedEvent(clusterInstanceCreatedEvent);
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}
Program: 116182
Project: 116182
Buggy source:
public ClusterInstanceCreatedEvent(String alias,String serviceName,String clusterId,String instanceId,String networkPartitionId){
  this.serviceName=serviceName;
  this.clusterId=clusterId;
  this.instanceId=instanceId;
  this.alias=alias;
  this.setNetworkPartitionId(networkPartitionId);
}

Fixed version (ground truth):
public ClusterInstanceCreatedEvent(String serviceName,String clusterId,ClusterInstance clusterInstance){
  this.serviceName=serviceName;
  this.clusterId=clusterId;
  this.clusterInstance=clusterInstance;
}
Program: 116183
Project: 116183
Buggy source:
private boolean doProcess(ClusterInstanceCreatedEvent event,Topology topology){
  if (TopologyServiceFilter.getInstance().isActive()) {
    if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",event.getServiceName()));
      }
      return false;
    }
  }
  if (TopologyClusterFilter.getInstance().isActive()) {
    if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",event.getClusterId()));
      }
      return false;
    }
  }
  Service service=topology.getService(event.getServiceName());
  if (service == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getServiceName()));
    }
    return false;
  }
  Cluster cluster=service.getCluster(event.getClusterId());
  if (cluster == null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str",event.getServiceName(),event.getClusterId()));
    }
  }
 else {
    ClusterInstance context=new ClusterInstance(event.getAlias(),event.getClusterId(),event.getInstanceId());
    context.setNetworkPartitionId(event.getNetworkPartitionId());
    context.setPartitionId(event.getPartitionId());
    cluster.addInstanceContext(event.getInstanceId(),context);
  }
  notifyEventListeners(event);
  return true;
}

Fixed version (ground truth):
private boolean doProcess(ClusterInstanceCreatedEvent event,Topology topology){
  if (TopologyServiceFilter.getInstance().isActive()) {
    if (TopologyServiceFilter.getInstance().serviceNameExcluded(event.getServiceName())) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",event.getServiceName()));
      }
      return false;
    }
  }
  if (TopologyClusterFilter.getInstance().isActive()) {
    if (TopologyClusterFilter.getInstance().clusterIdExcluded(event.getClusterId())) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",event.getClusterId()));
      }
      return false;
    }
  }
  Service service=topology.getService(event.getServiceName());
  if (service == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getServiceName()));
    }
    return false;
  }
  Cluster cluster=service.getCluster(event.getClusterId());
  if (cluster == null) {
    if (log.isDebugEnabled()) {
      log.debug(String.format("String_Node_Str",event.getServiceName(),event.getClusterId()));
    }
  }
 else {
    ClusterInstance clusterInstance=event.getClusterInstance();
    if (cluster.getInstanceContexts(clusterInstance.getInstanceId()) != null) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str" + "String_Node_Str",event.getServiceName(),event.getClusterId(),clusterInstance.getInstanceId()));
      }
    }
    cluster.addInstanceContext(clusterInstance.getInstanceId(),clusterInstance);
  }
  notifyEventListeners(event);
  return true;
}
Program: 116184
Project: 116184
Buggy source:
public static GroupInstance handleGroupInstanceCreatedEvent(String appId,String groupId,String instanceId,String parentId,String partitionId,String networkPartitionId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  GroupInstance instance=null;
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return instance;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return instance;
  }
  GroupStatus status=GroupStatus.Created;
  if (!group.containsInstanceContext(instanceId)) {
    instance=new GroupInstance(groupId,instanceId);
    instance.setParentId(parentId);
    instance.setStatus(status);
    group.addInstance(instanceId,instance);
    ApplicationHolder.persistApplication(application);
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
  return instance;
}

Fixed version (ground truth):
public static GroupInstance handleGroupInstanceCreatedEvent(String appId,String groupId,String parentId,String networkPartitionId,String instanceId,String partitionId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + groupId + "String_Node_Str"+ appId);
  }
  GroupInstance instance=null;
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return instance;
  }
  Group group=application.getGroupRecursively(groupId);
  if (group == null) {
    log.warn(String.format("String_Node_Str",groupId));
    return instance;
  }
  GroupStatus status=GroupStatus.Created;
  if (!group.containsInstanceContext(instanceId)) {
    instance=new GroupInstance(groupId,instanceId);
    instance.setParentId(parentId);
    instance.setPartitionId(partitionId);
    instance.setNetworkPartitionId(networkPartitionId);
    instance.setStatus(status);
    group.addInstance(instanceId,instance);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendGroupInstanceCreatedEvent(appId,groupId,instance);
  }
 else {
    log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
  }
  return instance;
}
Program: 116186
Project: 116186
Buggy source:
/** 
 * Creates the group instance and adds the required context objects
 * @param group                             the group
 * @param parentInstanceContext             the parent instance context
 * @param partitionContext
 * @param groupLevelNetworkPartitionContext the group level network partition context
 */
private String createGroupInstanceAndAddToMonitor(Group group,Instance parentInstanceContext,PartitionContext partitionContext,GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext,GroupInstance groupInstance){
  String partitionId;
  if (groupInstance == null) {
    partitionId=partitionContext.getPartitionId();
    groupInstance=createGroupInstance(group,parentInstanceContext.getInstanceId(),partitionId,parentInstanceContext.getNetworkPartitionId());
  }
  this.addInstance(groupInstance);
  String instanceId=groupInstance.getInstanceId();
  GroupInstanceContext groupInstanceContext=new GroupInstanceContext(instanceId);
  groupInstanceContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
  groupLevelNetworkPartitionContext.addInstanceContext(groupInstanceContext);
  if (partitionContext != null) {
    ((GroupLevelPartitionContext)partitionContext).addActiveInstance(groupInstance);
  }
  return instanceId;
}

Fixed version (ground truth):
/** 
 * Creates the group instance and adds the required context objects
 * @param group                             the group
 * @param parentInstanceContext             the parent instance context
 * @param partitionContext
 * @param groupLevelNetworkPartitionContext the group level network partition context
 */
private String createGroupInstanceAndAddToMonitor(Group group,Instance parentInstanceContext,PartitionContext partitionContext,GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext,GroupInstance groupInstance){
  String partitionId;
  if (groupInstance == null) {
    partitionId=partitionContext.getPartitionId();
    groupInstance=createGroupInstance(group,parentInstanceContext.getNetworkPartitionId(),parentInstanceContext.getInstanceId(),partitionId);
  }
  this.addInstance(groupInstance);
  String instanceId=groupInstance.getInstanceId();
  GroupInstanceContext groupInstanceContext=new GroupInstanceContext(instanceId);
  groupInstanceContext.addPartitionContext((GroupLevelPartitionContext)partitionContext);
  groupLevelNetworkPartitionContext.addInstanceContext(groupInstanceContext);
  if (partitionContext != null) {
    ((GroupLevelPartitionContext)partitionContext).addActiveInstance(groupInstance);
  }
  return instanceId;
}
Program: 116187
Project: 116187
Buggy source:
/** 
 * This will create the group instance in the applications Topology
 * @param group
 * @param parentInstanceId
 * @param partitionId
 * @param networkPartitionId
 * @return
 */
private GroupInstance createGroupInstance(Group group,String parentInstanceId,String partitionId,String networkPartitionId){
  String instanceId=parentInstanceId;
  int minGroupInstances=group.getGroupMinInstances();
  int maxGroupInstances=group.getGroupMaxInstances();
  if (minGroupInstances > 1 || maxGroupInstances > 1) {
    instanceId=this.generateInstanceId(group);
  }
  return ApplicationBuilder.handleGroupInstanceCreatedEvent(appId,group.getUniqueIdentifier(),instanceId,parentInstanceId,networkPartitionId,partitionId);
}

Fixed version (ground truth):
/** 
 * This will create the group instance in the applications Topology
 * @param group
 * @param parentInstanceId
 * @param partitionId
 * @param networkPartitionId
 * @return
 */
private GroupInstance createGroupInstance(Group group,String networkPartitionId,String parentInstanceId,String partitionId){
  String instanceId=parentInstanceId;
  int minGroupInstances=group.getGroupMinInstances();
  int maxGroupInstances=group.getGroupMaxInstances();
  if (minGroupInstances > 1 || maxGroupInstances > 1) {
    instanceId=this.generateInstanceId(group);
  }
  return ApplicationBuilder.handleGroupInstanceCreatedEvent(appId,group.getUniqueIdentifier(),parentInstanceId,networkPartitionId,instanceId,partitionId);
}
Program: 116188
Project: 116188
Buggy source:
private boolean doProcess(GroupInstanceCreatedEvent event,Applications applications){
  Application application=applications.getApplication(event.getAppId());
  if (application == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getAppId()));
    }
    return false;
  }
  Group group=application.getGroupRecursively(event.getGroupId());
  if (group == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getAppId(),event.getGroupId()));
      return false;
    }
  }
 else {
    String instanceId=event.getGroupInstance().getInstanceId();
    GroupInstance context=group.getInstanceContexts(instanceId);
    if (context == null) {
      if (log.isWarnEnabled()) {
        log.warn(String.format("String_Node_Str" + "String_Node_Str",event.getAppId(),event.getGroupId(),instanceId));
        return false;
      }
    }
    group.addInstance(instanceId,event.getGroupInstance());
  }
  notifyEventListeners(event);
  return true;
}

Fixed version (ground truth):
private boolean doProcess(GroupInstanceCreatedEvent event,Applications applications){
  Application application=applications.getApplication(event.getAppId());
  if (application == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getAppId()));
    }
    return false;
  }
  Group group=application.getGroupRecursively(event.getGroupId());
  if (group == null) {
    if (log.isWarnEnabled()) {
      log.warn(String.format("String_Node_Str",event.getAppId(),event.getGroupId()));
      return false;
    }
  }
 else {
    String instanceId=event.getGroupInstance().getInstanceId();
    GroupInstance context=group.getInstanceContexts(instanceId);
    if (context != null) {
      if (log.isWarnEnabled()) {
        log.warn(String.format("String_Node_Str" + "String_Node_Str",event.getAppId(),event.getGroupId(),instanceId));
        return false;
      }
    }
    group.addInstance(instanceId,event.getGroupInstance());
  }
  notifyEventListeners(event);
  return true;
}
Program: 116190
Project: 116190
Buggy source:
public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event){
  TopologyManager.acquireWriteLock();
  try {
    Topology topology=TopologyManager.getTopology();
    Cluster cluster=topology.getService(event.getServiceName()).getCluster(event.getClusterId());
    if (!cluster.isStateTransitionValid(ClusterStatus.Terminating,event.getInstanceId())) {
      log.error("String_Node_Str" + cluster.getStatus(event.getInstanceId()) + "String_Node_Str"+ ClusterStatus.Terminating);
    }
    ClusterInstance context=cluster.getInstanceContexts(event.getInstanceId());
    if (context == null) {
      log.warn("String_Node_Str" + event.getClusterId() + "String_Node_Str"+ event.getInstanceId());
      return;
    }
    ClusterStatus status=ClusterStatus.Terminating;
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      log.info("String_Node_Str" + cluster.getClusterId());
      TopologyManager.updateTopology(topology);
      ClusterTerminatingEvent clusterTerminaingEvent=new ClusterTerminatingEvent(event.getAppId(),event.getServiceName(),event.getClusterId(),null);
      TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
    }
 else {
      log.warn(String.format("String_Node_Str" + "String_Node_Str",event.getClusterId(),event.getInstanceId(),context.getStatus(),status));
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}

Fixed version (ground truth):
public static void handleClusterTerminatingEvent(ClusterStatusClusterTerminatingEvent event){
  TopologyManager.acquireWriteLock();
  try {
    Topology topology=TopologyManager.getTopology();
    Cluster cluster=topology.getService(event.getServiceName()).getCluster(event.getClusterId());
    if (!cluster.isStateTransitionValid(ClusterStatus.Terminating,event.getInstanceId())) {
      log.error("String_Node_Str" + cluster.getStatus(event.getInstanceId()) + "String_Node_Str"+ ClusterStatus.Terminating);
    }
    ClusterInstance context=cluster.getInstanceContexts(event.getInstanceId());
    if (context == null) {
      log.warn("String_Node_Str" + event.getClusterId() + "String_Node_Str"+ event.getInstanceId());
      return;
    }
    ClusterStatus status=ClusterStatus.Terminating;
    if (context.isStateTransitionValid(status)) {
      context.setStatus(status);
      log.info("String_Node_Str" + cluster.getClusterId());
      TopologyManager.updateTopology(topology);
      ClusterTerminatingEvent clusterTerminaingEvent=new ClusterTerminatingEvent(event.getAppId(),event.getServiceName(),event.getClusterId(),event.getInstanceId());
      TopologyEventPublisher.sendClusterTerminatingEvent(clusterTerminaingEvent);
    }
 else {
      log.warn(String.format("String_Node_Str" + "String_Node_Str",event.getClusterId(),event.getInstanceId(),context.getStatus(),status));
    }
  }
  finally {
    TopologyManager.releaseWriteLock();
  }
}
Program: 116191
Project: 116191
Buggy source:
/** 
 * Gets the parent instance context.
 * @param parentInstanceId the parent instance id
 * @return the parent instance context
 */
private Instance getParentInstanceContext(String parentInstanceId){
  Instance parentInstanceContext;
  Application application=ApplicationHolder.getApplications().getApplication(this.appId);
  if (this.id.equals(appId)) {
    parentInstanceContext=application.getInstanceContexts(parentInstanceId);
  }
 else {
    Group parentGroup=application.getGroupRecursively(this.parent.getId());
    parentInstanceContext=parentGroup.getInstanceContexts(parentInstanceId);
  }
  return parentInstanceContext;
}

Fixed version (ground truth):
/** 
 * Gets the parent instance context.
 * @param parentInstanceId the parent instance id
 * @return the parent instance context
 */
private Instance getParentInstanceContext(String parentInstanceId){
  Instance parentInstanceContext;
  Application application=ApplicationHolder.getApplications().getApplication(this.appId);
  if (this.parent.getId().equals(appId)) {
    parentInstanceContext=application.getInstanceContexts(parentInstanceId);
  }
 else {
    Group parentGroup=application.getGroupRecursively(this.parent.getId());
    parentInstanceContext=parentGroup.getInstanceContexts(parentInstanceId);
  }
  return parentInstanceContext;
}
Program: 116194
Project: 116194
Buggy source:
/** 
 * Retrieves InstanceContext obj. for the given instance id
 * @param parentInstanceId parent instance id
 * @return InstanceContext obj. if exists, else null
 */
public List<Instance> getInstanceContextsWithParentId(String parentInstanceId){
  if (getInstanceIdToInstanceContextMap().isEmpty()) {
    return null;
  }
  List<Instance> contexts=new ArrayList<Instance>();
  if (parentInstanceId == null) {
    for (    Instance context : instanceIdToInstanceContextMap.values()) {
      if (parentInstanceId.equals(context.getParentId())) {
        contexts.add(context);
      }
    }
  }
  return contexts;
}

Fixed version (ground truth):
/** 
 * Retrieves InstanceContext obj. for the given instance id
 * @param parentInstanceId parent instance id
 * @return InstanceContext obj. if exists, else null
 */
public List<Instance> getInstanceContextsWithParentId(String parentInstanceId){
  List<Instance> contexts=new ArrayList<Instance>();
  if (getInstanceIdToInstanceContextMap().isEmpty()) {
    return contexts;
  }
  if (parentInstanceId == null) {
    for (    Instance context : instanceIdToInstanceContextMap.values()) {
      if (parentInstanceId.equals(context.getParentId())) {
        contexts.add(context);
      }
    }
  }
  return contexts;
}
Program: 116195
Project: 116195
Buggy source:
public static void sendClusterActivatedEvent(String appId,String serviceName,String clusterId,String instanceId){
  TopologyManager.acquireReadLockForCluster(serviceName,clusterId);
  try {
    Service service=TopologyManager.getTopology().getService(serviceName);
    if (service != null) {
      Cluster cluster=service.getCluster(clusterId);
      ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
      if (clusterInstance.isStateTransitionValid(ClusterStatus.Active) && clusterInstance.getStatus() != ClusterStatus.Active) {
        ClusterStatusClusterActivatedEvent clusterActivatedEvent=new ClusterStatusClusterActivatedEvent(appId,serviceName,clusterId,"String_Node_Str");
        publishEvent(clusterActivatedEvent);
      }
 else {
        log.warn("String_Node_Str" + clusterId);
      }
    }
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}

Fixed version (ground truth):
public static void sendClusterActivatedEvent(String appId,String serviceName,String clusterId,String instanceId){
  TopologyManager.acquireReadLockForCluster(serviceName,clusterId);
  try {
    Service service=TopologyManager.getTopology().getService(serviceName);
    if (service != null) {
      Cluster cluster=service.getCluster(clusterId);
      ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
      if (clusterInstance.isStateTransitionValid(ClusterStatus.Active) && clusterInstance.getStatus() != ClusterStatus.Active) {
        ClusterStatusClusterActivatedEvent clusterActivatedEvent=new ClusterStatusClusterActivatedEvent(appId,serviceName,clusterId,instanceId);
        publishEvent(clusterActivatedEvent);
      }
 else {
        log.warn("String_Node_Str" + clusterId);
      }
    }
  }
  finally {
    TopologyManager.releaseReadLockForCluster(serviceName,clusterId);
  }
}
Program: 116196
Project: 116196
Buggy source:
private boolean getClusterInactive(String instanceId,VMClusterMonitor monitor){
  boolean clusterInActive=false;
  for (  ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext : monitor.getAllNetworkPartitionCtxts().values()) {
    ClusterInstanceContext instanceContext=clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
    if (instanceContext != null) {
      if (instanceContext.getActiveMembers() < instanceContext.getMaxInstanceCount()) {
        clusterInActive=true;
      }
    }
  }
  return clusterInActive;
}

Fixed version (ground truth):
private boolean getClusterInactive(String instanceId,VMClusterMonitor monitor){
  boolean clusterInActive=false;
  for (  ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext : monitor.getAllNetworkPartitionCtxts().values()) {
    ClusterInstanceContext instanceContext=clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
    if (instanceContext != null) {
      if (instanceContext.getActiveMembers() < instanceContext.getMinInstanceCount()) {
        clusterInActive=true;
      }
    }
  }
  return clusterInActive;
}
Program: 116197
Project: 116197
Buggy source:
@Override public boolean process(String type,String clusterId,String instanceId){
  boolean statusChanged;
  if (type == null || (ClusterStatusTerminatedProcessor.class.getName().equals(type))) {
    statusChanged=doProcess(clusterId,instanceId);
    if (statusChanged) {
      return statusChanged;
    }
  }
 else {
    if (nextProcessor != null) {
      return nextProcessor.process(null,clusterId,instanceId);
    }
 else {
      throw new RuntimeException(String.format("String_Node_Str" + "String_Node_Str",type,clusterId,instanceId));
    }
  }
  return false;
}

Fixed version (ground truth):
@Override public boolean process(String type,String clusterId,String instanceId){
  boolean statusChanged;
  if (type == null || (ClusterStatusTerminatedProcessor.class.getName().equals(type))) {
    statusChanged=doProcess(clusterId,instanceId);
    if (statusChanged) {
      return statusChanged;
    }
  }
 else {
    if (nextProcessor != null) {
      return nextProcessor.process(type,clusterId,instanceId);
    }
 else {
      throw new RuntimeException(String.format("String_Node_Str" + "String_Node_Str",type,clusterId,instanceId));
    }
  }
  return false;
}
Program: 116199
Project: 116199
Buggy source:
public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext,String clusterId,String instanceId,boolean isPrimary){
  try {
    String nwPartitionId=clusterMonitorPartitionContext.getNetworkPartitionId();
    int minimumCountOfNetworkPartition=0;
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)AutoscalerContext.getInstance().getClusterMonitor(clusterId);
    VMClusterContext clusterContext=(VMClusterContext)vmClusterMonitor.getClusterContext();
    ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext=clusterContext.getNetworkPartitionCtxt(nwPartitionId);
    ClusterInstanceContext clusterInstanceContext=clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
    minimumCountOfNetworkPartition=clusterInstanceContext.getMinInstanceCount();
    MemberContext memberContext=CloudControllerClient.getInstance().spawnAnInstance(clusterMonitorPartitionContext.getPartition(),clusterId,instanceId,clusterMonitorPartitionContext.getNetworkPartitionId(),isPrimary,minimumCountOfNetworkPartition);
    if (memberContext != null) {
      clusterMonitorPartitionContext.addPendingMember(memberContext);
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",memberContext.getMemberId(),memberContext.getPartition().getId()));
      }
    }
 else     if (log.isDebugEnabled()) {
      log.debug("String_Node_Str");
    }
  }
 catch (  Throwable e) {
    String message="String_Node_Str";
    log.error(message,e);
    throw new RuntimeException(message,e);
  }
}

Fixed version (ground truth):
public void delegateSpawn(ClusterLevelPartitionContext clusterMonitorPartitionContext,String clusterId,String instanceId,boolean isPrimary){
  try {
    String nwPartitionId=clusterMonitorPartitionContext.getNetworkPartitionId();
    int minimumCountOfNetworkPartition=0;
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)AutoscalerContext.getInstance().getClusterMonitor(clusterId);
    VMClusterContext clusterContext=(VMClusterContext)vmClusterMonitor.getClusterContext();
    ClusterLevelNetworkPartitionContext clusterLevelNetworkPartitionContext=clusterContext.getNetworkPartitionCtxt(nwPartitionId);
    ClusterInstanceContext clusterInstanceContext=clusterLevelNetworkPartitionContext.getClusterInstanceContext(instanceId);
    minimumCountOfNetworkPartition=clusterInstanceContext.getMinInstanceCount();
    MemberContext memberContext=CloudControllerClient.getInstance().spawnAnInstance(clusterMonitorPartitionContext.getPartition(),clusterId,clusterMonitorPartitionContext.getNetworkPartitionId(),instanceId,isPrimary,minimumCountOfNetworkPartition);
    if (memberContext != null) {
      clusterMonitorPartitionContext.addPendingMember(memberContext);
      if (log.isDebugEnabled()) {
        log.debug(String.format("String_Node_Str",memberContext.getMemberId(),memberContext.getPartition().getId()));
      }
    }
 else     if (log.isDebugEnabled()) {
      log.debug("String_Node_Str");
    }
  }
 catch (  Throwable e) {
    String message="String_Node_Str";
    log.error(message,e);
    throw new RuntimeException(message,e);
  }
}
Program: 116200
Project: 116200
Buggy source:
public ClusterInstanceContext(String clusterInstanceId,String partitionAlgo,int min,int max,String networkPartitionId){
  super(clusterInstanceId);
  this.networkPartitionId=networkPartitionId;
  this.setMinMembers(min);
  partitionCtxts=new ArrayList<ClusterLevelPartitionContext>();
  this.partitionAlgorithm=partitionAlgo;
  requestsInFlight=new RequestsInFlight();
  loadAverage=new LoadAverage();
  memoryConsumption=new MemoryConsumption();
  maxInstanceCount=max;
  requiredInstanceCountBasedOnStats=minInstanceCount;
  requiredInstanceCountBasedOnDependencies=minInstanceCount;
}

Fixed version (ground truth):
public ClusterInstanceContext(String clusterInstanceId,String partitionAlgo,int min,int max,String networkPartitionId){
  super(clusterInstanceId);
  this.networkPartitionId=networkPartitionId;
  this.minInstanceCount=min;
  this.maxInstanceCount=max;
  partitionCtxts=new ArrayList<ClusterLevelPartitionContext>();
  this.partitionAlgorithm=partitionAlgo;
  requestsInFlight=new RequestsInFlight();
  loadAverage=new LoadAverage();
  memoryConsumption=new MemoryConsumption();
  requiredInstanceCountBasedOnStats=minInstanceCount;
  requiredInstanceCountBasedOnDependencies=minInstanceCount;
}
Program: 116203
Project: 116203
Buggy source:
/** 
 * Triggered when a status event is received from the parent.
 * @param statusEvent
 */
public abstract void onParentStatusEvent(MonitorStatusEvent statusEvent) throws ParentMonitorNotFoundException ;

Fixed version (ground truth):
/** 
 * Triggered when a status event is received from the parent.
 * @param statusEvent
 */
public abstract void onParentStatusEvent(MonitorStatusEvent statusEvent) throws MonitorNotFoundException ;
Program: 116205
Project: 116205
Buggy source:
/** 
 * To set the status of the application monitor
 * @param status the status
 */
public void setStatus(ApplicationStatus status,String instanceId){
  this.applicationInstanceIdMap.get(instanceId).setStatus(status);
  try {
    MonitorStatusEventBuilder.notifyChildren(this,new ApplicationStatusEvent(status,appId,instanceId));
  }
 catch (  ParentMonitorNotFoundException e) {
    log.error("String_Node_Str" + appId,e);
  }
}

Fixed version (ground truth):
/** 
 * To set the status of the application monitor
 * @param status the status
 */
public void setStatus(ApplicationStatus status,String instanceId){
  this.applicationInstanceIdMap.get(instanceId).setStatus(status);
  try {
    MonitorStatusEventBuilder.notifyChildren(this,new ApplicationStatusEvent(status,appId,instanceId));
  }
 catch (  MonitorNotFoundException e) {
    log.error("String_Node_Str" + appId,e);
  }
}