nus-yam/ex-repair huggingface dataset:
Program: 116022
Project: 116022
Buggy source:
public synchronized void monitor(){
  final Collection<NetworkPartitionContext> networkPartitionContexts=this.networkPartitionCtxts.values();
  Runnable monitoringRunnable=new Runnable(){
    @Override public void run(){
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + appId + "String_Node_Str");
      }
      for (      NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
        for (        InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
          ApplicationInstance instance=(ApplicationInstance)instanceIdToInstanceMap.get(instanceContext.getId());
          if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
            if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
              handleScalingMaxOut(networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingEvent().isEmpty()) {
              handleDependentScaling(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingDownBeyondMinEvent().isEmpty()) {
              handleScalingDownBeyondMin(instanceContext,networkPartitionContext);
            }
          }
        }
      }
    }
  }
;
  monitoringRunnable.run();
}

Fixed version (ground truth):
public synchronized void monitor(){
  final Collection<NetworkPartitionContext> networkPartitionContexts=this.networkPartitionCtxts.values();
  Runnable monitoringRunnable=new Runnable(){
    @Override public void run(){
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + appId + "String_Node_Str");
      }
      for (      NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
        for (        InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
          ApplicationInstance instance=(ApplicationInstance)instanceIdToInstanceMap.get(instanceContext.getId());
          if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
            if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
              handleScalingMaxOut(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingEvent().isEmpty()) {
              handleDependentScaling(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingDownBeyondMinEvent().isEmpty()) {
              handleScalingDownBeyondMin(instanceContext,networkPartitionContext);
            }
          }
        }
      }
    }
  }
;
  monitoringRunnable.run();
}
Program: 116023
Project: 116023
Buggy source:
private void handleScalingDownBeyondMin(InstanceContext instanceContext,NetworkPartitionContext nwPartitionContext){
  boolean allChildrenScaleDown=false;
  for (  Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
    if (instanceContext.getScalingDownBeyondMinEvent(monitor.getId()) == null) {
      allChildrenScaleDown=false;
      break;
    }
 else {
      allChildrenScaleDown=true;
    }
  }
  if (allChildrenScaleDown) {
    ApplicationBuilder.handleApplicationInstanceTerminatingEvent(this.appId,instanceContext.getId());
  }
  instanceContext.setIdToScalingDownBeyondMinEvent(new HashMap<String,ScalingDownBeyondMinEvent>());
}

Fixed version (ground truth):
private void handleScalingDownBeyondMin(InstanceContext instanceContext,NetworkPartitionContext nwPartitionContext){
  boolean allChildrenScaleDown=false;
  for (  Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
    if (instanceContext.getScalingDownBeyondMinEvent(monitor.getId()) == null) {
      allChildrenScaleDown=false;
      break;
    }
 else {
      allChildrenScaleDown=true;
    }
  }
  if (allChildrenScaleDown) {
    ApplicationBuilder.handleApplicationInstanceTerminatingEvent(this.appId,instanceContext.getId());
  }
  instanceContext.setIdToScalingDownBeyondMinEvent(new ConcurrentHashMap<String,ScalingDownBeyondMinEvent>());
}
Program: 116024
Project: 116024
Buggy source:
private void handleScalingMaxOut(NetworkPartitionContext networkPartitionContext,InstanceContext instanceContext){
  if (!hasScalingDependents) {
    createGroupInstanceOnScaling(networkPartitionContext,instanceContext.getParentInstanceId());
  }
 else {
    notifyParentOnMaxOut(networkPartitionContext,instanceContext);
  }
  instanceContext.setIdToScalingOverMaxEvent(new HashMap<String,ScalingUpBeyondMaxEvent>());
}

Fixed version (ground truth):
private void handleScalingMaxOut(InstanceContext instanceContext,NetworkPartitionContext networkPartitionContext){
  if (!hasScalingDependents) {
    createGroupInstanceOnScaling(networkPartitionContext,instanceContext.getParentInstanceId());
  }
 else {
    notifyParentOnMaxOut(networkPartitionContext,instanceContext);
  }
  instanceContext.setIdToScalingOverMaxEvent(new ConcurrentHashMap<String,ScalingUpBeyondMaxEvent>());
}
Program: 116025
Project: 116025
Buggy source:
public synchronized void monitor(){
  final Collection<NetworkPartitionContext> networkPartitionContexts=this.networkPartitionCtxts.values();
  Runnable monitoringRunnable=new Runnable(){
    @Override public void run(){
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + id + "String_Node_Str");
      }
      for (      NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
        for (        InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
          GroupInstance instance=(GroupInstance)instanceIdToInstanceMap.get(instanceContext.getId());
          if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
            if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
              handleScalingMaxOut(networkPartitionContext,instanceContext);
            }
 else             if (!instanceContext.getIdToScalingEvent().isEmpty()) {
              handleDependentScaling(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingDownBeyondMinEvent().isEmpty()) {
              handleScalingDownBeyondMin(instanceContext,networkPartitionContext);
            }
          }
        }
      }
    }
  }
