nus-yam/ex-repair huggingface dataset:
Program: 115492
Project: 115492
Buggy source:
/** 
 * Find Cartridges And Groups In Application
 * @param applicationBean ApplicationBean
 * @param cartridges      List<String> cartridges
 * @param cartridgeGroups List <String> cartridgeGroups
 */
private static void findCartridgesAndGroupsInApplication(ApplicationBean applicationBean,List<String> cartridges,List<String> cartridgeGroups){
  if (applicationBean == null || applicationBean.getComponents() == null) {
    return;
  }
  ComponentBean componentBean=applicationBean.getComponents();
  List<CartridgeGroupReferenceBean> groupReferenceBeans=componentBean.getGroups();
  if (groupReferenceBeans != null) {
    for (    CartridgeGroupReferenceBean groupReferenceBean : groupReferenceBeans) {
      findCartridgesAndGroupsInCartridgeGroup(groupReferenceBean,cartridges,cartridgeGroups);
    }
  }
  List<CartridgeReferenceBean> cartridgeReferenceBeans=componentBean.getCartridges();
  findCartridgeNamesInCartridges(cartridgeReferenceBeans,cartridges);
}

Fixed version (ground truth):
/** 
 * Find Cartridges And Groups In Application
 * @param applicationBean ApplicationBean
 * @param cartridges      List<String> cartridges
 * @param cartridgeGroups List <String> cartridgeGroups
 */
private static void findCartridgesAndGroupsInApplication(ApplicationBean applicationBean,List<String> cartridges,List<String> cartridgeGroups) throws RemoteException, RestAPIException {
  if (applicationBean == null || applicationBean.getComponents() == null) {
    return;
  }
  ComponentBean componentBean=applicationBean.getComponents();
  List<CartridgeGroupReferenceBean> groupReferenceBeans=componentBean.getGroups();
  if (groupReferenceBeans != null) {
    for (    CartridgeGroupReferenceBean groupReferenceBean : groupReferenceBeans) {
      findCartridgesAndGroupsInCartridgeGroup(groupReferenceBean,cartridges,cartridgeGroups);
    }
  }
  List<CartridgeReferenceBean> cartridgeReferenceBeans=componentBean.getCartridges();
  findCartridgeNamesInCartridges(cartridgeReferenceBeans,cartridges);
}
Program: 115495
Project: 115495
Buggy source:
/** 
 * Find Cartridges And Groups In CartridgeGroup
 * @param groupReferenceBean GroupReferenceBean
 * @param cartridges         List <String>
 * @param cartridgeGroups    List <String>
 */
private static void findCartridgesAndGroupsInCartridgeGroup(CartridgeGroupReferenceBean groupReferenceBean,List<String> cartridges,List<String> cartridgeGroups){
  if (groupReferenceBean == null || cartridgeGroups == null) {
    return;
  }
  if (!cartridgeGroups.contains(groupReferenceBean.getName())) {
    cartridgeGroups.add(groupReferenceBean.getUuid());
  }
  if (groupReferenceBean.getGroups() != null) {
    for (    CartridgeGroupReferenceBean grReferenceBean : groupReferenceBean.getGroups()) {
      findCartridgesAndGroupsInCartridgeGroup(grReferenceBean,cartridges,cartridgeGroups);
      findCartridgeNamesInCartridges(groupReferenceBean.getCartridges(),cartridges);
    }
  }
  findCartridgeNamesInCartridges(groupReferenceBean.getCartridges(),cartridges);
}

Fixed version (ground truth):
/** 
 * Find Cartridges And Groups In CartridgeGroup
 * @param groupReferenceBean GroupReferenceBean
 * @param cartridges         List <String>
 * @param cartridgeGroups    List <String>
 */
private static void findCartridgesAndGroupsInCartridgeGroup(CartridgeGroupReferenceBean groupReferenceBean,List<String> cartridges,List<String> cartridgeGroups) throws RemoteException, RestAPIException {
  PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
  if (groupReferenceBean == null || cartridgeGroups == null) {
    return;
  }
  if (!cartridgeGroups.contains(groupReferenceBean.getName())) {
    ServiceGroup serviceGroup=AutoscalerServiceClient.getInstance().getServiceGroupByTenant(groupReferenceBean.getName(),carbonContext.getTenantId());
    cartridgeGroups.add(serviceGroup.getUuid());
  }
  if (groupReferenceBean.getGroups() != null) {
    for (    CartridgeGroupReferenceBean grReferenceBean : groupReferenceBean.getGroups()) {
      findCartridgesAndGroupsInCartridgeGroup(grReferenceBean,cartridges,cartridgeGroups);
      findCartridgeNamesInCartridges(groupReferenceBean.getCartridges(),cartridges);
    }
  }
  findCartridgeNamesInCartridges(groupReferenceBean.getCartridges(),cartridges);
}
Program: 115496
Project: 115496
Buggy source:
/** 
 * Find Cartrides in GroupBean
 * @param groupBean  groupBean
 * @param cartridges List of cartridges
 */
private static void findCartridgesInGroupBean(ServiceGroup groupBean,List<String> cartridges){
  if (groupBean == null || cartridges == null) {
    return;
  }
  if (groupBean.getCartridges() != null) {
    for (    String cartridge : groupBean.getCartridges()) {
      if (!cartridges.contains(cartridge)) {
        cartridges.add(groupBean.getUuid());
      }
    }
  }
  if (groupBean.getGroups() != null) {
    for (    ServiceGroup seGroup : groupBean.getGroups()) {
      findCartridgesInGroupBean(seGroup,cartridges);
    }
  }
}

