Program: 52887
Project: 52887
Buggy source:
ListenableFuture<BuildResult> build(){
  final AtomicReference<Long> outputSize=Atomics.newReference();
  ListenableFuture<List<BuildResult>> depResults=Futures.immediateFuture(Collections.emptyList());
  if (buildMode == CachingBuildEngine.BuildMode.DEEP || buildMode == CachingBuildEngine.BuildMode.POPULATE_FROM_REMOTE_CACHE) {
    depResults=buildRuleBuilderDelegate.getDepResults(rule,buildContext,executionContext);
  }
  ListenableFuture<BuildResult> buildResult=Futures.transformAsync(depResults,input -> buildOrFetchFromCache(),serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.SCHEDULING_MORE_WORK_RESOURCE_AMOUNTS));
  buildResult=Futures.catchingAsync(buildResult,Throwable.class,throwable -> {
    Preconditions.checkNotNull(throwable);
    buildRuleBuilderDelegate.setFirstFailure(throwable);
    Throwables.throwIfInstanceOf(throwable,Exception.class);
    throw new RuntimeException(throwable);
  }
);
  buildResult=Futures.transform(buildResult,(result) -> {
    buildRuleBuilderDelegate.markRuleAsUsed(rule,buildContext.getEventBus());
    return result;
  }
,MoreExecutors.directExecutor());
  AsyncFunction<BuildResult,BuildResult> callback=input -> {
    if (input.getStatus() != BuildRuleStatus.SUCCESS) {
      return Futures.immediateFuture(input);
    }
    try (Scope scope=LeafEvents.scope(buildContext.getEventBus(),"String_Node_Str")){
      BuildRuleSuccessType success=Preconditions.checkNotNull(input.getSuccess());
      if (success != BuildRuleSuccessType.BUILT_LOCALLY) {
        try {
          for (          String str : onDiskBuildInfo.getValuesOrThrow(BuildInfo.MetadataKey.RECORDED_PATHS)) {
            buildInfoRecorder.recordArtifact(Paths.get(str));
          }
        }
 catch (        IOException e) {
          LOG.error(e,"String_Node_Str",rule);
          throw e;
        }
      }
      if (success == BuildRuleSuccessType.BUILT_LOCALLY) {
        outputSize.set(buildInfoRecorder.getOutputSize());
      }
      if (success.outputsHaveChanged()) {
        if (rule instanceof HasPostBuildSteps) {
          executePostBuildSteps(((HasPostBuildSteps)rule).getPostBuildSteps(buildContext.getBuildContext()));
        }
        for (        Path path : buildInfoRecorder.getRecordedPaths()) {
          fileHashCache.invalidate(rule.getProjectFilesystem().resolve(path));
        }
      }
      if (SupportsInputBasedRuleKey.isSupported(rule) && success == BuildRuleSuccessType.BUILT_LOCALLY && !buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY).isPresent()) {
        Optional<RuleKey> inputRuleKey=calculateInputBasedRuleKey(buildContext.getEventBus());
        if (inputRuleKey.isPresent()) {
          buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY,inputRuleKey.get().toString());
        }
      }
      if (useDependencyFileRuleKey() && success == BuildRuleSuccessType.BUILT_LOCALLY) {
        ImmutableList<SourcePath> inputs=((SupportsDependencyFileRuleKey)rule).getInputsAfterBuildingLocally(buildContext.getBuildContext(),executionContext.getCellPathResolver());
        ImmutableList<String> inputStrings=inputs.stream().map(inputString -> DependencyFileEntry.fromSourcePath(inputString,pathResolver)).map(MoreFunctions.toJsonFunction()).collect(MoreCollectors.toImmutableList());
        buildInfoRecorder.addMetadata(BuildInfo.MetadataKey.DEP_FILE,inputStrings);
        Optional<RuleKeyAndInputs> depFileRuleKeyAndInputs=calculateDepFileRuleKey(Optional.of(inputStrings),false);
        if (depFileRuleKeyAndInputs.isPresent()) {
          RuleKey depFileRuleKey=depFileRuleKeyAndInputs.get().getRuleKey();
          buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY,depFileRuleKey.toString());
          if (useManifestCaching()) {
            Optional<RuleKeyAndInputs> manifestKey=calculateManifestKey(buildContext.getEventBus());
            if (manifestKey.isPresent()) {
              buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.MANIFEST_KEY,manifestKey.get().getRuleKey().toString());
              updateAndStoreManifest(depFileRuleKeyAndInputs.get().getRuleKey(),depFileRuleKeyAndInputs.get().getInputs(),manifestKey.get(),buildContext.getArtifactCache());
            }
          }
        }
      }
      if (success == BuildRuleSuccessType.BUILT_LOCALLY && shouldUploadToCache(success,Preconditions.checkNotNull(outputSize.get()))) {
        ImmutableSortedMap.Builder<String,String> outputHashes=ImmutableSortedMap.naturalOrder();
        for (        Path path : buildInfoRecorder.getOutputPaths()) {
          outputHashes.put(path.toString(),fileHashCache.get(rule.getProjectFilesystem().resolve(path)).toString());
        }
        buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.RECORDED_PATH_HASHES,outputHashes.build());
      }
      if (success != BuildRuleSuccessType.BUILT_LOCALLY && success.outputsHaveChanged()) {
        Optional<ImmutableMap<String,String>> hashes=onDiskBuildInfo.getBuildMap(BuildInfo.MetadataKey.RECORDED_PATH_HASHES);
        if (hashes.isPresent() && verifyRecordedPathHashes(rule.getBuildTarget(),rule.getProjectFilesystem(),hashes.get())) {
          for (          Map.Entry<String,String> ent : hashes.get().entrySet()) {
            Path path=rule.getProjectFilesystem().getPath(ent.getKey());
            HashCode hashCode=HashCode.fromString(ent.getValue());
            fileHashCache.set(rule.getProjectFilesystem().resolve(path),hashCode);
          }
        }
      }
      BuildId buildId=buildContext.getBuildId();
      if (success == BuildRuleSuccessType.BUILT_LOCALLY) {
        buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.ORIGIN_BUILD_ID,buildId.toString());
      }
 else       if (success.outputsHaveChanged()) {
        Preconditions.checkState(buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.ORIGIN_BUILD_ID).isPresent(),"String_Node_Str",BuildInfo.MetadataKey.ORIGIN_BUILD_ID,success);
      }
      buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.TARGET,rule.getBuildTarget().toString());
      buildInfoRecorder.addMetadata(BuildInfo.MetadataKey.RECORDED_PATHS,buildInfoRecorder.getRecordedPaths().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
      if (success.shouldWriteRecordedMetadataToDiskAfterBuilding()) {
        try {
          boolean clearExistingMetadata=success.shouldClearAndOverwriteMetadataOnDisk();
          buildInfoRecorder.writeMetadataToDisk(clearExistingMetadata);
        }
 catch (        IOException e) {
          throw new IOException(String.format("String_Node_Str",rule),e);
        }
      }
      try {
        if (rule instanceof InitializableFromDisk) {
          doInitializeFromDisk((InitializableFromDisk<?>)rule);
        }
      }
 catch (      IOException e) {
        throw new IOException(String.format("String_Node_Str",rule,e.getMessage()),e);
      }
    }
     return Futures.immediateFuture(input);
  }
