Program: 63968
Project: 63968
Buggy source:
@Override public void newHostgroupNodesSetup(Long stackId,Set<String> instanceIds,String hostGroup) throws CloudbreakException {
  try {
    Set<InstanceMetaData> instanceMetaDatas=new HashSet<>();
    for (    String instanceId : instanceIds) {
      InstanceMetaData instanceMetaData=instanceMetaDataRepository.findHostInStackByInstanceId(stackId,instanceId);
      instanceMetaDatas.add(instanceMetaData);
    }
    Stack stack=stackRepository.findOneWithLists(stackId);
    HostGroup hostGroupObject=hostGroupRepository.findHostGroupsByInstanceGroupName(stack.getCluster().getId(),hostGroup);
    ExecutorService executorService=Executors.newFixedThreadPool(TEN);
    List<Future<Boolean>> futures=new ArrayList<>();
    DockerClient swarmManagerClient=DockerClientBuilder.getInstance(getSwarmClientConfig(stack.getAmbariIp())).build();
    swarmInfoPollingService.pollWithTimeout(swarmCheckerTask,new SwarmContext(stack,swarmManagerClient,stack.getFullNodeCount()),POLLING_INTERVAL,MAX_POLLING_ATTEMPTS);
    for (    InstanceMetaData data : instanceMetaDatas) {
      futures.add(executorService.submit(new ConsulWatchBootstrap(swarmManagerClient,consulWatchPlugnDockerImageName,getLongNameTag(data.getLongName()),data.getPrivateIp(),data.getId())));
    }
    for (    Future<Boolean> future : futures) {
      future.get();
    }
    futures=new ArrayList<>();
    for (    InstanceMetaData data : instanceMetaDatas) {
      AmbariAgentBootstrap agentCreate=new AmbariAgentBootstrap(swarmManagerClient,data.getPrivateIp(),getLongNameTag(data.getLongName()),ambariDockerImageName,hostGroupObject.getInstanceGroup().getTemplate().getVolumeCount(),data.getId());
      futures.add(executorService.submit(agentCreate));
    }
    for (    Future<Boolean> future : futures) {
      future.get();
    }
  }
 catch (  Exception ex) {
    throw new CloudbreakException(ex);
  }
}

Fixed version (ground truth):
@Override public void newHostgroupNodesSetup(Long stackId,Set<String> instanceIds,String hostGroup) throws CloudbreakException {
  try {
    Set<InstanceMetaData> instanceMetaDatas=new HashSet<>();
    for (    String instanceId : instanceIds) {
      InstanceMetaData instanceMetaData=instanceMetaDataRepository.findHostInStackByInstanceId(stackId,instanceId);
      instanceMetaDatas.add(instanceMetaData);
    }
    Stack stack=stackRepository.findOneWithLists(stackId);
    HostGroup hostGroupObject=hostGroupRepository.findHostGroupsByInstanceGroupName(stack.getCluster().getId(),hostGroup);
    ExecutorService executorService=Executors.newFixedThreadPool(TEN);
    List<Future<Boolean>> futures=new ArrayList<>();
    DockerClient swarmManagerClient=DockerClientBuilder.getInstance(getSwarmClientConfig(stack.getAmbariIp())).withDockerCmdExecFactory(new DockerCmdExecFactoryImpl()).build();
    swarmInfoPollingService.pollWithTimeout(swarmCheckerTask,new SwarmContext(stack,swarmManagerClient,stack.getFullNodeCount()),POLLING_INTERVAL,MAX_POLLING_ATTEMPTS);
    for (    InstanceMetaData data : instanceMetaDatas) {
      futures.add(executorService.submit(new ConsulWatchBootstrap(swarmManagerClient,consulWatchPlugnDockerImageName,getLongNameTag(data.getLongName()),data.getPrivateIp(),data.getId())));
    }
    for (    Future<Boolean> future : futures) {
      future.get();
    }
    futures=new ArrayList<>();
    for (    InstanceMetaData data : instanceMetaDatas) {
      AmbariAgentBootstrap agentCreate=new AmbariAgentBootstrap(swarmManagerClient,data.getPrivateIp(),getLongNameTag(data.getLongName()),ambariDockerImageName,hostGroupObject.getInstanceGroup().getTemplate().getVolumeCount(),data.getId());
      futures.add(executorService.submit(agentCreate));
    }
    for (    Future<Boolean> future : futures) {
      future.get();
    }
  }
 catch (  Exception ex) {
    throw new CloudbreakException(ex);
  }
}