Fixed version (ground truth):
/** 
 * Find Cartrides in GroupBean
 * @param groupBean  groupBean
 * @param cartridges List of cartridges
 */
private static void findCartridgesInGroupBean(ServiceGroup groupBean,List<String> cartridges){
  if (groupBean == null || cartridges == null) {
    return;
  }
  if (groupBean.getCartridges() != null) {
    for (    String cartridge : groupBean.getCartridges()) {
      if (!cartridges.contains(cartridge)) {
        cartridges.add(cartridge);
      }
    }
  }
  if (groupBean.getGroups() != null) {
    for (    ServiceGroup seGroup : groupBean.getGroups()) {
      findCartridgesInGroupBean(seGroup,cartridges);
    }
  }
}
Program: 115497
Project: 115497
Buggy source:
/** 
 * Find Cartridge Names In Cartridges
 * @param cartridgeReferenceBeans List of CartridgeReferenceBean
 * @param cartridges              List <String>
 */
private static void findCartridgeNamesInCartridges(List<CartridgeReferenceBean> cartridgeReferenceBeans,List<String> cartridges){
  if (cartridgeReferenceBeans == null || cartridges == null) {
    return;
  }
  for (  CartridgeReferenceBean cartridgeReferenceBean : cartridgeReferenceBeans) {
    if (cartridgeReferenceBean != null && !cartridges.contains(cartridgeReferenceBean.getUuid())) {
      cartridges.add(cartridgeReferenceBean.getUuid());
    }
  }
}

Fixed version (ground truth):
/** 
 * Find Cartridge Names In Cartridges
 * @param cartridgeReferenceBeans List of CartridgeReferenceBean
 * @param cartridges              List <String>
 */
private static void findCartridgeNamesInCartridges(List<CartridgeReferenceBean> cartridgeReferenceBeans,List<String> cartridges) throws RemoteException, RestAPIException {
  PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
  if (cartridgeReferenceBeans == null || cartridges == null) {
    return;
  }
  for (  CartridgeReferenceBean cartridgeReferenceBean : cartridgeReferenceBeans) {
    if (cartridgeReferenceBean != null && !cartridges.contains(cartridgeReferenceBean.getUuid())) {
      Cartridge cartridge=null;
      try {
        cartridge=CloudControllerServiceClient.getInstance().getCartridgeByTenant(cartridgeReferenceBean.getType(),carbonContext.getTenantId());
      }
 catch (      CloudControllerServiceCartridgeNotFoundExceptionException e) {
        String message=e.getFaultMessage().getCartridgeNotFoundException().getMessage();
        log.error(message);
        throw new RestAPIException(message,e);
      }
      cartridges.add(cartridge.getUuid());
    }
  }
}
Program: 115498
Project: 115498
Buggy source:
private static List<CartridgeGroupReferenceBean> convertStubGroupContextsToGroupDefinitions(GroupContext[] groupContexts){
  List<CartridgeGroupReferenceBean> groupDefinitions=new ArrayList<CartridgeGroupReferenceBean>();
  if (groupContexts != null) {
    for (    GroupContext groupContext : groupContexts) {
      if (groupContext != null) {
        CartridgeGroupReferenceBean groupDefinition=new CartridgeGroupReferenceBean();
        groupDefinition.setAlias(groupContext.getAlias());
        groupDefinition.setGroupMaxInstances(groupContext.getGroupMaxInstances());
        groupDefinition.setGroupMinInstances(groupContext.getGroupMinInstances());
        groupDefinition.setTenantId(groupContext.getTenantId());
        groupDefinition.setName(groupContext.getName());
        groupDefinition.setGroups(convertStubGroupContextsToGroupDefinitions(groupContext.getGroupContexts()));
        groupDefinition.setCartridges(convertStubCartridgeContextsToCartridgeReferenceBeans(groupContext.getCartridgeContexts()));
        groupDefinitions.add(groupDefinition);
      }
    }
  }
  return groupDefinitions;
}

Fixed version (ground truth):
private static List<CartridgeGroupReferenceBean> convertStubGroupContextsToGroupDefinitions(GroupContext[] groupContexts){
  List<CartridgeGroupReferenceBean> groupDefinitions=new ArrayList<CartridgeGroupReferenceBean>();
  if (groupContexts != null) {
    for (    GroupContext groupContext : groupContexts) {
      if (groupContext != null) {
        CartridgeGroupReferenceBean groupDefinition=new CartridgeGroupReferenceBean();
        groupDefinition.setUuid(groupContext.getUuid());
        groupDefinition.setAlias(groupContext.getAlias());
        groupDefinition.setGroupMaxInstances(groupContext.getGroupMaxInstances());
        groupDefinition.setGroupMinInstances(groupContext.getGroupMinInstances());
        groupDefinition.setTenantId(groupContext.getTenantId());
        groupDefinition.setName(groupContext.getName());
        groupDefinition.setGroups(convertStubGroupContextsToGroupDefinitions(groupContext.getGroupContexts()));
        groupDefinition.setCartridges(convertStubCartridgeContextsToCartridgeReferenceBeans(groupContext.getCartridgeContexts()));
        groupDefinitions.add(groupDefinition);
      }
    }
  }
  return groupDefinitions;
}
Program: 115499
Project: 115499
Buggy source:
public Cartridge getCartridge(String cartridgeType) throws RemoteException, CloudControllerServiceCartridgeNotFoundExceptionException {
  return stub.getCartridge(cartridgeType);
}

Fixed version (ground truth):
public Cartridge getCartridge(String cartridgeUuid) throws RemoteException, CloudControllerServiceCartridgeNotFoundExceptionException {
  return stub.getCartridge(cartridgeUuid);
}
Program: 115501
Project: 115501
Buggy source:
/** 
 * Find Cartrides in GroupBean
 * @param groupBean  groupBean
 * @param cartridges List of cartridges
 */
