Program: 63985
Project: 63985
Buggy source:
private void downScaleStack(UpdateInstancesRequest request,Stack stack) throws Exception {
  Set<String> instanceIds=new HashSet<>();
  int i=0;
  for (  InstanceGroup instanceGroup : stack.getInstanceGroups()) {
    for (    InstanceMetaData metadataEntry : instanceGroup.getInstanceMetaData()) {
      if (metadataEntry.isDecommissioned() || metadataEntry.isUnRegistered()) {
        instanceIds.add(metadataEntry.getInstanceId());
        if (++i >= request.getScalingAdjustment() * -1) {
          break;
        }
      }
    }
  }
  if (stack.isCloudPlatformUsedWithTemplate()) {
    cloudPlatformConnectors.get(stack.cloudPlatform()).removeInstances(stack,instanceIds,request.getInstanceGroup());
  }
 else {
    ResourceBuilderInit resourceBuilderInit=resourceBuilderInits.get(stack.cloudPlatform());
    final DeleteContextObject deleteContextObject=resourceBuilderInit.decommissionInit(stack,instanceIds);
    for (int j=instanceResourceBuilders.get(stack.cloudPlatform()).size() - 1; j >= 0; j--) {
      List<Future<ResourceRequestResult>> futures=new ArrayList<>();
      final int index=j;
      final ResourceBuilder resourceBuilder=instanceResourceBuilders.get(stack.cloudPlatform()).get(index);
      for (      final Resource resource : getResourcesByType(resourceBuilder.resourceType(),deleteContextObject.getDecommissionResources())) {
        Future<ResourceRequestResult> submit=resourceBuilderExecutor.submit(DownScaleCallableBuilder.builder().withStack(stack).withDeleteContextObject(deleteContextObject).withResource(resource).withResourceBuilder(resourceBuilder).build());
        futures.add(submit);
        if (provisionUtil.isRequestFull(stack,futures.size() + 1)) {
          Map<FutureResult,List<ResourceRequestResult>> result=provisionUtil.waitForRequestToFinish(stack.getId(),futures);
          provisionUtil.checkErrorOccurred(result);
          futures=new ArrayList<>();
        }
      }
      Map<FutureResult,List<ResourceRequestResult>> result=provisionUtil.waitForRequestToFinish(stack.getId(),futures);
      provisionUtil.checkErrorOccurred(result);
    }
    if (!stackRepository.findById(stack.getId()).isStackInDeletionPhase()) {
      stackUpdater.removeStackResources(stack.getId(),deleteContextObject.getDecommissionResources());
      LOGGER.info("String_Node_Str",instanceIds);
      LOGGER.info("String_Node_Str",ReactorConfig.REMOVE_INSTANCES_COMPLETE_EVENT);
      reactor.notify(ReactorConfig.REMOVE_INSTANCES_COMPLETE_EVENT,Event.wrap(new StackUpdateSuccess(stack.getId(),true,instanceIds,request.getInstanceGroup())));
    }
  }
}

Fixed version (ground truth):
private void downScaleStack(UpdateInstancesRequest request,Stack stack) throws Exception {
  Set<String> instanceIds=new HashSet<>();
  int i=0;
  for (  InstanceGroup instanceGroup : stack.getInstanceGroups()) {
    for (    InstanceMetaData metadataEntry : instanceGroup.getInstanceMetaData()) {
      if (metadataEntry.isDecommissioned() || metadataEntry.isUnRegistered()) {
        instanceIds.add(metadataEntry.getInstanceId());
        if (++i >= request.getScalingAdjustment() * -1) {
          break;
        }
      }
    }
  }
  if (stack.isCloudPlatformUsedWithTemplate()) {
    cloudPlatformConnectors.get(stack.cloudPlatform()).removeInstances(stack,instanceIds,request.getInstanceGroup());
  }
 else {
    ResourceBuilderInit resourceBuilderInit=resourceBuilderInits.get(stack.cloudPlatform());
    final DeleteContextObject deleteContextObject=resourceBuilderInit.decommissionInit(stack,instanceIds);
    List<ResourceRequestResult> failedResourceList=new ArrayList<>();
    for (int j=instanceResourceBuilders.get(stack.cloudPlatform()).size() - 1; j >= 0; j--) {
      List<Future<ResourceRequestResult>> futures=new ArrayList<>();
      final int index=j;
      final ResourceBuilder resourceBuilder=instanceResourceBuilders.get(stack.cloudPlatform()).get(index);
      for (      final Resource resource : getResourcesByType(resourceBuilder.resourceType(),deleteContextObject.getDecommissionResources())) {
        Future<ResourceRequestResult> submit=resourceBuilderExecutor.submit(DownScaleCallableBuilder.builder().withStack(stack).withDeleteContextObject(deleteContextObject).withResource(resource).withResourceBuilder(resourceBuilder).build());
        futures.add(submit);
        if (provisionUtil.isRequestFull(stack,futures.size() + 1)) {
          Map<FutureResult,List<ResourceRequestResult>> result=provisionUtil.waitForRequestToFinish(stack.getId(),futures);
          failedResourceList.addAll(result.get(FutureResult.FAILED));
          futures=new ArrayList<>();
        }
      }
      Map<FutureResult,List<ResourceRequestResult>> result=provisionUtil.waitForRequestToFinish(stack.getId(),futures);
      failedResourceList.addAll(result.get(FutureResult.FAILED));
    }
    instanceIds.removeAll(filterFailedResources(failedResourceList,instanceIds));
    if (!stackRepository.findById(stack.getId()).isStackInDeletionPhase()) {
      stackUpdater.removeStackResources(stack.getId(),deleteContextObject.getDecommissionResources());
      LOGGER.info("String_Node_Str",instanceIds);
      LOGGER.info("String_Node_Str",ReactorConfig.REMOVE_INSTANCES_COMPLETE_EVENT);
      reactor.notify(ReactorConfig.REMOVE_INSTANCES_COMPLETE_EVENT,Event.wrap(new StackUpdateSuccess(stack.getId(),true,instanceIds,request.getInstanceGroup())));
    }
  }
}