;
  monitoringRunnable.run();
}

Fixed version (ground truth):
public synchronized void monitor(){
  final Collection<NetworkPartitionContext> networkPartitionContexts=this.networkPartitionCtxts.values();
  Runnable monitoringRunnable=new Runnable(){
    @Override public void run(){
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + id + "String_Node_Str");
      }
      for (      NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
        for (        InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
          GroupInstance instance=(GroupInstance)instanceIdToInstanceMap.get(instanceContext.getId());
          if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
            if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
              handleScalingMaxOut(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingEvent().isEmpty()) {
              handleDependentScaling(instanceContext,networkPartitionContext);
            }
 else             if (!instanceContext.getIdToScalingDownBeyondMinEvent().isEmpty()) {
              handleScalingDownBeyondMin(instanceContext,networkPartitionContext);
            }
          }
        }
      }
    }
  }
;
  monitoringRunnable.run();
}
Program: 116030
Project: 116030
Buggy source:
private void startInstanceNotifierReceiver(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  final InstanceNotifierEventReceiver instanceNotifierEventReceiver=new InstanceNotifierEventReceiver();
  instanceNotifierEventReceiver.addEventListener(new InstanceCleanupClusterEventListener(){
    @Override protected void onEvent(    Event event){
      InstanceCleanupClusterEvent instanceCleanupClusterEvent=(InstanceCleanupClusterEvent)event;
      if (mockMemberContext.getClusterId().equals(instanceCleanupClusterEvent.getClusterId()) && mockMemberContext.getInstanceId().equals(instanceCleanupClusterEvent.getInstanceId())) {
        handleMemberTermination();
      }
    }
  }
);
  instanceNotifierEventReceiver.addEventListener(new InstanceCleanupMemberEventListener(){
    @Override protected void onEvent(    Event event){
      InstanceCleanupMemberEvent instanceCleanupClusterEvent=(InstanceCleanupMemberEvent)event;
      if (mockMemberContext.getMemberId().equals(instanceCleanupClusterEvent.getMemberId())) {
        handleMemberTermination();
      }
    }
  }
);
  instanceNotifierExecutorService.submit(new Runnable(){
    @Override public void run(){
      instanceNotifierEventReceiver.execute();
    }
  }
);
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
}

Fixed version (ground truth):
private void startInstanceNotifierReceiver(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  final InstanceNotifierEventReceiver instanceNotifierEventReceiver=new InstanceNotifierEventReceiver();
  instanceNotifierEventReceiver.addEventListener(new InstanceCleanupClusterEventListener(){
    @Override protected void onEvent(    Event event){
      InstanceCleanupClusterEvent instanceCleanupClusterEvent=(InstanceCleanupClusterEvent)event;
      if (mockMemberContext.getClusterId().equals(instanceCleanupClusterEvent.getClusterId()) && mockMemberContext.getClusterInstanceId().equals(instanceCleanupClusterEvent.getClusterInstanceId())) {
        handleMemberTermination();
      }
    }
  }
);
  instanceNotifierEventReceiver.addEventListener(new InstanceCleanupMemberEventListener(){
    @Override protected void onEvent(    Event event){
      InstanceCleanupMemberEvent instanceCleanupClusterEvent=(InstanceCleanupMemberEvent)event;
      if (mockMemberContext.getMemberId().equals(instanceCleanupClusterEvent.getMemberId())) {
        handleMemberTermination();
      }
    }
  }
);
  instanceNotifierExecutorService.submit(new Runnable(){
    @Override public void run(){
      instanceNotifierEventReceiver.execute();
    }
  }
);
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
}
Program: 116031
Project: 116031
Buggy source:
public InstanceCleanupClusterEvent(String clusterId,String instanceId){
  this.clusterId=clusterId;
  this.instanceId=instanceId;
}

Fixed version (ground truth):
public InstanceCleanupClusterEvent(String clusterId,String instanceId){
  this.clusterId=clusterId;
  this.clusterInstanceId=instanceId;
}
Program: 116032
Project: 116032
Buggy source:
/** 
 * Gets the group level network partition context.
 * @param parentInstanceContext the parent instance context
 * @return the group level network partition context
 */