private static void findCartridgesInGroupBean(ServiceGroup groupBean,List<String> cartridges){
  if (groupBean == null || cartridges == null) {
    return;
  }
  if (groupBean.getCartridges() != null) {
    for (    String cartridge : groupBean.getCartridges()) {
      if (!cartridges.contains(cartridge)) {
        cartridges.add(cartridge);
      }
    }
  }
  if (groupBean.getGroups() != null) {
    for (    ServiceGroup seGroup : groupBean.getGroups()) {
      findCartridgesInGroupBean(seGroup,cartridges);
    }
  }
}

Fixed version (ground truth):
/** 
 * Find Cartrides in GroupBean
 * @param groupBean  groupBean
 * @param cartridges List of cartridges
 */
private static void findCartridgesInGroupBean(ServiceGroup groupBean,List<String> cartridges) throws RemoteException, CloudControllerServiceCartridgeNotFoundExceptionException {
  PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
  if (groupBean == null || cartridges == null) {
    return;
  }
  if (groupBean.getCartridges() != null) {
    for (    String cartridge : groupBean.getCartridges()) {
      if (!cartridges.contains(cartridge)) {
        Cartridge cartridge1=CloudControllerServiceClient.getInstance().getCartridgeByTenant(cartridge,groupBean.getTenantId());
        cartridges.add(cartridge1.getUuid());
      }
    }
  }
  if (groupBean.getGroups() != null) {
    for (    ServiceGroup seGroup : groupBean.getGroups()) {
      findCartridgesInGroupBean(seGroup,cartridges);
    }
  }
}
Program: 115506
Project: 115506
Buggy source:
@Override public Cartridge[] getCartridgesByTenant(int tenantId){
  Collection<Cartridge> allCartridges=CloudControllerContext.getInstance().getCartridges();
  log.info("String_Node_Str" + allCartridges);
  List<Cartridge> cartridges=new ArrayList<Cartridge>();
  if (allCartridges == null || allCartridges.size() == 0) {
    log.info("String_Node_Str" + tenantId);
    return null;
  }
  for (  Cartridge cartridge : allCartridges) {
    if (log.isDebugEnabled()) {
      log.debug(cartridge);
    }
    if (cartridge.getTenantId() == tenantId) {
      cartridges.add(cartridge);
    }
  }
  log.info("String_Node_Str" + cartridges);
  return cartridges.toArray(new Cartridge[cartridges.size()]);
}

Fixed version (ground truth):
@Override public Cartridge[] getCartridgesByTenant(int tenantId){
  Collection<Cartridge> allCartridges=CloudControllerContext.getInstance().getCartridges();
  List<Cartridge> cartridges=new ArrayList<Cartridge>();
  if (allCartridges == null || allCartridges.size() == 0) {
    log.info("String_Node_Str" + tenantId);
    return null;
  }
  for (  Cartridge cartridge : allCartridges) {
    if (log.isDebugEnabled()) {
      log.debug(cartridge);
    }
    if (cartridge.getTenantId() == tenantId) {
      cartridges.add(cartridge);
    }
  }
  return cartridges.toArray(new Cartridge[cartridges.size()]);
}
Program: 115510
Project: 115510
Buggy source:
/** 
 * This method validates group aliases recursively
 * @param groupsSet - the group collection in which the groups are added to
 * @param groups    - the group collection in which it traverses through
 * @throws RestAPIException
 */
private static void validateGroupsRecursively(ConcurrentHashMap<String,CartridgeGroupReferenceBean> groupsSet,Collection<CartridgeGroupReferenceBean> groups,boolean hasDeploymentPolicy) throws RestAPIException {
  boolean groupHasDeploymentPolicy=false;
  for (  CartridgeGroupReferenceBean group : groups) {
    if (groupsSet.get(group.getAlias()) != null) {
      String message="String_Node_Str" + group.getAlias();
      throw new RestAPIException(message);
    }
    if (group.getDeploymentPolicy() != null) {
      if (hasDeploymentPolicy) {
        String message="String_Node_Str" + "String_Node_Str" + group.getAlias();
        throw new RestAPIException(message);
      }
 else {
        groupHasDeploymentPolicy=true;
      }
    }
 else {
      groupHasDeploymentPolicy=hasDeploymentPolicy;
    }
    if (group.getCartridges() != null) {
      validateCartridgesForDeploymentPolicy(group.getCartridges(),groupHasDeploymentPolicy);
    }
    groupsSet.put(group.getAlias(),group);
    if (group.getGroups() != null) {
      validateGroupsRecursively(groupsSet,group.getGroups(),groupHasDeploymentPolicy);
    }
  }
}

Fixed version (ground truth):
/** 
 * This method validates group aliases recursively
 * @param groupsSet - the group collection in which the groups are added to
 * @param groups    - the group collection in which it traverses through
 * @throws RestAPIException
 */
