Program: 52836
Project: 52836
Buggy source:
private ExitCode executeDistBuild(CommandRunnerParams params,DistBuildConfig distBuildConfig,ActionAndTargetGraphs graphs,WeightedListeningExecutorService executorService,ProjectFilesystem filesystem,FileHashCache fileHashCache,ClientStatsTracker distBuildClientStats,RuleKeyCacheScope<RuleKey> ruleKeyCacheScope) throws IOException, InterruptedException {
  Preconditions.checkNotNull(distBuildClientEventListener);
  if (distributedBuildStateFile == null && distBuildConfig.getBuildMode().equals(BuildMode.DISTRIBUTED_BUILD_WITH_LOCAL_COORDINATOR) && !distBuildConfig.getMinionQueue().isPresent()) {
    throw new HumanReadableException("String_Node_Str");
  }
  BuildEvent.DistBuildStarted started=BuildEvent.distBuildStarted();
  params.getBuckEventBus().post(started);
  LOG.info("String_Node_Str");
  AsyncJobStateAndCells stateAndCells=computeDistBuildState(params,graphs,executorService,Optional.of(distBuildClientStats));
  ListenableFuture<BuildJobState> asyncJobState=stateAndCells.asyncJobState;
  DistBuildCellIndexer distBuildCellIndexer=stateAndCells.distBuildCellIndexer;
  if (distributedBuildStateFile != null) {
    BuildJobState jobState;
    try {
      jobState=asyncJobState.get();
    }
 catch (    ExecutionException e) {
      throw new RuntimeException("String_Node_Str",e);
    }
    for (    BuildJobStateFileHashes cell : jobState.getFileHashes()) {
      ProjectFilesystem cellFilesystem=Preconditions.checkNotNull(distBuildCellIndexer.getLocalFilesystemsByCellIndex().get(cell.getCellIndex()));
      for (      BuildJobStateFileHashEntry entry : cell.getEntries()) {
        cellFilesystem.readFileIfItExists(cellFilesystem.resolve(entry.getPath().getPath())).ifPresent(contents -> entry.setContents(contents.getBytes()));
      }
    }
    Path stateDumpPath=Paths.get(distributedBuildStateFile);
    BuildJobStateSerializer.serialize(jobState,filesystem.newFileOutputStream(stateDumpPath));
    return ExitCode.SUCCESS;
  }
  BuckVersion buckVersion=getBuckVersion();
  Preconditions.checkArgument(params.getInvocationInfo().isPresent());
  distBuildClientStats.setIsLocalFallbackBuildEnabled(distBuildConfig.isSlowLocalBuildFallbackModeEnabled());
  ListenableFuture<?> localBuildFuture;
  ListenableFuture<?> distributedBuildFuture;
  Object distributedBuildExitCodeLock=new Object();
  AtomicReference<StampedeId> stampedeIdReference=new AtomicReference<>(createPendingStampedeId());
  AtomicInteger distributedBuildExitCode=new AtomicInteger(com.facebook.buck.distributed.ExitCode.DISTRIBUTED_PENDING_EXIT_CODE.getCode());
  CountDownLatch localBuildInitializationLatch=new CountDownLatch(com.facebook.buck.distributed.ExitCode.DISTRIBUTED_PENDING_EXIT_CODE.getCode());
  AtomicInteger localBuildExitCode=new AtomicInteger(com.facebook.buck.distributed.ExitCode.LOCAL_PENDING_EXIT_CODE.getCode());
  try (DistBuildService distBuildService=DistBuildFactory.newDistBuildService(params)){
    ListeningExecutorService stampedeControllerExecutor=createStampedeControllerExecutorService(distBuildConfig.getControllerMaxThreadCount());
    LogStateTracker distBuildLogStateTracker=DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(),filesystem,distBuildService);
    final RemoteBuildRuleSynchronizer remoteBuildSynchronizer=new RemoteBuildRuleSynchronizer(distBuildConfig.shouldAlwaysWaitForRemoteBuildBeforeProceedingLocally());
    BuildController build=new BuildController(BuildControllerArgs.builder().setBuilderExecutorArgs(params.createBuilderArgs()).setTopLevelTargets(buildTargets).setBuildGraphs(graphs).setCachingBuildEngineDelegate(Optional.of(new LocalCachingBuildEngineDelegate(params.getFileHashCache()))).setAsyncJobState(asyncJobState).setDistBuildCellIndexer(distBuildCellIndexer).setDistBuildService(distBuildService).setDistBuildLogStateTracker(distBuildLogStateTracker).setBuckVersion(buckVersion).setDistBuildClientStats(distBuildClientStats).setScheduler(params.getScheduledExecutor()).setMaxTimeoutWaitingForLogsMillis(distBuildConfig.getMaxWaitForRemoteLogsToBeAvailableMillis()).setLogMaterializationEnabled(distBuildConfig.getLogMaterializationEnabled()).setRemoteBuildRuleCompletionNotifier(remoteBuildSynchronizer).setStampedeIdReference(stampedeIdReference).setBuildLabel(distBuildConfig.getBuildLabel()).build());
    localBuildFuture=Preconditions.checkNotNull(params.getExecutors().get(ExecutorPool.CPU)).submit(() -> {
      performStampedeLocalBuild(params,graphs,executorService,distBuildClientStats,ruleKeyCacheScope,distributedBuildExitCodeLock,distributedBuildExitCode,localBuildInitializationLatch,localBuildExitCode,remoteBuildSynchronizer);
    }
);
    distributedBuildFuture=Preconditions.checkNotNull(params.getExecutors().get(ExecutorPool.CPU)).submit(() -> {
      performStampedeDistributedBuild(distBuildService,params,distBuildConfig,stampedeControllerExecutor,filesystem,fileHashCache,started,distributedBuildExitCodeLock,stampedeIdReference,distributedBuildExitCode,localBuildInitializationLatch,localBuildExitCode,remoteBuildSynchronizer,build);
    }
);
    try {
      localBuildFuture.get();
    }
 catch (    ExecutionException e) {
      LOG.error(e);
      throw new RuntimeException(e);
    }
    if (distributedBuildExitCode.get() == com.facebook.buck.distributed.ExitCode.LOCAL_BUILD_FINISHED_FIRST.getCode()) {
      LOG.warn("String_Node_Str");
      boolean succeededLocally=localBuildExitCode.get() == 0;
      terminateStampedeBuild(distBuildService,Preconditions.checkNotNull(stampedeIdReference.get()),succeededLocally ? BuildStatus.FINISHED_SUCCESSFULLY : BuildStatus.FAILED,(succeededLocally ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
    }
    distBuildClientStats.setStampedeId(Preconditions.checkNotNull(stampedeIdReference.get()).getId());
    distBuildClientStats.setDistributedBuildExitCode(distributedBuildExitCode.get());
    distributedBuildFuture.cancel(true);
    stateAndCells.cancel();
    stampedeControllerExecutor.shutdown();
    if (!stampedeControllerExecutor.awaitTermination(STAMPEDE_EXECUTOR_SHUTDOWN_TIMEOUT_MILLIS,TimeUnit.MILLISECONDS)) {
      LOG.warn("String_Node_Str" + "String_Node_Str");
      stampedeControllerExecutor.shutdownNow();
    }
    try {
      Set<String> cacheMissRequestKeys=distBuildClientEventListener.getDefaultCacheMissRequestKeys();
      ArtifactCacheBuckConfig artifactCacheBuckConfig=ArtifactCacheBuckConfig.of(distBuildConfig.getBuckConfig());
      List<RuleKeyLogEntry> ruleKeyLogs=distBuildService.fetchRuleKeyLogs(cacheMissRequestKeys,artifactCacheBuckConfig.getRepository(),artifactCacheBuckConfig.getScheduleType(),true);
      params.getBuckEventBus().post(distBuildClientEventListener.createDistBuildClientCacheResultsEvent(ruleKeyLogs));
    }
 catch (    Exception ex) {
      LOG.error("String_Node_Str",ex);
    }
    performStampedePostBuildAnalysis(params,distBuildConfig,filesystem,distBuildClientStats,stampedeIdReference,distributedBuildExitCode,localBuildExitCode,distBuildLogStateTracker);
    if (distributedBuildExitCode.get() == 0) {
      distBuildClientStats.stopTimer(POST_DISTRIBUTED_BUILD_LOCAL_STEPS);
    }
    if (distBuildClientStats.hasStampedeId()) {
      params.getBuckEventBus().post(new DistBuildClientStatsEvent(distBuildClientStats.generateStats()));
    }
    return ExitCode.map(localBuildExitCode.get());
  }
 }

Fixed version (ground truth):
private ExitCode executeDistBuild(CommandRunnerParams params,DistBuildConfig distBuildConfig,ActionAndTargetGraphs graphs,WeightedListeningExecutorService executorService,ProjectFilesystem filesystem,FileHashCache fileHashCache,ClientStatsTracker distBuildClientStats,RuleKeyCacheScope<RuleKey> ruleKeyCacheScope) throws IOException, InterruptedException {
  Preconditions.checkNotNull(distBuildClientEventListener);
  if (distributedBuildStateFile == null && distBuildConfig.getBuildMode().equals(BuildMode.DISTRIBUTED_BUILD_WITH_LOCAL_COORDINATOR) && !distBuildConfig.getMinionQueue().isPresent()) {
    throw new HumanReadableException("String_Node_Str");
  }
  BuildEvent.DistBuildStarted started=BuildEvent.distBuildStarted();
  params.getBuckEventBus().post(started);
  LOG.info("String_Node_Str");
  AsyncJobStateAndCells stateAndCells=computeDistBuildState(params,graphs,executorService,Optional.of(distBuildClientStats));
  ListenableFuture<BuildJobState> asyncJobState=stateAndCells.asyncJobState;
  DistBuildCellIndexer distBuildCellIndexer=stateAndCells.distBuildCellIndexer;
  if (distributedBuildStateFile != null) {
    BuildJobState jobState;
    try {
      jobState=asyncJobState.get();
    }
 catch (    ExecutionException e) {
      throw new RuntimeException("String_Node_Str",e);
    }
    for (    BuildJobStateFileHashes cell : jobState.getFileHashes()) {
      ProjectFilesystem cellFilesystem=Preconditions.checkNotNull(distBuildCellIndexer.getLocalFilesystemsByCellIndex().get(cell.getCellIndex()));
      for (      BuildJobStateFileHashEntry entry : cell.getEntries()) {
        cellFilesystem.readFileIfItExists(cellFilesystem.resolve(entry.getPath().getPath())).ifPresent(contents -> entry.setContents(contents.getBytes()));
      }
    }
    Path stateDumpPath=Paths.get(distributedBuildStateFile);
    BuildJobStateSerializer.serialize(jobState,filesystem.newFileOutputStream(stateDumpPath));
    return ExitCode.SUCCESS;
  }
  BuckVersion buckVersion=getBuckVersion();
  Preconditions.checkArgument(params.getInvocationInfo().isPresent());
  distBuildClientStats.setIsLocalFallbackBuildEnabled(distBuildConfig.isSlowLocalBuildFallbackModeEnabled());
  ListenableFuture<?> localBuildFuture;
  ListenableFuture<?> distributedBuildFuture;
  Object distributedBuildExitCodeLock=new Object();
  AtomicReference<StampedeId> stampedeIdReference=new AtomicReference<>(createPendingStampedeId());
  AtomicInteger distributedBuildExitCode=new AtomicInteger(com.facebook.buck.distributed.ExitCode.DISTRIBUTED_PENDING_EXIT_CODE.getCode());
  CountDownLatch localBuildInitializationLatch=new CountDownLatch(1);
  AtomicInteger localBuildExitCode=new AtomicInteger(com.facebook.buck.distributed.ExitCode.LOCAL_PENDING_EXIT_CODE.getCode());
  try (DistBuildService distBuildService=DistBuildFactory.newDistBuildService(params)){
    ListeningExecutorService stampedeControllerExecutor=createStampedeControllerExecutorService(distBuildConfig.getControllerMaxThreadCount());
    LogStateTracker distBuildLogStateTracker=DistBuildFactory.newDistBuildLogStateTracker(params.getInvocationInfo().get().getLogDirectoryPath(),filesystem,distBuildService);
    final RemoteBuildRuleSynchronizer remoteBuildSynchronizer=new RemoteBuildRuleSynchronizer(distBuildConfig.shouldAlwaysWaitForRemoteBuildBeforeProceedingLocally());
    BuildController build=new BuildController(BuildControllerArgs.builder().setBuilderExecutorArgs(params.createBuilderArgs()).setTopLevelTargets(buildTargets).setBuildGraphs(graphs).setCachingBuildEngineDelegate(Optional.of(new LocalCachingBuildEngineDelegate(params.getFileHashCache()))).setAsyncJobState(asyncJobState).setDistBuildCellIndexer(distBuildCellIndexer).setDistBuildService(distBuildService).setDistBuildLogStateTracker(distBuildLogStateTracker).setBuckVersion(buckVersion).setDistBuildClientStats(distBuildClientStats).setScheduler(params.getScheduledExecutor()).setMaxTimeoutWaitingForLogsMillis(distBuildConfig.getMaxWaitForRemoteLogsToBeAvailableMillis()).setLogMaterializationEnabled(distBuildConfig.getLogMaterializationEnabled()).setRemoteBuildRuleCompletionNotifier(remoteBuildSynchronizer).setStampedeIdReference(stampedeIdReference).setBuildLabel(distBuildConfig.getBuildLabel()).build());
    localBuildFuture=Preconditions.checkNotNull(params.getExecutors().get(ExecutorPool.CPU)).submit(() -> {
      performStampedeLocalBuild(params,graphs,executorService,distBuildClientStats,ruleKeyCacheScope,distributedBuildExitCodeLock,distributedBuildExitCode,localBuildInitializationLatch,localBuildExitCode,remoteBuildSynchronizer);
    }
);
    distributedBuildFuture=Preconditions.checkNotNull(params.getExecutors().get(ExecutorPool.CPU)).submit(() -> {
      performStampedeDistributedBuild(distBuildService,params,distBuildConfig,stampedeControllerExecutor,filesystem,fileHashCache,started,distributedBuildExitCodeLock,stampedeIdReference,distributedBuildExitCode,localBuildInitializationLatch,localBuildExitCode,remoteBuildSynchronizer,build);
    }
);
    try {
      localBuildFuture.get();
    }
 catch (    ExecutionException e) {
      LOG.error(e);
      throw new RuntimeException(e);
    }
    if (distributedBuildExitCode.get() == com.facebook.buck.distributed.ExitCode.LOCAL_BUILD_FINISHED_FIRST.getCode()) {
      LOG.warn("String_Node_Str");
      boolean succeededLocally=localBuildExitCode.get() == 0;
      terminateStampedeBuild(distBuildService,Preconditions.checkNotNull(stampedeIdReference.get()),succeededLocally ? BuildStatus.FINISHED_SUCCESSFULLY : BuildStatus.FAILED,(succeededLocally ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str");
    }
    distBuildClientStats.setStampedeId(Preconditions.checkNotNull(stampedeIdReference.get()).getId());
    distBuildClientStats.setDistributedBuildExitCode(distributedBuildExitCode.get());
    distributedBuildFuture.cancel(true);
    stateAndCells.cancel();
    stampedeControllerExecutor.shutdown();
    if (!stampedeControllerExecutor.awaitTermination(STAMPEDE_EXECUTOR_SHUTDOWN_TIMEOUT_MILLIS,TimeUnit.MILLISECONDS)) {
      LOG.warn("String_Node_Str" + "String_Node_Str");
      stampedeControllerExecutor.shutdownNow();
    }
    try {
      Set<String> cacheMissRequestKeys=distBuildClientEventListener.getDefaultCacheMissRequestKeys();
      ArtifactCacheBuckConfig artifactCacheBuckConfig=ArtifactCacheBuckConfig.of(distBuildConfig.getBuckConfig());
      List<RuleKeyLogEntry> ruleKeyLogs=distBuildService.fetchRuleKeyLogs(cacheMissRequestKeys,artifactCacheBuckConfig.getRepository(),artifactCacheBuckConfig.getScheduleType(),true);
      params.getBuckEventBus().post(distBuildClientEventListener.createDistBuildClientCacheResultsEvent(ruleKeyLogs));
    }
 catch (    Exception ex) {
      LOG.error("String_Node_Str",ex);
    }
    performStampedePostBuildAnalysis(params,distBuildConfig,filesystem,distBuildClientStats,stampedeIdReference,distributedBuildExitCode,localBuildExitCode,distBuildLogStateTracker);
    if (distributedBuildExitCode.get() == 0) {
      distBuildClientStats.stopTimer(POST_DISTRIBUTED_BUILD_LOCAL_STEPS);
    }
    if (distBuildClientStats.hasStampedeId()) {
      params.getBuckEventBus().post(new DistBuildClientStatsEvent(distBuildClientStats.generateStats()));
    }
    return ExitCode.map(localBuildExitCode.get());
  }
 }