private GroupLevelNetworkPartitionContext getGroupLevelNetworkPartitionContext(String groupId,String appId,Instance parentInstanceContext){
  GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext;
  ChildPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(appId).getChildPolicy(groupId);
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  if (this.networkPartitionCtxts.containsKey(parentInstanceContext)) {
    groupLevelNetworkPartitionContext=(GroupLevelNetworkPartitionContext)this.networkPartitionCtxts.get(networkPartitionId);
  }
 else {
    if (policy != null) {
      ChildLevelNetworkPartition networkPartition=policy.getChildLevelNetworkPartition(parentInstanceContext.getNetworkPartitionId());
      groupLevelNetworkPartitionContext=new GroupLevelNetworkPartitionContext(networkPartitionId,networkPartition.getPartitionAlgo());
    }
 else {
      groupLevelNetworkPartitionContext=new GroupLevelNetworkPartitionContext(networkPartitionId);
    }
    if (log.isInfoEnabled()) {
      log.info("String_Node_Str" + networkPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
    }
    this.addNetworkPartitionContext(groupLevelNetworkPartitionContext);
  }
  return groupLevelNetworkPartitionContext;
}

Fixed version (ground truth):
/** 
 * Gets the group level network partition context.
 * @param parentInstanceContext the parent instance context
 * @return the group level network partition context
 */
private GroupLevelNetworkPartitionContext getGroupLevelNetworkPartitionContext(String groupId,String appId,Instance parentInstanceContext){
  GroupLevelNetworkPartitionContext groupLevelNetworkPartitionContext;
  ChildPolicy policy=PolicyManager.getInstance().getDeploymentPolicyByApplication(appId).getChildPolicy(groupId);
  String networkPartitionId=parentInstanceContext.getNetworkPartitionId();
  if (this.networkPartitionCtxts.containsKey(networkPartitionId)) {
    groupLevelNetworkPartitionContext=(GroupLevelNetworkPartitionContext)this.networkPartitionCtxts.get(networkPartitionId);
  }
 else {
    if (policy != null) {
      ChildLevelNetworkPartition networkPartition=policy.getChildLevelNetworkPartition(parentInstanceContext.getNetworkPartitionId());
      groupLevelNetworkPartitionContext=new GroupLevelNetworkPartitionContext(networkPartitionId,networkPartition.getPartitionAlgo());
    }
 else {
      groupLevelNetworkPartitionContext=new GroupLevelNetworkPartitionContext(networkPartitionId);
    }
    if (log.isInfoEnabled()) {
      log.info("String_Node_Str" + networkPartitionId + "String_Node_Str"+ "String_Node_Str"+ this.id);
    }
    this.addNetworkPartitionContext(groupLevelNetworkPartitionContext);
  }
  return groupLevelNetworkPartitionContext;
}
Program: 116034
Project: 116034
Buggy source:
private static void updateApplicationMonitor(String appId,ApplicationStatus status,String instanceId){
  ApplicationMonitor applicationMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
  if (applicationMonitor != null) {
    if (status == ApplicationStatus.Terminating) {
      applicationMonitor.setTerminating(true);
    }
    applicationMonitor.setStatus(status,instanceId);
  }
 else {
    log.warn("String_Node_Str" + appId);
  }
}

Fixed version (ground truth):
private static void updateApplicationMonitor(String appId,ApplicationStatus status,String networkPartitionId,String instanceId){
  ApplicationMonitor applicationMonitor=AutoscalerContext.getInstance().getAppMonitor(appId);
  if (applicationMonitor != null) {
    if (status == ApplicationStatus.Active) {
      applicationMonitor.getNetworkPartitionContext(networkPartitionId).movePendingInstanceToActiveInstances(instanceId);
    }
 else     if (status == ApplicationStatus.Terminating) {
      applicationMonitor.setTerminating(true);
      NetworkPartitionContext context=applicationMonitor.getNetworkPartitionContext(networkPartitionId);
      if (context.getActiveInstance(instanceId) != null) {
        context.moveActiveInstanceToTerminationPendingInstances(instanceId);
      }
 else       if (context.getPendingInstance(instanceId) != null) {
        context.movePendingInstanceToTerminationPendingInstances(instanceId);
      }
    }
    applicationMonitor.setStatus(status,instanceId);
  }
 else {
    log.warn("String_Node_Str" + appId);
  }
}
Program: 116037
Project: 116037
Buggy source:
public static void handleApplicationInstanceInactivateEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId + "String_Node_Str"+ instanceId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  ApplicationStatus status=ApplicationStatus.Inactive;
  ApplicationInstance applicationInstance=application.getInstanceContexts(instanceId);
  if (applicationInstance.isStateTransitionValid(status)) {
    application.setStatus(status,instanceId);
    updateApplicationMonitor(appId,status,instanceId);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendApplicationInstanceInactivatedEvent(appId,instanceId);
  }
 else {
    log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId,applicationInstance.getStatus(),status));
  }
}

Fixed version (ground truth):
public static void handleApplicationInstanceInactivateEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId + "String_Node_Str"+ instanceId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  ApplicationStatus status=ApplicationStatus.Inactive;
  ApplicationInstance applicationInstance=application.getInstanceContexts(instanceId);
  if (applicationInstance.isStateTransitionValid(status)) {
    application.setStatus(status,instanceId);
    updateApplicationMonitor(appId,status,applicationInstance.getNetworkPartitionId(),instanceId);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendApplicationInstanceInactivatedEvent(appId,instanceId);
  }
 else {
    log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId,applicationInstance.getStatus(),status));
  }
}
Program: 116038
Project: 116038
Buggy source:
public static void handleApplicationInstanceActivatedEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId + "String_Node_Str"+ instanceId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  ApplicationStatus status=ApplicationStatus.Active;
  ApplicationInstance applicationInstance=application.getInstanceContexts(instanceId);
  if (applicationInstance.isStateTransitionValid(status)) {
    application.setStatus(status,instanceId);
    updateApplicationMonitor(appId,status,instanceId);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendApplicationInstanceActivatedEvent(appId,instanceId);
  }
 else {
    log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId,applicationInstance.getStatus(),status));
  }
}