private static void validateGroupsRecursively(ConcurrentHashMap<String,CartridgeGroupReferenceBean> groupsSet,Collection<CartridgeGroupReferenceBean> groups,boolean hasDeploymentPolicy) throws RestAPIException {
  boolean groupHasDeploymentPolicy;
  for (  CartridgeGroupReferenceBean group : groups) {
    if (groupsSet.get(group.getAlias()) != null) {
      String message="String_Node_Str" + group.getAlias();
      throw new RestAPIException(message);
    }
    if (group.getDeploymentPolicy() != null) {
      if (hasDeploymentPolicy) {
        String message="String_Node_Str" + "String_Node_Str" + group.getAlias();
        throw new RestAPIException(message);
      }
 else {
        groupHasDeploymentPolicy=true;
      }
    }
 else {
      groupHasDeploymentPolicy=hasDeploymentPolicy;
    }
    if (group.getCartridges() != null) {
      validateCartridgesForDeploymentPolicy(group.getCartridges(),groupHasDeploymentPolicy);
    }
    groupsSet.put(group.getAlias(),group);
    if (group.getGroups() != null) {
      validateGroupsRecursively(groupsSet,group.getGroups(),groupHasDeploymentPolicy);
    }
  }
}
Program: 115512
Project: 115512
Buggy source:
/** 
 * Assert application activation
 * @param applicationUuid
 */
private void assertGroupActivation(String applicationUuid){
  Application application=ApplicationManager.getApplications().getApplication(applicationUuid);
  assertNotNull(String.format("String_Node_Str",applicationUuid),application);
  Collection<Group> groups=application.getAllGroupsRecursively();
  for (  Group group : groups) {
    assertEquals(group.getInstanceContextCount() >= group.getGroupMinInstances(),true);
  }
}

Fixed version (ground truth):
/** 
 * Assert application activation
 * @param applicationId
 */
private void assertGroupActivation(String applicationId,int tenantId){
  Application application=ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId);
  assertNotNull(String.format("String_Node_Str",applicationId),application);
  Collection<Group> groups=application.getAllGroupsRecursively();
  for (  Group group : groups) {
    assertEquals(group.getInstanceContextCount() >= group.getGroupMinInstances(),true);
  }
}
Program: 115514
Project: 115514
Buggy source:
/** 
 * Assert application activation
 * @param applicationUuid
 */
private void assertApplicationActivation(String applicationUuid){
  long startTime=System.currentTimeMillis();
  Application application=ApplicationManager.getApplications().getApplication(applicationUuid);
  while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    application=ApplicationManager.getApplications().getApplication(applicationUuid);
    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
      break;
    }
  }
  assertNotNull(String.format("String_Node_Str",applicationUuid),application);
  assertEquals(String.format("String_Node_Str",applicationUuid),ApplicationStatus.Active,application.getStatus());
}

Fixed version (ground truth):
/** 
 * Assert application activation
 * @param applicationId
 */
private void assertApplicationActivation(String applicationId,int tenantId){
  long startTime=System.currentTimeMillis();
  Application application=ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId);
  while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    application=ApplicationManager.getApplications().getApplicationByTenant(applicationId,tenantId);
    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
      break;
    }
  }
  assertNotNull(String.format("String_Node_Str",application.getId()),application);
  assertEquals(String.format("String_Node_Str",application.getId()),ApplicationStatus.Active,application.getStatus());
}
Program: 115516
Project: 115516
Buggy source:
private void runApplicationTest(String applicationFolderName,String applicationId){
  executeCommand(getApplicationsPath() + "String_Node_Str" + applicationFolderName+ "String_Node_Str");
  assertApplicationActivation(applicationId);
  executeCommand(getApplicationsPath() + "String_Node_Str" + applicationFolderName+ "String_Node_Str");
  assertApplicationNotExists(applicationId);
}

Fixed version (ground truth):
private void runApplicationTest(String applicationFolderName,String applicationId){
  executeCommand(getApplicationsPath() + "String_Node_Str" + applicationFolderName+ "String_Node_Str");
  assertApplicationActivation(applicationId,-1234);
  executeCommand(getApplicationsPath() + "String_Node_Str" + applicationFolderName+ "String_Node_Str");
  assertApplicationNotExists(applicationId);
}
Program: 115521
Project: 115521
Buggy source:
/** 
 * Assert application activation
 * @param applicationName
 */
private void assertGroupActivation(String applicationName){
  Application application=ApplicationManager.getApplications().getApplication(applicationName);
  assertNotNull(String.format("String_Node_Str",applicationName),application);
  Collection<Group> groups=application.getAllGroupsRecursively();
  for (  Group group : groups) {
    assertEquals(group.getInstanceContextCount() >= group.getGroupMinInstances(),true);
  }
}

Fixed version (ground truth):
/** 
 * Assert application activation
 * @param applicationUuid
 */
private void assertGroupActivation(String applicationUuid){
  Application application=ApplicationManager.getApplications().getApplication(applicationUuid);
  assertNotNull(String.format("String_Node_Str",applicationUuid),application);
  Collection<Group> groups=application.getAllGroupsRecursively();
  for (  Group group : groups) {
    assertEquals(group.getInstanceContextCount() >= group.getGroupMinInstances(),true);
  }
}
Program: 115523
Project: 115523
Buggy source:
/** 
 * Assert application activation
 * @param applicationName
 */
private void assertApplicationActivation(String applicationName){
  long startTime=System.currentTimeMillis();
  Application application=ApplicationManager.getApplications().getApplication(applicationName);
  while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    application=ApplicationManager.getApplications().getApplication(applicationName);
    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
      break;
    }
  }
  assertNotNull(String.format("String_Node_Str",applicationName),application);
  assertEquals(String.format("String_Node_Str",applicationName),ApplicationStatus.Active,application.getStatus());
}

Fixed version (ground truth):
/** 
 * Assert application activation
 * @param applicationUuid
 */
