Program: 52885
Project: 52885
Buggy source:
static AppleBundle createAppleBundle(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,Flavor defaultCxxFlavor,FlavorDomain<AppleCxxPlatform> appleCxxPlatforms,TargetGraph targetGraph,BuildTarget buildTarget,ProjectFilesystem projectFilesystem,BuildRuleParams params,BuildRuleResolver resolver,CodeSignIdentityStore codeSignIdentityStore,ProvisioningProfileStore provisioningProfileStore,BuildTarget binary,Either<AppleBundleExtension,String> extension,Optional<String> productName,final SourcePath infoPlist,ImmutableMap<String,String> infoPlistSubstitutions,ImmutableSortedSet<BuildTarget> deps,ImmutableSortedSet<BuildTarget> tests,AppleDebugFormat debugFormat,boolean dryRunCodeSigning,boolean cacheable) throws NoSuchBuildTargetException {
  AppleCxxPlatform appleCxxPlatform=ApplePlatforms.getAppleCxxPlatformForBuildTarget(cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms,buildTarget,MultiarchFileInfos.create(appleCxxPlatforms,buildTarget));
  AppleBundleDestinations destinations;
  if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
    destinations=AppleBundleDestinations.platformFrameworkDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
  }
 else {
    destinations=AppleBundleDestinations.platformDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
  }
  AppleBundleResources collectedResources=AppleResources.collectResourceDirsAndFiles(targetGraph,resolver,Optional.empty(),targetGraph.get(buildTarget));
  ImmutableSet.Builder<SourcePath> frameworksBuilder=ImmutableSet.builder();
  if (INCLUDE_FRAMEWORKS.getRequiredValue(buildTarget)) {
    for (    BuildTarget dep : deps) {
      Optional<FrameworkDependencies> frameworkDependencies=resolver.requireMetadata(dep.withAppendedFlavors(FRAMEWORK_FLAVOR,NO_INCLUDE_FRAMEWORKS_FLAVOR,appleCxxPlatform.getCxxPlatform().getFlavor()),FrameworkDependencies.class);
      if (frameworkDependencies.isPresent()) {
        frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
      }
    }
  }
  for (  BuildTarget dep : deps) {
    Optional<TargetNode<PrebuiltAppleFrameworkDescriptionArg,?>> prebuiltNode=targetGraph.getOptional(dep).flatMap(node -> node.castArg(PrebuiltAppleFrameworkDescriptionArg.class));
    if (prebuiltNode.isPresent() && !prebuiltNode.get().getConstructorArg().getPreferredLinkage().equals(NativeLinkable.Linkage.STATIC)) {
      frameworksBuilder.add(resolver.requireRule(dep).getSourcePathToOutput());
    }
  }
  ImmutableSet<SourcePath> frameworks=frameworksBuilder.build();
  SourcePathRuleFinder ruleFinder=new SourcePathRuleFinder(resolver);
  SourcePathResolver sourcePathResolver=DefaultSourcePathResolver.from(ruleFinder);
  BuildTarget buildTargetWithoutBundleSpecificFlavors=stripBundleSpecificFlavors(buildTarget);
  Optional<AppleAssetCatalog> assetCatalog=createBuildRuleForTransitiveAssetCatalogDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,sourcePathResolver,appleCxxPlatform.getAppleSdk().getApplePlatform(),appleCxxPlatform.getMinVersion(),appleCxxPlatform.getActool());
  addToIndex(resolver,assetCatalog);
  Optional<CoreDataModel> coreDataModel=createBuildRulesForCoreDataDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,AppleBundle.getBinaryName(buildTarget,productName),appleCxxPlatform);
  addToIndex(resolver,coreDataModel);
  Optional<SceneKitAssets> sceneKitAssets=createBuildRulesForSceneKitAssetsDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,appleCxxPlatform);
  addToIndex(resolver,sceneKitAssets);
  BuildRule flavoredBinaryRule=getFlavoredBinaryRule(cxxPlatformFlavorDomain,defaultCxxFlavor,targetGraph,buildTargetWithoutBundleSpecificFlavors.getFlavors(),resolver,binary);
  if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
    debugFormat=AppleDebugFormat.NONE;
  }
  BuildTarget unstrippedTarget=flavoredBinaryRule.getBuildTarget().withoutFlavors(CxxStrip.RULE_FLAVOR,AppleDebuggableBinary.RULE_FLAVOR,AppleBinaryDescription.APP_FLAVOR).withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR).withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
  Optional<LinkerMapMode> linkerMapMode=LinkerMapMode.FLAVOR_DOMAIN.getValue(buildTarget);
  if (linkerMapMode.isPresent()) {
    unstrippedTarget=unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
  }
  BuildRule unstrippedBinaryRule=resolver.requireRule(unstrippedTarget);
  BuildRule targetDebuggableBinaryRule;
  Optional<AppleDsym> appleDsym;
  if (unstrippedBinaryRule instanceof ProvidesLinkedBinaryDeps) {
    BuildTarget binaryBuildTarget=getBinaryFromBuildRuleWithBinary(flavoredBinaryRule).getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
    targetDebuggableBinaryRule=createAppleDebuggableBinary(binaryBuildTarget,projectFilesystem,params,resolver,getBinaryFromBuildRuleWithBinary(flavoredBinaryRule),(ProvidesLinkedBinaryDeps)unstrippedBinaryRule,debugFormat,cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms);
    appleDsym=createAppleDsymForDebugFormat(debugFormat,binaryBuildTarget,projectFilesystem,params,resolver,(ProvidesLinkedBinaryDeps)unstrippedBinaryRule,cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms);
  }
 else {
    targetDebuggableBinaryRule=unstrippedBinaryRule;
    appleDsym=Optional.empty();
  }
  BuildRuleParams bundleParamsWithFlavoredBinaryDep=getBundleParamsWithUpdatedDeps(params,binary,ImmutableSet.<BuildRule>builder().add(targetDebuggableBinaryRule).addAll(Optionals.toStream(assetCatalog).iterator()).addAll(Optionals.toStream(coreDataModel).iterator()).addAll(Optionals.toStream(sceneKitAssets).iterator()).addAll(BuildRules.toBuildRulesFor(buildTarget,resolver,RichStream.from(collectedResources.getAll()).concat(frameworks.stream()).filter(BuildTargetSourcePath.class).map(BuildTargetSourcePath::getTarget).collect(MoreCollectors.toImmutableSet()))).addAll(Optionals.toStream(appleDsym).iterator()).build());
  ImmutableMap<SourcePath,String> extensionBundlePaths=collectFirstLevelAppleDependencyBundles(params.getBuildDeps(),destinations);
  return new AppleBundle(buildTarget,projectFilesystem,bundleParamsWithFlavoredBinaryDep,resolver,extension,productName,infoPlist,infoPlistSubstitutions,Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)),appleDsym,destinations,collectedResources,extensionBundlePaths,frameworks,appleCxxPlatform,assetCatalog,coreDataModel,sceneKitAssets,tests,codeSignIdentityStore,provisioningProfileStore,dryRunCodeSigning,cacheable);
}