Fixed version (ground truth):
public static void handleApplicationInstanceActivatedEvent(String appId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + appId + "String_Node_Str"+ instanceId);
  }
  Applications applications=ApplicationHolder.getApplications();
  Application application=applications.getApplication(appId);
  if (application == null) {
    log.warn(String.format("String_Node_Str",appId));
    return;
  }
  ApplicationStatus status=ApplicationStatus.Active;
  ApplicationInstance applicationInstance=application.getInstanceContexts(instanceId);
  if (applicationInstance.isStateTransitionValid(status)) {
    application.setStatus(status,instanceId);
    updateApplicationMonitor(appId,status,applicationInstance.getNetworkPartitionId(),instanceId);
    ApplicationHolder.persistApplication(application);
    ApplicationsEventPublisher.sendApplicationInstanceActivatedEvent(appId,instanceId);
  }
 else {
    log.warn(String.format("String_Node_Str" + "String_Node_Str",appId,instanceId,applicationInstance.getStatus(),status));
  }
}
Program: 116039
Project: 116039
Buggy source:
protected NetworkPartitionContext(String id){
  this.id=id;
  instanceIdToInstanceContextMap=new HashMap<String,InstanceContext>();
}

Fixed version (ground truth):
protected NetworkPartitionContext(String id){
  this.id=id;
  instanceIdToInstanceContextMap=new HashMap<String,InstanceContext>();
  pendingInstances=new ArrayList<InstanceContext>();
  activeInstances=new ArrayList<InstanceContext>();
  terminatingPending=new ArrayList<InstanceContext>();
}
Program: 116040
Project: 116040
Buggy source:
@Override public void run(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + this.toString());
  }
  for (  NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
    for (    InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
      ApplicationInstance instance=(ApplicationInstance)instanceIdToInstanceMap.get(instanceContext.getId());
      if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
        if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty() && networkPartitionContext.getPendingInstancesCount() > 0) {
          try {
            if (log.isInfoEnabled()) {
              log.info("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
            }
            createInstanceOnBurstingForApplication();
          }
 catch (          TopologyInConsistentException e) {
            log.error("String_Node_Str",e);
          }
catch (          PolicyValidationException e) {
            log.error("String_Node_Str",e);
          }
catch (          MonitorNotFoundException e) {
            log.error("String_Node_Str",e);
          }
        }
 else {
          handleDependentScaling(instanceContext,networkPartitionContext);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + this.toString());
  }
  for (  NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
    for (    InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
      ApplicationInstance instance=(ApplicationInstance)instanceIdToInstanceMap.get(instanceContext.getId());
      if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
        if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
          if (networkPartitionContext.getPendingInstancesCount() == 0) {
            try {
              if (log.isInfoEnabled()) {
                log.info("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
              }
              createInstanceOnBurstingForApplication();
            }
 catch (            TopologyInConsistentException e) {
              log.error("String_Node_Str",e);
            }
catch (            PolicyValidationException e) {
              log.error("String_Node_Str",e);
            }
catch (            MonitorNotFoundException e) {
              log.error("String_Node_Str",e);
            }
          }
 else {
            if (log.isDebugEnabled()) {
              log.debug("String_Node_Str" + "String_Node_Str");
            }
          }
        }
 else {
          handleDependentScaling(instanceContext,networkPartitionContext);
        }
      }
    }
  }
}
Program: 116042
Project: 116042
Buggy source:
private String handleApplicationInstanceCreation(Application application,ApplicationLevelNetworkPartitionContext context,ApplicationInstance instanceExist){
  ApplicationInstance instance;
  ApplicationInstanceContext instanceContext;
  if (instanceExist != null) {
    instance=instanceExist;
  }
 else {
    instance=createApplicationInstance(application,context.getId());
  }
  String instanceId=instance.getInstanceId();
  instanceContext=new ApplicationInstanceContext(instanceId);
  context.addInstanceContext(instanceContext);
  this.instanceIdToInstanceMap.put(instanceId,instance);
  this.networkPartitionCtxts.put(context.getId(),context);
  return instanceId;
}