private void assertApplicationActivation(String applicationUuid){
  long startTime=System.currentTimeMillis();
  Application application=ApplicationManager.getApplications().getApplication(applicationUuid);
  while (!((application != null) && (application.getStatus() == ApplicationStatus.Active))) {
    try {
      Thread.sleep(1000);
    }
 catch (    InterruptedException ignore) {
    }
    application=ApplicationManager.getApplications().getApplication(applicationUuid);
    if ((System.currentTimeMillis() - startTime) > APPLICATION_ACTIVATION_TIMEOUT) {
      break;
    }
  }
  assertNotNull(String.format("String_Node_Str",applicationUuid),application);
  assertEquals(String.format("String_Node_Str",applicationUuid),ApplicationStatus.Active,application.getStatus());
}
Program: 115525
Project: 115525
Buggy source:
public static void sendClusterTerminatedEvent(String appId,String serviceName,String clusterId,String instanceId){
  Service service=TopologyManager.getTopology().getService(serviceName);
  if (service != null) {
    Cluster cluster=service.getCluster(clusterId);
    ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
    if (clusterInstance == null) {
      log.warn(String.format("String_Node_Str",instanceId));
      return;
    }
    if (clusterInstance.isStateTransitionValid(ClusterStatus.Terminated)) {
      if (clusterInstance.getStatus() != ClusterStatus.Terminated) {
        ClusterStatusClusterTerminatedEvent appStatusClusterTerminatedEvent=new ClusterStatusClusterTerminatedEvent(appId,serviceName,clusterId,instanceId);
        publishEvent(appStatusClusterTerminatedEvent);
      }
 else {
        if (log.isDebugEnabled()) {
          log.warn("String_Node_Str" + clusterId);
        }
      }
    }
 else {
      log.warn("String_Node_Str" + clusterInstance.getInstanceId() + "String_Node_Str"+ clusterId+ "String_Node_Str"+ clusterInstance.getStatus());
    }
  }
}

Fixed version (ground truth):
public static void sendClusterTerminatedEvent(String appId,String serviceName,String clusterId,String instanceId){
  Service service=TopologyManager.getTopology().getService(serviceName);
  if (service != null) {
    Cluster cluster=service.getCluster(clusterId);
    ClusterInstance clusterInstance=cluster.getInstanceContexts(instanceId);
    if (clusterInstance == null) {
      log.warn(String.format("String_Node_Str",instanceId));
      return;
    }
    if (clusterInstance.isStateTransitionValid(ClusterStatus.Terminated)) {
      if (clusterInstance.getStatus() != ClusterStatus.Terminated) {
        ClusterStatusClusterTerminatedEvent appStatusClusterTerminatedEvent=new ClusterStatusClusterTerminatedEvent(appId,serviceName,clusterId,instanceId);
        publishEvent(appStatusClusterTerminatedEvent);
      }
 else {
        log.warn("String_Node_Str" + clusterId);
      }
    }
 else {
      log.warn("String_Node_Str" + clusterInstance.getInstanceId() + "String_Node_Str"+ clusterId+ "String_Node_Str"+ clusterInstance.getStatus());
    }
  }
}
Program: 115527
Project: 115527
Buggy source:
public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue,float rifThreshold){
  if (rifThreshold != 0) {
    float requiredNumberOfInstances=rifPredictedValue / rifThreshold;
    return (int)Math.ceil(requiredNumberOfInstances);
  }
 else {
    log.error("String_Node_Str");
    return 0;
  }
}

Fixed version (ground truth):
public int getNumberOfInstancesRequiredBasedOnRif(float rifPredictedValue,float rifThreshold){
  if (rifThreshold > 0) {
    float requiredNumberOfInstances=rifPredictedValue / rifThreshold;
    return (int)Math.ceil(requiredNumberOfInstances);
  }
 else {
    log.error("String_Node_Str");
    return 0;
  }
}
Program: 115529
Project: 115529
Buggy source:
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") public Response deleteApplicationProperty(@PathParam("String_Node_Str") String applicationId,@PathParam("String_Node_Str") String propertyName) throws RestAPIException {
  try {
    boolean deleted=registry.removePropertyFromApplication(applicationId,propertyName);
  }
 catch (  RegistryException e) {
    String msg=String.format("String_Node_Str",applicationId,propertyName);
    log.error(msg,e);
    throw new RestAPIException(msg,e);
  }
  return Response.ok().build();
}

Fixed version (ground truth):
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") public Response deleteApplicationProperty(@PathParam("String_Node_Str") String applicationId,@PathParam("String_Node_Str") String propertyName) throws RestAPIException {
  try {
    boolean deleted=registry.removePropertyFromApplication(applicationId,propertyName);
    if (!deleted) {
      log.warn(String.format("String_Node_Str",applicationId));
    }
  }
 catch (  RegistryException e) {
    String msg=String.format("String_Node_Str",applicationId,propertyName);
    log.error(msg,e);
    throw new RestAPIException(msg,e);
  }
  return Response.ok().build();
}
Program: 115530
Project: 115530
Buggy source:
public void addPropertyToApplication(String applicationId,Property property) throws RegistryException {
  Registry registry=getRegistry();
  String resourcePath=mainResource + applicationId;
  try {
    PrivilegedCarbonContext ctx=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    Resource nodeResource=null;
    if (registry.resourceExists(resourcePath)) {
      nodeResource=registry.get(resourcePath);
    }
 else {
      nodeResource=registry.newCollection();
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + nodeResource.getPath());
      }
    }
    boolean updated=false;
    for (    String value : property.getValues()) {
      if (!propertyValueExist(nodeResource,property.getKey(),value)) {
        updated=true;
        log.info(String.format("String_Node_Str",resourcePath,property.getKey(),value));
        nodeResource.addProperty(property.getKey(),value);
      }
 else {
        log.info(String.format("String_Node_Str",property.getKey(),value));
      }
    }
    if (updated) {
      registry.put(resourcePath,nodeResource);
    }
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + resourcePath;
    log.error(msg,e);
    throw new RegistryException(msg,e);
  }
}