Fixed version (ground truth):
static AppleBundle createAppleBundle(FlavorDomain<CxxPlatform> cxxPlatformFlavorDomain,Flavor defaultCxxFlavor,FlavorDomain<AppleCxxPlatform> appleCxxPlatforms,TargetGraph targetGraph,BuildTarget buildTarget,ProjectFilesystem projectFilesystem,BuildRuleParams params,BuildRuleResolver resolver,CodeSignIdentityStore codeSignIdentityStore,ProvisioningProfileStore provisioningProfileStore,BuildTarget binary,Either<AppleBundleExtension,String> extension,Optional<String> productName,final SourcePath infoPlist,ImmutableMap<String,String> infoPlistSubstitutions,ImmutableSortedSet<BuildTarget> deps,ImmutableSortedSet<BuildTarget> tests,AppleDebugFormat debugFormat,boolean dryRunCodeSigning,boolean cacheable) throws NoSuchBuildTargetException {
  AppleCxxPlatform appleCxxPlatform=ApplePlatforms.getAppleCxxPlatformForBuildTarget(cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms,buildTarget,MultiarchFileInfos.create(appleCxxPlatforms,buildTarget));
  AppleBundleDestinations destinations;
  if (extension.isLeft() && extension.getLeft().equals(AppleBundleExtension.FRAMEWORK)) {
    destinations=AppleBundleDestinations.platformFrameworkDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
  }
 else {
    destinations=AppleBundleDestinations.platformDestinations(appleCxxPlatform.getAppleSdk().getApplePlatform());
  }
  AppleBundleResources collectedResources=AppleResources.collectResourceDirsAndFiles(targetGraph,resolver,Optional.empty(),targetGraph.get(buildTarget));
  ImmutableSet.Builder<SourcePath> frameworksBuilder=ImmutableSet.builder();
  if (INCLUDE_FRAMEWORKS.getRequiredValue(buildTarget)) {
    for (    BuildTarget dep : deps) {
      Optional<FrameworkDependencies> frameworkDependencies=resolver.requireMetadata(dep.withAppendedFlavors(FRAMEWORK_FLAVOR,NO_INCLUDE_FRAMEWORKS_FLAVOR,appleCxxPlatform.getCxxPlatform().getFlavor()),FrameworkDependencies.class);
      if (frameworkDependencies.isPresent()) {
        frameworksBuilder.addAll(frameworkDependencies.get().getSourcePaths());
      }
    }
  }
  for (  BuildTarget dep : deps) {
    Optional<TargetNode<PrebuiltAppleFrameworkDescriptionArg,?>> prebuiltNode=targetGraph.getOptional(dep).flatMap(node -> node.castArg(PrebuiltAppleFrameworkDescriptionArg.class));
    if (prebuiltNode.isPresent() && !prebuiltNode.get().getConstructorArg().getPreferredLinkage().equals(NativeLinkable.Linkage.STATIC)) {
      frameworksBuilder.add(resolver.requireRule(dep).getSourcePathToOutput());
    }
  }
  ImmutableSet<SourcePath> frameworks=frameworksBuilder.build();
  SourcePathRuleFinder ruleFinder=new SourcePathRuleFinder(resolver);
  SourcePathResolver sourcePathResolver=DefaultSourcePathResolver.from(ruleFinder);
  BuildTarget buildTargetWithoutBundleSpecificFlavors=stripBundleSpecificFlavors(buildTarget);
  Optional<AppleAssetCatalog> assetCatalog=createBuildRuleForTransitiveAssetCatalogDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,sourcePathResolver,appleCxxPlatform.getAppleSdk().getApplePlatform(),appleCxxPlatform.getMinVersion(),appleCxxPlatform.getActool());
  addToIndex(resolver,assetCatalog);
  Optional<CoreDataModel> coreDataModel=createBuildRulesForCoreDataDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,AppleBundle.getBinaryName(buildTarget,productName),appleCxxPlatform);
  addToIndex(resolver,coreDataModel);
  Optional<SceneKitAssets> sceneKitAssets=createBuildRulesForSceneKitAssetsDependencies(targetGraph,buildTargetWithoutBundleSpecificFlavors,projectFilesystem,params,appleCxxPlatform);
  addToIndex(resolver,sceneKitAssets);
  BuildRule flavoredBinaryRule=getFlavoredBinaryRule(cxxPlatformFlavorDomain,defaultCxxFlavor,targetGraph,buildTargetWithoutBundleSpecificFlavors.getFlavors(),resolver,binary);
  if (!AppleDebuggableBinary.isBuildRuleDebuggable(flavoredBinaryRule)) {
    debugFormat=AppleDebugFormat.NONE;
  }
  BuildTarget unstrippedTarget=flavoredBinaryRule.getBuildTarget().withoutFlavors(CxxStrip.RULE_FLAVOR,AppleDebuggableBinary.RULE_FLAVOR,AppleBinaryDescription.APP_FLAVOR).withoutFlavors(StripStyle.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors()).withoutFlavors(AppleDebuggableBinary.RULE_FLAVOR).withoutFlavors(ImmutableSet.of(AppleBinaryDescription.APP_FLAVOR));
  Optional<LinkerMapMode> linkerMapMode=LinkerMapMode.FLAVOR_DOMAIN.getValue(buildTarget);
  if (linkerMapMode.isPresent()) {
    unstrippedTarget=unstrippedTarget.withAppendedFlavors(linkerMapMode.get().getFlavor());
  }
  BuildRule unstrippedBinaryRule=resolver.requireRule(unstrippedTarget);
  BuildRule targetDebuggableBinaryRule;
  Optional<AppleDsym> appleDsym;
  if (unstrippedBinaryRule instanceof ProvidesLinkedBinaryDeps) {
    BuildTarget binaryBuildTarget=getBinaryFromBuildRuleWithBinary(flavoredBinaryRule).getBuildTarget().withoutFlavors(AppleDebugFormat.FLAVOR_DOMAIN.getFlavors());
    targetDebuggableBinaryRule=createAppleDebuggableBinary(binaryBuildTarget,projectFilesystem,params,resolver,getBinaryFromBuildRuleWithBinary(flavoredBinaryRule),(ProvidesLinkedBinaryDeps)unstrippedBinaryRule,debugFormat,cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms);
    if (debugFormat == AppleDebugFormat.DWARF_AND_DSYM) {
      appleDsym=Optional.of(requireAppleDsym(binaryBuildTarget,projectFilesystem,params,resolver,(ProvidesLinkedBinaryDeps)unstrippedBinaryRule,cxxPlatformFlavorDomain,defaultCxxFlavor,appleCxxPlatforms));
    }
 else {
      appleDsym=Optional.empty();
    }
  }
 else {
    targetDebuggableBinaryRule=unstrippedBinaryRule;
    appleDsym=Optional.empty();
  }
  BuildRuleParams bundleParamsWithFlavoredBinaryDep=getBundleParamsWithUpdatedDeps(params,binary,ImmutableSet.<BuildRule>builder().add(targetDebuggableBinaryRule).addAll(Optionals.toStream(assetCatalog).iterator()).addAll(Optionals.toStream(coreDataModel).iterator()).addAll(Optionals.toStream(sceneKitAssets).iterator()).addAll(BuildRules.toBuildRulesFor(buildTarget,resolver,RichStream.from(collectedResources.getAll()).concat(frameworks.stream()).filter(BuildTargetSourcePath.class).map(BuildTargetSourcePath::getTarget).collect(MoreCollectors.toImmutableSet()))).addAll(Optionals.toStream(appleDsym).iterator()).build());
  ImmutableMap<SourcePath,String> extensionBundlePaths=collectFirstLevelAppleDependencyBundles(params.getBuildDeps(),destinations);
  return new AppleBundle(buildTarget,projectFilesystem,bundleParamsWithFlavoredBinaryDep,resolver,extension,productName,infoPlist,infoPlistSubstitutions,Optional.of(getBinaryFromBuildRuleWithBinary(flavoredBinaryRule)),appleDsym,destinations,collectedResources,extensionBundlePaths,frameworks,appleCxxPlatform,assetCatalog,coreDataModel,sceneKitAssets,tests,codeSignIdentityStore,provisioningProfileStore,dryRunCodeSigning,cacheable);
}