Fixed version (ground truth):
private String handleApplicationInstanceCreation(Application application,ApplicationLevelNetworkPartitionContext context,ApplicationInstance instanceExist){
  ApplicationInstance instance;
  ApplicationInstanceContext instanceContext;
  if (instanceExist != null) {
    instance=instanceExist;
  }
 else {
    instance=createApplicationInstance(application,context.getId());
  }
  String instanceId=instance.getInstanceId();
  instanceContext=new ApplicationInstanceContext(instanceId);
  context.addInstanceContext(instanceContext);
  context.addPendingInstance(instanceContext);
  this.instanceIdToInstanceMap.put(instanceId,instance);
  this.networkPartitionCtxts.put(context.getId(),context);
  return instanceId;
}
Program: 116045
Project: 116045
Buggy source:
public static void addServiceGroup(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException {
  try {
    serviceGropingManager.deployServiceGroupDefinition(serviceGroupDefinition);
  }
 catch (  InvalidServiceGroupException e) {
    throw new RestAPIException(e);
  }
catch (  ServiceGroupDefinitioException e) {
    throw new RestAPIException(e);
  }
catch (  ADCException e) {
    throw new RestAPIException(e);
  }
catch (  CloudControllerServiceUnregisteredCartridgeExceptionException e) {
    throw new RestAPIException(e);
  }
  log.info("String_Node_Str" + serviceGroupDefinition.getName());
}

Fixed version (ground truth):
public static void addServiceGroup(ServiceGroupDefinition serviceGroupDefinition) throws RestAPIException {
  try {
    serviceGropingManager.deployServiceGroupDefinition(serviceGroupDefinition);
  }
 catch (  InvalidServiceGroupException e) {
    throw new RestAPIException(e);
  }
catch (  ServiceGroupDefinitioException e) {
    throw new RestAPIException(e);
  }
catch (  ADCException e) {
    throw new RestAPIException(e);
  }
catch (  CloudControllerServiceCartridgeNotFoundExceptionException e) {
    throw new RestAPIException(e);
  }
  log.info("String_Node_Str" + serviceGroupDefinition.getName());
}
Program: 116046
Project: 116046
Buggy source:
public static CartridgeDefinitionBean getCartridge(String cartridgeType) throws RestAPIException {
  try {
    CartridgeInfo cartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
    if (cartridgeInfo == null) {
      return null;
    }
    return convertCartridgeToCartridgeDefinitionBean(cartridgeInfo);
  }
 catch (  RemoteException e) {
    String message=e.getMessage();
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
catch (  CloudControllerServiceUnregisteredCartridgeExceptionException e) {
    String message=e.getMessage();
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
}

Fixed version (ground truth):
public static CartridgeDefinitionBean getCartridge(String cartridgeType) throws RestAPIException {
  try {
    CartridgeInfo cartridgeInfo=CloudControllerServiceClient.getServiceClient().getCartridgeInfo(cartridgeType);
    if (cartridgeInfo == null) {
      return null;
    }
    return convertCartridgeToCartridgeDefinitionBean(cartridgeInfo);
  }
 catch (  RemoteException e) {
    String message=e.getMessage();
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
catch (  CloudControllerServiceCartridgeNotFoundExceptionException e) {
    String message=e.getMessage();
    log.error(message,e);
    throw new RestAPIException(message,e);
  }
}
Program: 116047
Project: 116047
Buggy source:
public static ApplicationBean convertApplicationToApplicationBean(Application application){
  if (application == null) {
    return null;
  }
  ApplicationBean applicationBean=new ApplicationBean();
  applicationBean.setId(application.getUniqueIdentifier());
  applicationBean.setName(application.getName());
  applicationBean.setDescription(application.getDescription());
  applicationBean.setTenantDomain(application.getTenantDomain());
  applicationBean.setTenantAdminUsername(application.getTenantAdminUserName());
  applicationBean.setInstances(convertApplicationInstancesToInstances(application));
  return applicationBean;
}

Fixed version (ground truth):
public static ApplicationInfoBean convertApplicationToApplicationBean(Application application){
  if (application == null) {
    return null;
  }
  ApplicationInfoBean applicationBean=new ApplicationInfoBean();
  applicationBean.setId(application.getUniqueIdentifier());
  applicationBean.setName(application.getName());
  applicationBean.setDescription(application.getDescription());
  applicationBean.setTenantDomain(application.getTenantDomain());
  applicationBean.setTenantAdminUsername(application.getTenantAdminUserName());
  return applicationBean;
}
Program: 116051
Project: 116051
Buggy source:
/** 
 * This will create a new app monitor based on the give appId by getting the application from Topology
 * @param applicationId appId of the application which requires to create app monitor
 * @return ApplicationMonitor
 * @throws DependencyBuilderException    throws while building dependency for app monitor
 * @throws TopologyInConsistentException throws while traversing thr topology
 */
public static ApplicationMonitor getApplicationMonitor(String applicationId) throws DependencyBuilderException, TopologyInConsistentException, PolicyValidationException {
  ApplicationMonitor applicationMonitor;
  Application application;
  try {
    ApplicationHolder.acquireReadLock();
    application=ApplicationHolder.getApplications().getApplication(applicationId);
    if (application != null) {
      applicationMonitor=new ApplicationMonitor(application);
      applicationMonitor.setHasStartupDependents(false);
    }
 else {
      String msg="String_Node_Str" + applicationId;
      throw new TopologyInConsistentException(msg);
    }
  }
  finally {
    ApplicationHolder.releaseReadLock();
  }
  applicationMonitor.startMinimumDependencies(application);
  return applicationMonitor;
}

Fixed version (ground truth):
/** 
 * This will create a new app monitor based on the give appId by getting the application from Topology
 * @param applicationId appId of the application which requires to create app monitor
 * @return ApplicationMonitor
 * @throws DependencyBuilderException    throws while building dependency for app monitor
 * @throws TopologyInConsistentException throws while traversing thr topology
 */
public static ApplicationMonitor getApplicationMonitor(String applicationId) throws DependencyBuilderException, TopologyInConsistentException, PolicyValidationException {
  ApplicationMonitor applicationMonitor;
  Application application;
  try {
    ApplicationHolder.acquireReadLock();
    application=ApplicationHolder.getApplications().getApplication(applicationId);
    if (application != null) {
      applicationMonitor=new ApplicationMonitor(application);
      applicationMonitor.setHasStartupDependents(false);
      applicationMonitor.startScheduler();
    }
 else {
      String msg="String_Node_Str" + applicationId;
      throw new TopologyInConsistentException(msg);
    }
  }
  finally {
    ApplicationHolder.releaseReadLock();
  }
  applicationMonitor.startMinimumDependencies(application);
  return applicationMonitor;
}
Program: 116053
Project: 116053
Buggy source:
@Override public void run(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + this.toString());
  }
  for (  NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
    for (    InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
      GroupInstance instance=(GroupInstance)instanceIdToInstanceMap.get(instanceContext.getId());
      if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
        if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
          if (groupScalingEnabled) {
            boolean createOnDemand=createInstanceOnDemand(instanceContext.getParentInstanceId());
            if (!createOnDemand) {
              MonitorStatusEventBuilder.handleScalingOverMaxEvent(parent,networkPartitionContext.getId(),instanceContext.getId(),appId);
            }
 else {
              instanceContext.setIdToScalingOverMaxEvent(new HashMap<String,ScalingOverMaxEvent>());
            }
          }
 else {
            MonitorStatusEventBuilder.handleScalingOverMaxEvent(parent,networkPartitionContext.getId(),instanceContext.getId(),appId);
          }
        }
 else {
          handleDependentScaling(instanceContext,networkPartitionContext);
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void run(){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + this.toString());
  }
  for (  NetworkPartitionContext networkPartitionContext : networkPartitionContexts) {
    for (    InstanceContext instanceContext : networkPartitionContext.getInstanceIdToInstanceContextMap().values()) {
      GroupInstance instance=(GroupInstance)instanceIdToInstanceMap.get(instanceContext.getId());
      if (instance.getStatus().getCode() <= GroupStatus.Active.getCode()) {
        if (!instanceContext.getIdToScalingOverMaxEvent().isEmpty()) {
          if (groupScalingEnabled) {
            if (log.isDebugEnabled()) {
              log.debug("String_Node_Str" + id + "String_Node_Str"+ "String_Node_Str");
            }
            boolean createOnDemand=createInstanceOnDemand(instanceContext.getParentInstanceId());
            if (!createOnDemand) {
              MonitorStatusEventBuilder.handleScalingOverMaxEvent(parent,networkPartitionContext.getId(),instanceContext.getId(),appId);
            }
 else {
              instanceContext.setIdToScalingOverMaxEvent(new HashMap<String,ScalingOverMaxEvent>());
            }
          }
 else {
            MonitorStatusEventBuilder.handleScalingOverMaxEvent(parent,networkPartitionContext.getId(),instanceContext.getId(),appId);
          }
        }
 else {
          handleDependentScaling(instanceContext,networkPartitionContext);
        }
      }
    }
  }
}
Program: 116055
Project: 116055
Buggy source:
@Override public void onChildScalingOverMaxEvent(ScalingOverMaxEvent scalingOverMaxEvent){
  String networkPartitionId=scalingOverMaxEvent.getNetworkPartitionId();
  String instanceId=scalingOverMaxEvent.getInstanceId();
  String id=scalingOverMaxEvent.getId();
  NetworkPartitionContext networkPartitionContext=this.networkPartitionCtxts.get(networkPartitionId);
  if (networkPartitionContext != null) {
    InstanceContext instanceContext=networkPartitionContext.getInstanceContext(instanceId);
    if (instanceContext != null) {
      if (instanceContext.containsScalingEvent(id)) {
        instanceContext.removeScalingOverMaxEvent(id);
        instanceContext.addScalingOverMaxEvent(scalingOverMaxEvent);
      }
 else {
        instanceContext.addScalingOverMaxEvent(scalingOverMaxEvent);
      }
    }
  }
  this.monitor();
}

Fixed version (ground truth):
@Override public void onChildScalingOverMaxEvent(ScalingOverMaxEvent scalingOverMaxEvent){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + this.getId() + "String_Node_Str"+ scalingOverMaxEvent.getNetworkPartitionId()+ "String_Node_Str"+ scalingOverMaxEvent.getId()+ "String_Node_Str"+ "String_Node_Str"+ scalingOverMaxEvent.getInstanceId());
  }
  String networkPartitionId=scalingOverMaxEvent.getNetworkPartitionId();
  String instanceId=scalingOverMaxEvent.getInstanceId();
  String id=scalingOverMaxEvent.getId();
  NetworkPartitionContext networkPartitionContext=this.networkPartitionCtxts.get(networkPartitionId);
  if (networkPartitionContext != null) {
    InstanceContext instanceContext=networkPartitionContext.getInstanceContext(instanceId);
    if (instanceContext != null) {
      if (instanceContext.containsScalingEvent(id)) {
        instanceContext.removeScalingOverMaxEvent(id);
        instanceContext.addScalingOverMaxEvent(scalingOverMaxEvent);
      }
 else {
        instanceContext.addScalingOverMaxEvent(scalingOverMaxEvent);
      }
    }
  }
  this.monitor();
}
Program: 116057
Project: 116057
Buggy source:
public void delegateScalingDependencyNotification(String clusterId,String networkPartitionId,String instanceId,int requiredInstanceCount,int minimumInstanceCount){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterId);
  float factor=requiredInstanceCount / minimumInstanceCount;
  if (clusterMonitor instanceof VMClusterMonitor) {
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)clusterMonitor;
    vmClusterMonitor.sendClusterScalingEvent(networkPartitionId,instanceId,factor);
  }
}