Fixed version (ground truth):
public void addPropertyToApplication(String applicationId,Property property) throws RegistryException {
  Registry registry=getRegistry();
  String resourcePath=mainResource + applicationId;
  try {
    PrivilegedCarbonContext ctx=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    ctx.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
    ctx.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    Resource nodeResource=null;
    if (registry.resourceExists(resourcePath)) {
      nodeResource=registry.get(resourcePath);
    }
 else {
      nodeResource=registry.newCollection();
      if (log.isDebugEnabled()) {
        log.debug("String_Node_Str" + nodeResource.getPath());
      }
    }
    boolean updated=false;
    for (    String value : property.getValues()) {
      if (!propertyValueExist(nodeResource,property.getKey(),value)) {
        updated=true;
        log.info(String.format("String_Node_Str" + "String_Node_Str",resourcePath,property.getKey(),value));
        nodeResource.addProperty(property.getKey(),value);
      }
 else {
        log.info(String.format("String_Node_Str",property.getKey(),value));
      }
    }
    if (updated) {
      registry.put(resourcePath,nodeResource);
    }
  }
 catch (  Exception e) {
    String msg="String_Node_Str" + resourcePath;
    log.error(msg,e);
    throw new RegistryException(msg,e);
  }
}
Program: 115533
Project: 115533
Buggy source:
public static ApplicationInfoBean convertApplicationToApplicationInstanceBean(Application application){
  if (application == null) {
    return null;
  }
  ApplicationInfoBean applicationBean=new ApplicationInfoBean();
  applicationBean.setId(application.getId());
  applicationBean.setName(application.getName());
  applicationBean.setStatus(application.getStatus().name());
  applicationBean.setDescription(application.getDescription());
  applicationBean.setTenantDomain(application.getTenantDomain());
  applicationBean.setTenantAdminUsername(application.getTenantAdminUserName());
  applicationBean.setApplicationInstances(convertApplicationInstancesToApplicationInstances(application));
  return applicationBean;
}

Fixed version (ground truth):
public static ApplicationInfoBean convertApplicationToApplicationInstanceBean(Application application){
  if (application == null) {
    return null;
  }
  ApplicationInfoBean applicationBean=new ApplicationInfoBean();
  applicationBean.setId(application.getUniqueIdentifier());
  applicationBean.setName(application.getName());
  applicationBean.setStatus(application.getStatus().name());
  applicationBean.setDescription(application.getDescription());
  applicationBean.setTenantDomain(application.getTenantDomain());
  applicationBean.setTenantAdminUsername(application.getTenantAdminUserName());
  applicationBean.setApplicationInstances(convertApplicationInstancesToApplicationInstances(application));
  return applicationBean;
}
Program: 115534
Project: 115534
Buggy source:
private static List<ApplicationInstanceBean> convertApplicationInstancesToApplicationInstances(Application application){
  if (application == null) {
    return null;
  }
  List<ApplicationInstanceBean> applicationInstanceList=new ArrayList<ApplicationInstanceBean>();
  Collection<ApplicationInstance> applicationInstancesInTopology=application.getInstanceIdToInstanceContextMap().values();
  for (  ApplicationInstance applicationInstance : applicationInstancesInTopology) {
    ApplicationInstanceBean instance=new ApplicationInstanceBean();
    instance.setInstanceId(applicationInstance.getAlias());
    instance.setApplicationId(application.getUniqueIdentifier());
    instance.setParentInstanceId(applicationInstance.getParentId());
    instance.setStatus(applicationInstance.getStatus().toString());
    applicationInstanceList.add(instance);
  }
  return applicationInstanceList;
}

Fixed version (ground truth):
private static List<ApplicationInstanceBean> convertApplicationInstancesToApplicationInstances(Application application){
  if (application == null) {
    return null;
  }
  List<ApplicationInstanceBean> applicationInstanceList=new ArrayList<ApplicationInstanceBean>();
  Collection<ApplicationInstance> applicationInstancesInTopology=application.getInstanceIdToInstanceContextMap().values();
  for (  ApplicationInstance applicationInstance : applicationInstancesInTopology) {
    ApplicationInstanceBean instance=new ApplicationInstanceBean();
    instance.setInstanceId(applicationInstance.getInstanceId());
    instance.setApplicationId(application.getUniqueIdentifier());
    instance.setParentInstanceId(applicationInstance.getParentId());
    instance.setStatus(applicationInstance.getStatus().toString());
    applicationInstanceList.add(instance);
  }
  return applicationInstanceList;
}
Program: 115535
Project: 115535
Buggy source:
public ApplicationPolicy[] getApplicationPolicies(){
  return applicationPolicyListMap.values().toArray(new ApplicationPolicy[0]);
}

Fixed version (ground truth):
/** 
 * Returns the application policy to which the specified id is mapped or null
 * @return List of all application policies
 */
public ApplicationPolicy[] getApplicationPolicies(){
  return applicationPolicyListMap.values().toArray(new ApplicationPolicy[0]);
}
Program: 115536
Project: 115536
Buggy source:
/** 
 * Get autoscaling policy definition by tenant
 * @param tenantId tenant id
 * @return Autoscaling policy
 */
public AutoscalePolicy[] getAutoScalingPoliciesByTenant(int tenantId);

Fixed version (ground truth):
/** 
 * Get autoscaling policy definition by tenant
 * @param tenantId tenant id
 * @return Array of autoscaling policies for tenant
 */
public AutoscalePolicy[] getAutoScalingPoliciesByTenant(int tenantId);
Program: 115537
Project: 115537
Buggy source:
/** 
 * Get application policy by application uuid
 * @param applicationPolicyId the application policy id
 * @return {@link ApplicationPolicy} used by the given application
 */