;
  buildResult=Futures.transformAsync(buildResult,ruleAsyncFunction(buildContext.getEventBus(),callback),serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.RULE_KEY_COMPUTATION_RESOURCE_AMOUNTS));
  buildResult=Futures.catchingAsync(buildResult,Exception.class,thrown -> {
    LOG.debug(thrown,"String_Node_Str",rule.getBuildTarget());
    if (consoleLogBuildFailuresInline) {
      buildContext.getEventBus().post(ConsoleEvent.severe(getErrorMessageIncludingBuildRule(thrown)));
    }
    thrown=maybeAttachBuildRuleNameToException(thrown);
    recordFailureAndCleanUp(thrown);
    return Futures.immediateFuture(BuildResult.failure(rule,thrown));
  }
);
  buildRuleBuilderDelegate.addAsyncCallback(MoreFutures.addListenableCallback(buildResult,new FutureCallback<BuildResult>(){
    private void uploadToCache(    BuildRuleSuccessType success){
      Set<RuleKey> ruleKeys=new HashSet<>();
      ruleKeys.add(ruleKeyFactories.getDefaultRuleKeyFactory().build(rule));
      if (SupportsInputBasedRuleKey.isSupported(rule)) {
        Optional<RuleKey> calculatedRuleKey=calculateInputBasedRuleKey(buildContext.getEventBus());
        Optional<RuleKey> onDiskRuleKey=onDiskBuildInfo.getRuleKey(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY);
        Optional<RuleKey> metaDataRuleKey=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY).map(RuleKey::new);
        Preconditions.checkState(calculatedRuleKey.equals(onDiskRuleKey),"String_Node_Str",rule.getBuildTarget(),rule.getType(),success,calculatedRuleKey,onDiskRuleKey);
        Preconditions.checkState(calculatedRuleKey.equals(metaDataRuleKey),"String_Node_Str",rule.getBuildTarget(),success,calculatedRuleKey,metaDataRuleKey);
        if (calculatedRuleKey.isPresent()) {
          ruleKeys.add(calculatedRuleKey.get());
        }
      }
      if (useManifestCaching()) {
        Optional<RuleKey> onDiskRuleKey=onDiskBuildInfo.getRuleKey(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY);
        Optional<RuleKey> metaDataRuleKey=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY).map(RuleKey::new);
        Preconditions.checkState(onDiskRuleKey.equals(metaDataRuleKey),"String_Node_Str",rule.getBuildTarget(),success,onDiskRuleKey,metaDataRuleKey);
        if (onDiskRuleKey.isPresent()) {
          ruleKeys.add(onDiskRuleKey.get());
        }
      }
      try {
        Optional<String> recordedPathHashes=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.RECORDED_PATH_HASHES);
        if (recordedPathHashes.isPresent() && !verifyRecordedPathHashes(rule.getBuildTarget(),rule.getProjectFilesystem(),recordedPathHashes.get())) {
          return;
        }
        buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.copyOf(ruleKeys),buildContext.getArtifactCache(),buildContext.getEventBus());
      }
 catch (      Throwable t) {
        buildContext.getEventBus().post(ThrowableConsoleEvent.create(t,"String_Node_Str",rule));
      }
    }
    private void handleResult(    BuildResult input){
      Optional<Long> outputSize=Optional.empty();
      Optional<HashCode> outputHash=Optional.empty();
      Optional<BuildRuleSuccessType> successType=Optional.empty();
      boolean shouldUploadToCache=false;
      BuildRuleEvent.Resumed resumedEvent=BuildRuleEvent.resumed(rule,buildRuleDurationTracker,ruleKeyFactories.getDefaultRuleKeyFactory());
      LOG.verbose(resumedEvent.toString());
      buildContext.getEventBus().post(resumedEvent);
      if (input.getStatus() == BuildRuleStatus.SUCCESS) {
        BuildRuleSuccessType success=Preconditions.checkNotNull(input.getSuccess());
        successType=Optional.of(success);
        if (success == BuildRuleSuccessType.BUILT_LOCALLY || success.shouldUploadResultingArtifact()) {
          try {
            outputSize=Optional.of(buildInfoRecorder.getOutputSize());
          }
 catch (          IOException e) {
            buildContext.getEventBus().post(ThrowableConsoleEvent.create(e,"String_Node_Str",rule));
          }
        }
        if (outputSize.isPresent() && shouldHashOutputs(success,outputSize.get())) {
          try {
            outputHash=Optional.of(buildInfoRecorder.getOutputHash(fileHashCache));
          }
 catch (          IOException e) {
            buildContext.getEventBus().post(ThrowableConsoleEvent.create(e,"String_Node_Str",rule));
          }
        }
        shouldUploadToCache=outputSize.isPresent() && shouldUploadToCache(success,outputSize.get());
        if (shouldUploadToCache) {
          uploadToCache(success);
        }
      }
      boolean failureOrBuiltLocally=input.getStatus() == BuildRuleStatus.FAIL || input.getSuccess() == BuildRuleSuccessType.BUILT_LOCALLY;
      BuildRuleEvent.Finished finished=BuildRuleEvent.finished(resumedEvent,getBuildRuleKeys(),input.getStatus(),input.getCacheResult(),onDiskBuildInfo.getBuildValue(BuildInfo.MetadataKey.ORIGIN_BUILD_ID).map(BuildId::new),successType,shouldUploadToCache,outputHash,outputSize,getBuildRuleDiagnosticData(failureOrBuiltLocally));
      LOG.verbose(finished.toString());
      buildContext.getEventBus().post(finished);
    }
    @Override public void onSuccess(    BuildResult input){
      handleResult(input);
      if (input.getFailure() instanceof InterruptedException) {
        Threads.interruptCurrentThread();
      }
    }
    @Override public void onFailure(    @Nonnull Throwable thrown){
      throw new AssertionError("String_Node_Str");
    }
  }
,serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.RULE_KEY_COMPUTATION_RESOURCE_AMOUNTS)));
  return buildResult;
}

Fixed version (ground truth):
ListenableFuture<BuildResult> build(){
  final AtomicReference<Long> outputSize=Atomics.newReference();
  ListenableFuture<List<BuildResult>> depResults=Futures.immediateFuture(Collections.emptyList());
  if (buildMode == CachingBuildEngine.BuildMode.DEEP || buildMode == CachingBuildEngine.BuildMode.POPULATE_FROM_REMOTE_CACHE) {
    depResults=buildRuleBuilderDelegate.getDepResults(rule,buildContext,executionContext);
  }
  ListenableFuture<BuildResult> buildResult=Futures.transformAsync(depResults,input -> buildOrFetchFromCache(),serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.SCHEDULING_MORE_WORK_RESOURCE_AMOUNTS));
  buildResult=Futures.catchingAsync(buildResult,Throwable.class,throwable -> {
    Preconditions.checkNotNull(throwable);
    buildRuleBuilderDelegate.setFirstFailure(throwable);
    Throwables.throwIfInstanceOf(throwable,Exception.class);
    throw new RuntimeException(throwable);
  }
);
  buildResult=Futures.transform(buildResult,(result) -> {
    buildRuleBuilderDelegate.markRuleAsUsed(rule,buildContext.getEventBus());
    return result;
  }
,MoreExecutors.directExecutor());
  AsyncFunction<BuildResult,BuildResult> callback=input -> {
    if (input.getStatus() != BuildRuleStatus.SUCCESS) {
      return Futures.immediateFuture(input);
    }
    try (Scope scope=LeafEvents.scope(buildContext.getEventBus(),"String_Node_Str")){
      BuildRuleSuccessType success=Preconditions.checkNotNull(input.getSuccess());
      if (success != BuildRuleSuccessType.BUILT_LOCALLY) {
        try {
          for (          String str : onDiskBuildInfo.getValuesOrThrow(BuildInfo.MetadataKey.RECORDED_PATHS)) {
            buildInfoRecorder.recordArtifact(Paths.get(str));
          }
        }
 catch (        IOException e) {
          LOG.error(e,"String_Node_Str",rule);
          throw e;
        }
      }
      if (success == BuildRuleSuccessType.BUILT_LOCALLY) {
        outputSize.set(buildInfoRecorder.getOutputSize());
      }
      if (success.outputsHaveChanged()) {
        if (rule instanceof HasPostBuildSteps) {
          executePostBuildSteps(((HasPostBuildSteps)rule).getPostBuildSteps(buildContext.getBuildContext()));
        }
        for (        Path path : buildInfoRecorder.getRecordedPaths()) {
          fileHashCache.invalidate(rule.getProjectFilesystem().resolve(path));
        }
      }
      if (SupportsInputBasedRuleKey.isSupported(rule) && success == BuildRuleSuccessType.BUILT_LOCALLY && !buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY).isPresent()) {
        Optional<RuleKey> inputRuleKey=calculateInputBasedRuleKey(buildContext.getEventBus());
        if (inputRuleKey.isPresent()) {
          buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY,inputRuleKey.get().toString());
        }
      }
      if (useDependencyFileRuleKey() && success == BuildRuleSuccessType.BUILT_LOCALLY) {
        ImmutableList<SourcePath> inputs=((SupportsDependencyFileRuleKey)rule).getInputsAfterBuildingLocally(buildContext.getBuildContext(),executionContext.getCellPathResolver());
        ImmutableList<String> inputStrings=inputs.stream().map(inputString -> DependencyFileEntry.fromSourcePath(inputString,pathResolver)).map(MoreFunctions.toJsonFunction()).collect(MoreCollectors.toImmutableList());
        buildInfoRecorder.addMetadata(BuildInfo.MetadataKey.DEP_FILE,inputStrings);
        Optional<RuleKeyAndInputs> depFileRuleKeyAndInputs=calculateDepFileRuleKey(Optional.of(inputStrings),false);
        if (depFileRuleKeyAndInputs.isPresent()) {
          RuleKey depFileRuleKey=depFileRuleKeyAndInputs.get().getRuleKey();
          buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY,depFileRuleKey.toString());
          if (useManifestCaching()) {
            Optional<RuleKeyAndInputs> manifestKey=calculateManifestKey(buildContext.getEventBus());
            if (manifestKey.isPresent()) {
              buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.MANIFEST_KEY,manifestKey.get().getRuleKey().toString());
              updateAndStoreManifest(depFileRuleKeyAndInputs.get().getRuleKey(),depFileRuleKeyAndInputs.get().getInputs(),manifestKey.get(),buildContext.getArtifactCache());
            }
          }
        }
      }
      if (success == BuildRuleSuccessType.BUILT_LOCALLY && shouldUploadToCache(success,Preconditions.checkNotNull(outputSize.get()))) {
        ImmutableSortedMap.Builder<String,String> outputHashes=ImmutableSortedMap.naturalOrder();
        for (        Path path : buildInfoRecorder.getOutputPaths()) {
          outputHashes.put(path.toString(),fileHashCache.get(rule.getProjectFilesystem().resolve(path)).toString());
        }
        buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.RECORDED_PATH_HASHES,outputHashes.build());
      }
      if (success != BuildRuleSuccessType.BUILT_LOCALLY && success.outputsHaveChanged()) {
        Optional<ImmutableMap<String,String>> hashes=onDiskBuildInfo.getBuildMap(BuildInfo.MetadataKey.RECORDED_PATH_HASHES);
        if (hashes.isPresent() && verifyRecordedPathHashes(rule.getBuildTarget(),rule.getProjectFilesystem(),hashes.get())) {
          for (          Map.Entry<String,String> ent : hashes.get().entrySet()) {
            Path path=rule.getProjectFilesystem().getPath(ent.getKey());
            HashCode hashCode=HashCode.fromString(ent.getValue());
            fileHashCache.set(rule.getProjectFilesystem().resolve(path),hashCode);
          }
        }
      }
      BuildId buildId=buildContext.getBuildId();
      if (success == BuildRuleSuccessType.BUILT_LOCALLY) {
        buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.ORIGIN_BUILD_ID,buildId.toString());
      }
 else       if (success.outputsHaveChanged()) {
        Preconditions.checkState(buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.ORIGIN_BUILD_ID).isPresent(),"String_Node_Str",BuildInfo.MetadataKey.ORIGIN_BUILD_ID,success);
      }
      buildInfoRecorder.addBuildMetadata(BuildInfo.MetadataKey.TARGET,rule.getBuildTarget().toString());
      buildInfoRecorder.addMetadata(BuildInfo.MetadataKey.RECORDED_PATHS,buildInfoRecorder.getRecordedPaths().stream().map(Object::toString).collect(MoreCollectors.toImmutableList()));
      if (success.shouldWriteRecordedMetadataToDiskAfterBuilding()) {
        try {
          boolean clearExistingMetadata=success.shouldClearAndOverwriteMetadataOnDisk();
          buildInfoRecorder.writeMetadataToDisk(clearExistingMetadata);
        }
 catch (        IOException e) {
          throw new IOException(String.format("String_Node_Str",rule),e);
        }
      }
      try {
        if (rule instanceof InitializableFromDisk) {
          doInitializeFromDisk((InitializableFromDisk<?>)rule);
        }
      }
 catch (      IOException e) {
        throw new IOException(String.format("String_Node_Str",rule,e.getMessage()),e);
      }
    }
     return Futures.immediateFuture(input);
  }