Fixed version (ground truth):
public void delegateScalingDependencyNotification(String clusterId,String networkPartitionId,String instanceId,int requiredInstanceCount,int minimumInstanceCount){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + instanceId);
  }
  AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterId);
  float factor=requiredInstanceCount / minimumInstanceCount;
  if (clusterMonitor instanceof VMClusterMonitor) {
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)clusterMonitor;
    vmClusterMonitor.sendClusterScalingEvent(networkPartitionId,instanceId,factor);
  }
}
Program: 116058
Project: 116058
Buggy source:
public void delegateScalingOverMaxNotification(String clusterId,String networkPartitionId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str");
  }
  AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterId);
  if (clusterMonitor instanceof VMClusterMonitor) {
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)clusterMonitor;
    vmClusterMonitor.sendScalingOverMaxEvent(networkPartitionId,instanceId);
  }
}

Fixed version (ground truth):
public void delegateScalingOverMaxNotification(String clusterId,String networkPartitionId,String instanceId){
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + instanceId);
  }
  AbstractClusterMonitor clusterMonitor=AutoscalerContext.getInstance().getClusterMonitor(clusterId);
  if (clusterMonitor instanceof VMClusterMonitor) {
    VMClusterMonitor vmClusterMonitor=(VMClusterMonitor)clusterMonitor;
    vmClusterMonitor.sendScalingOverMaxEvent(networkPartitionId,instanceId);
  }
}
Program: 116059
Project: 116059
Buggy source:
public boolean verifyGroupStatus(String childId,String instanceId,GroupStatus requiredStatus){
  Monitor monitor=this.getMonitor(childId);
  List<String> groupInstances;
  GroupInstance groupInstance=(GroupInstance)monitor.getInstance(instanceId);
  if (groupInstance == null) {
    groupInstances=monitor.getInstancesByParentInstanceId(instanceId);
  }
 else {
    if (groupInstance.getStatus() == requiredStatus) {
      return true;
    }
 else {
      return false;
    }
  }
  String networkPartitionId=null;
  int noOfInstancesOfRequiredStatus=0;
  for (  String childInstanceId : groupInstances) {
    GroupInstance childGroupInstance=(GroupInstance)monitor.getInstance(childInstanceId);
    networkPartitionId=childGroupInstance.getNetworkPartitionId();
    if (childGroupInstance.getStatus() == requiredStatus) {
      noOfInstancesOfRequiredStatus++;
    }
    if (!groupInstances.isEmpty()) {
      GroupLevelNetworkPartitionContext networkPartitionContext=(GroupLevelNetworkPartitionContext)this.networkPartitionCtxts.get(networkPartitionId);
      int minInstances=networkPartitionContext.getMinInstanceCount();
      if (noOfInstancesOfRequiredStatus == this.inactiveInstancesMap.size() && requiredStatus == GroupStatus.Terminated) {
        return true;
      }
 else       if (noOfInstancesOfRequiredStatus >= minInstances) {
        return true;
      }
    }
  }
  return false;
}