public ApplicationPolicy getApplicationPolicy(String applicationPolicyId);

Fixed version (ground truth):
/** 
 * Get application policy by application id
 * @param applicationPolicyId the application policy id
 * @param tenantId tenant id
 * @return {@link ApplicationPolicy} used by the given application
 */
public ApplicationPolicy getApplicationPolicy(String applicationPolicyId,int tenantId);
Program: 115538
Project: 115538
Buggy source:
@Override public ApplicationPolicy getApplicationPolicy(String applicationPolicyUuid){
  return PolicyManager.getInstance().getApplicationPolicy(applicationPolicyUuid);
}

Fixed version (ground truth):
@Override public ApplicationPolicy getApplicationPolicy(String applicationPolicyId,int tenantId){
  ApplicationPolicy[] applicationPolicies=getApplicationPolicies();
  ApplicationPolicy applicationPolicy=null;
  if (applicationPolicies != null) {
    for (    ApplicationPolicy applicationPolicy1 : applicationPolicies) {
      if (applicationPolicy1.getTenantId() == tenantId && applicationPolicy1.getId().equals(applicationPolicyId)) {
        applicationPolicy=applicationPolicy1;
      }
    }
  }
  return applicationPolicy;
}
Program: 115539
Project: 115539
Buggy source:
@Override public boolean addApplicationPolicy(ApplicationPolicy applicationPolicy) throws RemoteException, InvalidApplicationPolicyException, ApplicationPolicyAlreadyExistsException {
  AutoscalerUtil.validateApplicationPolicy(applicationPolicy);
  if (log.isInfoEnabled()) {
    log.info("String_Node_Str" + applicationPolicy.getUuid());
  }
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + applicationPolicy.toString());
  }
  String applicationPolicyUuid=applicationPolicy.getUuid();
  if (PolicyManager.getInstance().getApplicationPolicy(applicationPolicyUuid) != null) {
    String message="String_Node_Str" + applicationPolicyUuid;
    log.error(message);
    throw new ApplicationPolicyAlreadyExistsException(message);
  }
  String applicationPolicyUuid1=applicationPolicy.getUuid();
  if (PolicyManager.getInstance().getApplicationPolicyByUuid(applicationPolicyUuid1) != null && PolicyManager.getInstance().getApplicationPolicyByUuid(applicationPolicyUuid1).getTenantId() == applicationPolicy.getTenantId()) {
    String message="String_Node_Str" + applicationPolicyUuid1;
    log.error(message);
    throw new ApplicationPolicyAlreadyExistsException(message);
  }
  PolicyManager.getInstance().addApplicationPolicy(applicationPolicy);
  return true;
}

Fixed version (ground truth):
@Override public boolean addApplicationPolicy(ApplicationPolicy applicationPolicy) throws RemoteException, InvalidApplicationPolicyException, ApplicationPolicyAlreadyExistsException {
  AutoscalerUtil.validateApplicationPolicy(applicationPolicy);
  if (log.isInfoEnabled()) {
    log.info("String_Node_Str" + applicationPolicy.getUuid());
  }
  if (log.isDebugEnabled()) {
    log.debug("String_Node_Str" + applicationPolicy.toString());
  }
  String applicationPolicyId=applicationPolicy.getId();
  if (PolicyManager.getInstance().getApplicationPolicy(applicationPolicyId) != null) {
    String message="String_Node_Str" + applicationPolicyId;
    log.error(message);
    throw new ApplicationPolicyAlreadyExistsException(message);
  }
  String applicationPolicyUuid1=applicationPolicy.getUuid();
  if (PolicyManager.getInstance().getApplicationPolicyByUuid(applicationPolicyUuid1) != null && PolicyManager.getInstance().getApplicationPolicyByUuid(applicationPolicyUuid1).getTenantId() == applicationPolicy.getTenantId()) {
    String message="String_Node_Str" + applicationPolicyUuid1;
    log.error(message);
    throw new ApplicationPolicyAlreadyExistsException(message);
  }
  PolicyManager.getInstance().addApplicationPolicy(applicationPolicy);
  return true;
}
Program: 115540
Project: 115540
Buggy source:
public ApplicationPolicy getApplicationPolicy(String applicationPolicyUuid) throws RemoteException {
  return stub.getApplicationPolicy(applicationPolicyUuid);
}

Fixed version (ground truth):
public ApplicationPolicy getApplicationPolicy(String applicationPolicyId,int tenantId) throws RemoteException {
  return stub.getApplicationPolicy(applicationPolicyId,tenantId);
}
Program: 115541
Project: 115541
Buggy source:
@Override public void removeUsedCartridgesInCartridgeGroups(String cartridgeGroupUuid,String[] cartridgeNames){
  Lock lock=null;
  try {
    lock=StratosManagerContext.getInstance().acquireCartridgesCartridgeGroupsWriteLock();
    StratosManagerContext.getInstance().removeUsedCartridgesInCartridgeGroups(cartridgeGroupUuid,cartridgeNames);
    StratosManagerContext.getInstance().persist();
  }
  finally {
    if (lock != null) {
      StratosManagerContext.getInstance().releaseWriteLock(lock);
    }
  }
}