;
  buildResult=Futures.transformAsync(buildResult,ruleAsyncFunction(buildContext.getEventBus(),callback),serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.RULE_KEY_COMPUTATION_RESOURCE_AMOUNTS));
  buildResult=Futures.catchingAsync(buildResult,Throwable.class,thrown -> {
    LOG.debug(thrown,"String_Node_Str",rule.getBuildTarget());
    if (consoleLogBuildFailuresInline) {
      buildContext.getEventBus().post(ConsoleEvent.severe(getErrorMessageIncludingBuildRule(thrown)));
    }
    thrown=maybeAttachBuildRuleNameToException(thrown);
    recordFailureAndCleanUp(thrown);
    return Futures.immediateFuture(BuildResult.failure(rule,thrown));
  }
);
  buildRuleBuilderDelegate.addAsyncCallback(MoreFutures.addListenableCallback(buildResult,new FutureCallback<BuildResult>(){
    private void uploadToCache(    BuildRuleSuccessType success){
      Set<RuleKey> ruleKeys=new HashSet<>();
      ruleKeys.add(ruleKeyFactories.getDefaultRuleKeyFactory().build(rule));
      if (SupportsInputBasedRuleKey.isSupported(rule)) {
        Optional<RuleKey> calculatedRuleKey=calculateInputBasedRuleKey(buildContext.getEventBus());
        Optional<RuleKey> onDiskRuleKey=onDiskBuildInfo.getRuleKey(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY);
        Optional<RuleKey> metaDataRuleKey=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.INPUT_BASED_RULE_KEY).map(RuleKey::new);
        Preconditions.checkState(calculatedRuleKey.equals(onDiskRuleKey),"String_Node_Str",rule.getBuildTarget(),rule.getType(),success,calculatedRuleKey,onDiskRuleKey);
        Preconditions.checkState(calculatedRuleKey.equals(metaDataRuleKey),"String_Node_Str",rule.getBuildTarget(),success,calculatedRuleKey,metaDataRuleKey);
        if (calculatedRuleKey.isPresent()) {
          ruleKeys.add(calculatedRuleKey.get());
        }
      }
      if (useManifestCaching()) {
        Optional<RuleKey> onDiskRuleKey=onDiskBuildInfo.getRuleKey(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY);
        Optional<RuleKey> metaDataRuleKey=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.DEP_FILE_RULE_KEY).map(RuleKey::new);
        Preconditions.checkState(onDiskRuleKey.equals(metaDataRuleKey),"String_Node_Str",rule.getBuildTarget(),success,onDiskRuleKey,metaDataRuleKey);
        if (onDiskRuleKey.isPresent()) {
          ruleKeys.add(onDiskRuleKey.get());
        }
      }
      try {
        Optional<String> recordedPathHashes=buildInfoRecorder.getBuildMetadataFor(BuildInfo.MetadataKey.RECORDED_PATH_HASHES);
        if (recordedPathHashes.isPresent() && !verifyRecordedPathHashes(rule.getBuildTarget(),rule.getProjectFilesystem(),recordedPathHashes.get())) {
          return;
        }
        buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.copyOf(ruleKeys),buildContext.getArtifactCache(),buildContext.getEventBus());
      }
 catch (      Throwable t) {
        buildContext.getEventBus().post(ThrowableConsoleEvent.create(t,"String_Node_Str",rule));
      }
    }
    private void handleResult(    BuildResult input){
      Optional<Long> outputSize=Optional.empty();
      Optional<HashCode> outputHash=Optional.empty();
      Optional<BuildRuleSuccessType> successType=Optional.empty();
      boolean shouldUploadToCache=false;
      BuildRuleEvent.Resumed resumedEvent=BuildRuleEvent.resumed(rule,buildRuleDurationTracker,ruleKeyFactories.getDefaultRuleKeyFactory());
      LOG.verbose(resumedEvent.toString());
      buildContext.getEventBus().post(resumedEvent);
      if (input.getStatus() == BuildRuleStatus.SUCCESS) {
        BuildRuleSuccessType success=Preconditions.checkNotNull(input.getSuccess());
        successType=Optional.of(success);
        if (success == BuildRuleSuccessType.BUILT_LOCALLY || success.shouldUploadResultingArtifact()) {
          try {
            outputSize=Optional.of(buildInfoRecorder.getOutputSize());
          }
 catch (          IOException e) {
            buildContext.getEventBus().post(ThrowableConsoleEvent.create(e,"String_Node_Str",rule));
          }
        }
        if (outputSize.isPresent() && shouldHashOutputs(success,outputSize.get())) {
          try {
            outputHash=Optional.of(buildInfoRecorder.getOutputHash(fileHashCache));
          }
 catch (          IOException e) {
            buildContext.getEventBus().post(ThrowableConsoleEvent.create(e,"String_Node_Str",rule));
          }
        }
        shouldUploadToCache=outputSize.isPresent() && shouldUploadToCache(success,outputSize.get());
        if (shouldUploadToCache) {
          uploadToCache(success);
        }
      }
      boolean failureOrBuiltLocally=input.getStatus() == BuildRuleStatus.FAIL || input.getSuccess() == BuildRuleSuccessType.BUILT_LOCALLY;
      BuildRuleEvent.Finished finished=BuildRuleEvent.finished(resumedEvent,getBuildRuleKeys(),input.getStatus(),input.getCacheResult(),onDiskBuildInfo.getBuildValue(BuildInfo.MetadataKey.ORIGIN_BUILD_ID).map(BuildId::new),successType,shouldUploadToCache,outputHash,outputSize,getBuildRuleDiagnosticData(failureOrBuiltLocally));
      LOG.verbose(finished.toString());
      buildContext.getEventBus().post(finished);
    }
    @Override public void onSuccess(    BuildResult input){
      handleResult(input);
      if (input.getFailure() instanceof InterruptedException) {
        Threads.interruptCurrentThread();
      }
    }
    @Override public void onFailure(    @Nonnull Throwable thrown){
      throw new AssertionError("String_Node_Str");
    }
  }
,serviceByAdjustingDefaultWeightsTo(CachingBuildEngine.RULE_KEY_COMPUTATION_RESOURCE_AMOUNTS)));
  return buildResult;
}