Fixed version (ground truth):
public boolean verifyGroupStatus(String childId,String instanceId,GroupStatus requiredStatus){
  Monitor monitor=this.getMonitor(childId);
  List<String> groupInstances;
  GroupInstance groupInstance=(GroupInstance)monitor.getInstance(instanceId);
  if (groupInstance == null) {
    groupInstances=monitor.getInstancesByParentInstanceId(instanceId);
  }
 else {
    if (groupInstance.getStatus() == requiredStatus) {
      return true;
    }
 else {
      return false;
    }
  }
  String networkPartitionId=null;
  int noOfInstancesOfRequiredStatus=0;
  for (  String childInstanceId : groupInstances) {
    GroupInstance childGroupInstance=(GroupInstance)monitor.getInstance(childInstanceId);
    networkPartitionId=childGroupInstance.getNetworkPartitionId();
    if (childGroupInstance.getStatus() == requiredStatus) {
      noOfInstancesOfRequiredStatus++;
    }
  }
  if (!groupInstances.isEmpty()) {
    GroupLevelNetworkPartitionContext networkPartitionContext=(GroupLevelNetworkPartitionContext)this.networkPartitionCtxts.get(networkPartitionId);
    int minInstances=networkPartitionContext.getMinInstanceCount();
    if (noOfInstancesOfRequiredStatus == this.inactiveInstancesMap.size() && requiredStatus == GroupStatus.Terminated) {
      return true;
    }
 else     if (noOfInstancesOfRequiredStatus >= minInstances) {
      return true;
    }
 else {
      if (requiredStatus == GroupStatus.Inactive && noOfInstancesOfRequiredStatus >= 1) {
        return true;
      }
    }
  }
  return false;
}
Program: 116060
Project: 116060
Buggy source:
/** 
 * Creates a ApplicationClusterContext object to keep information related to a Cluster in this Application
 * @param appId Application id
 * @param groupName Group name
 * @param cartridgeInfo Cartridge information
 * @param subscriptionKey Generated key for the Application
 * @param tenantId Tenant Id of the tenant which deployed the Application
 * @param repoUrl Repository URL
 * @param alias alias specified for this Subscribable in the Application Definition
 * @param clusterId Cluster id
 * @param hostname Hostname
 * @param deploymentPolicy Deployment policy used
 * @param isLB if this cluster is an LB
 * @return ApplicationClusterContext object with relevant information
 * @throws ApplicationDefinitionException If any error occurs
 */