Fixed version (ground truth):
@Override public void removeUsedCartridgesInCartridgeGroups(String cartridgeGroupUuid,String[] cartridgeNamesUuid){
  Lock lock=null;
  try {
    lock=StratosManagerContext.getInstance().acquireCartridgesCartridgeGroupsWriteLock();
    StratosManagerContext.getInstance().removeUsedCartridgesInCartridgeGroups(cartridgeGroupUuid,cartridgeNamesUuid);
    StratosManagerContext.getInstance().persist();
  }
  finally {
    if (lock != null) {
      StratosManagerContext.getInstance().releaseWriteLock(lock);
    }
  }
}
Program: 115542
Project: 115542
Buggy source:
/** 
 * Updates a cartridge group
 * @param cartridgeGroupBean cartridge group definition
 * @return 200 if network partition is successfully updated
 * @throws RestAPIException
 */
@PUT @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") public Response updateCartridgeGroup(CartridgeGroupBean cartridgeGroupBean) throws RestAPIException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    StratosApiV41Utils.updateServiceGroup(cartridgeGroupBean,carbonContext.getTenantId());
    URI url=uriInfo.getAbsolutePathBuilder().path(cartridgeGroupBean.getUuid()).build();
    return Response.ok(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",cartridgeGroupBean.getUuid()))).build();
  }
 catch (  InvalidCartridgeGroupDefinitionException e) {
    return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
catch (  RestAPIException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
}

Fixed version (ground truth):
/** 
 * Updates a cartridge group
 * @param cartridgeGroupBean cartridge group definition
 * @return 200 if network partition is successfully updated
 * @throws RestAPIException
 */
@PUT @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") public Response updateCartridgeGroup(CartridgeGroupBean cartridgeGroupBean) throws RestAPIException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    StratosApiV41Utils.updateServiceGroup(cartridgeGroupBean,carbonContext.getTenantId());
    URI url=uriInfo.getAbsolutePathBuilder().path(cartridgeGroupBean.getUuid()).build();
    return Response.ok(url).entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",cartridgeGroupBean.getUuid()))).build();
  }
 catch (  InvalidCartridgeGroupDefinitionException e) {
    return Response.status(Response.Status.BAD_REQUEST).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
catch (  RestAPIException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
catch (  CloudControllerServiceCartridgeNotFoundExceptionException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
}
Program: 115544
Project: 115544
Buggy source:
/** 
 * Delete cartridge group definition.
 * @param name the group definition name
 * @return 200 if cartridge group is successfully removed
 * @throws RestAPIException the rest api exception
 */
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") @SuperTenantService(true) public Response removeServiceGroup(@PathParam("String_Node_Str") String name) throws RestAPIException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    StratosApiV41Utils.removeServiceGroup(name,carbonContext.getTenantId());
  }
 catch (  AutoscalerServiceCartridgeGroupNotFoundExceptionException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
  return Response.ok().entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",name))).build();
}

Fixed version (ground truth):
/** 
 * Delete cartridge group definition.
 * @param name the group definition name
 * @return 200 if cartridge group is successfully removed
 * @throws RestAPIException the rest api exception
 */
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") public Response removeServiceGroup(@PathParam("String_Node_Str") String name) throws RestAPIException {
  try {
    PrivilegedCarbonContext carbonContext=PrivilegedCarbonContext.getThreadLocalCarbonContext();
    StratosApiV41Utils.removeServiceGroup(name,carbonContext.getTenantId());
  }
 catch (  AutoscalerServiceCartridgeGroupNotFoundExceptionException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
catch (  CloudControllerServiceCartridgeNotFoundExceptionException e) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
  return Response.ok().entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",name))).build();
}
Program: 115545
Project: 115545
Buggy source:
/** 
 * Delete an application.
 * @param applicationId the application id
 * @return 200 if application is successfully removed, 404 if specified application is not found, 409 ifapplication is not in CREATED state
 * @throws RestAPIException the rest api exception
 */
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") @SuperTenantService(true) public Response removeApplication(@PathParam("String_Node_Str") String applicationId) throws RestAPIException {
  ApplicationBean applicationDefinition=StratosApiV41Utils.getApplication(applicationId);
  if (applicationDefinition == null) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
  if (!applicationDefinition.getStatus().equalsIgnoreCase(StratosApiV41Utils.APPLICATION_STATUS_CREATED)) {
    return Response.status(Response.Status.CONFLICT).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,String.format("String_Node_Str" + "String_Node_Str",applicationId,applicationDefinition.getStatus()))).build();
  }
  StratosApiV41Utils.removeApplication(applicationId);
  return Response.ok().entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",applicationId))).build();
}

Fixed version (ground truth):
/** 
 * Delete an application.
 * @param applicationId the application id
 * @return 200 if application is successfully removed, 404 if specified application is not found, 409 ifapplication is not in CREATED state
 * @throws RestAPIException the rest api exception
 */
@DELETE @Path("String_Node_Str") @Produces("String_Node_Str") @Consumes("String_Node_Str") @AuthorizationAction("String_Node_Str") public Response removeApplication(@PathParam("String_Node_Str") String applicationId) throws RestAPIException {
  ApplicationBean applicationDefinition=StratosApiV41Utils.getApplication(applicationId);
  if (applicationDefinition == null) {
    return Response.status(Response.Status.NOT_FOUND).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,"String_Node_Str")).build();
  }
  if (!applicationDefinition.getStatus().equalsIgnoreCase(StratosApiV41Utils.APPLICATION_STATUS_CREATED)) {
    return Response.status(Response.Status.CONFLICT).entity(new ResponseMessageBean(ResponseMessageBean.ERROR,String.format("String_Node_Str" + "String_Node_Str",applicationId,applicationDefinition.getStatus()))).build();
  }
  StratosApiV41Utils.removeApplication(applicationId);
  return Response.ok().entity(new ResponseMessageBean(ResponseMessageBean.SUCCESS,String.format("String_Node_Str",applicationId))).build();
}