private ApplicationClusterContext createApplicationClusterContext(String appId,String groupName,CartridgeInfo cartridgeInfo,String subscriptionKey,int tenantId,String repoUrl,String alias,String clusterId,String hostname,String deploymentPolicy,boolean isLB,String[] dependencyAliases,Properties properties) throws ApplicationDefinitionException {
  PayloadData payloadData=ApplicationUtils.createPayload(appId,groupName,cartridgeInfo,subscriptionKey,tenantId,clusterId,hostname,repoUrl,alias,null,dependencyAliases,properties);
  String textPayload=payloadData.toString();
  return new ApplicationClusterContext(cartridgeInfo.getType(),clusterId,hostname,textPayload,deploymentPolicy,isLB);
}

Fixed version (ground truth):
/** 
 * Creates a ApplicationClusterContext object to keep information related to a Cluster in this Application
 * @param appId Application id
 * @param groupName Group name
 * @param cartridgeInfo Cartridge information
 * @param subscriptionKey Generated key for the Application
 * @param tenantId Tenant Id of the tenant which deployed the Application
 * @param repoUrl Repository URL
 * @param alias alias specified for this Subscribable in the Application Definition
 * @param clusterId Cluster id
 * @param hostname Hostname
 * @param deploymentPolicy Deployment policy used
 * @param isLB if this cluster is an LB
 * @return ApplicationClusterContext object with relevant information
 * @throws ApplicationDefinitionException If any error occurs
 */
private ApplicationClusterContext createApplicationClusterContext(String appId,String groupName,CartridgeInfo cartridgeInfo,String subscriptionKey,int tenantId,String repoUrl,String alias,String clusterId,String hostname,String deploymentPolicy,boolean isLB,String[] dependencyAliases,Properties properties) throws ApplicationDefinitionException {
  PayloadData payloadData=ApplicationUtils.createPayload(appId,groupName,cartridgeInfo,subscriptionKey,tenantId,clusterId,hostname,repoUrl,alias,null,dependencyAliases,properties);
  String oAuth_token=createToken(appId);
  payloadData.add(TOKEN_PAYLOD_PARAM_NAME,oAuth_token);
  String textPayload=payloadData.toString();
  return new ApplicationClusterContext(cartridgeInfo.getType(),clusterId,hostname,textPayload,deploymentPolicy,isLB);
}
Program: 116062
Project: 116062
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+ "String_Node_Str"+ instanceId);
  }
  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();
  }
}

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+ "String_Node_Str"+ instanceId);
  }
  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 groupInstance=group.getInstanceContexts(instanceId);
    GroupStatus status=GroupStatus.Terminating;
    if (groupInstance != null) {
      if (groupInstance.isStateTransitionValid(status)) {
        groupInstance.setStatus(status);
        updateGroupMonitor(appId,groupId,status,instanceId,groupInstance.getParentId());
        ApplicationHolder.persistApplication(application);
        ApplicationsEventPublisher.sendGroupInstanceTerminatingEvent(appId,groupId,instanceId);
      }
 else {
        log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId+ "String_Node_Str"+ groupInstance.getStatus()+ "String_Node_Str"+ status);
      }
    }
 else {
      log.warn("String_Node_Str" + groupId + "String_Node_Str"+ instanceId);
    }
  }
  finally {
    ApplicationHolder.releaseWriteLock();
  }
}