Program: 110830
Project: 110830
Buggy source:
public static ConfiguredTarget init(CppSemantics semantics,RuleContext ruleContext,boolean fake) throws InterruptedException, RuleErrorException {
  ruleContext.checkSrcsSamePackage(true);
  FeatureConfiguration featureConfiguration=CcCommon.configureFeatures(ruleContext);
  CcCommon common=new CcCommon(ruleContext);
  CppConfiguration cppConfiguration=ruleContext.getFragment(CppConfiguration.class);
  PrecompiledFiles precompiledFiles=new PrecompiledFiles(ruleContext);
  semantics.validateAttributes(ruleContext);
  if (ruleContext.hasErrors()) {
    return null;
  }
  CcLibraryHelper helper=new CcLibraryHelper(ruleContext,semantics,featureConfiguration).fromCommon(common).addSources(common.getSources()).addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext))).setFake(fake).setLinkType(LinkTargetType.STATIC_LIBRARY).addPrecompiledFiles(precompiledFiles).enableInterfaceSharedObjects();
  CcLibraryHelper.Info info=helper.build();
  CppCompilationContext cppCompilationContext=info.getCppCompilationContext();
  CcCompilationOutputs ccCompilationOutputs=info.getCcCompilationOutputs();
  PathFragment binaryPath=new PathFragment(ruleContext.getTarget().getName());
  if (!isLinkShared(ruleContext)) {
    binaryPath=new PathFragment(binaryPath.getPathString() + OsUtils.executableExtension());
  }
  Artifact binary=ruleContext.getBinArtifact(binaryPath);
  if (isLinkShared(ruleContext) && !CppFileTypes.SHARED_LIBRARY.matches(binary.getFilename()) && !CppFileTypes.VERSIONED_SHARED_LIBRARY.matches(binary.getFilename())) {
    ruleContext.attributeError("String_Node_Str","String_Node_Str");
    return null;
  }
  LinkTargetType linkType=isLinkShared(ruleContext) ? LinkTargetType.DYNAMIC_LIBRARY : LinkTargetType.EXECUTABLE;
  List<String> linkopts=common.getLinkopts();
  LinkStaticness linkStaticness=getLinkStaticness(ruleContext,linkopts,cppConfiguration);
  CppLinkActionBuilder linkActionBuilder=determineLinkerArguments(ruleContext,common,precompiledFiles,info,cppCompilationContext.getTransitiveCompilationPrerequisites(),fake,binary,linkStaticness,linkopts);
  linkActionBuilder.setUseTestOnlyFlags(ruleContext.isTestTarget());
  CcToolchainProvider ccToolchain=CppHelper.getToolchain(ruleContext);
  if (linkStaticness == LinkStaticness.DYNAMIC) {
    linkActionBuilder.setRuntimeInputs(ArtifactCategory.DYNAMIC_LIBRARY,ccToolchain.getDynamicRuntimeLinkMiddleman(),ccToolchain.getDynamicRuntimeLinkInputs());
  }
 else {
    linkActionBuilder.setRuntimeInputs(ArtifactCategory.STATIC_LIBRARY,ccToolchain.getStaticRuntimeLinkMiddleman(),ccToolchain.getStaticRuntimeLinkInputs());
    if (!ccToolchain.getStaticRuntimeLinkInputs().isEmpty()) {
      linkActionBuilder.addLinkopt("String_Node_Str");
    }
  }
  linkActionBuilder.setLinkType(linkType);
  linkActionBuilder.setLinkStaticness(linkStaticness);
  linkActionBuilder.setFake(fake);
  linkActionBuilder.setFeatureConfiguration(featureConfiguration);
  if (CppLinkAction.enableSymbolsCounts(cppConfiguration,fake,linkType)) {
    linkActionBuilder.setSymbolCountsOutput(ruleContext.getBinArtifact(CppLinkAction.symbolCountsFileName(binaryPath)));
  }
  if (isLinkShared(ruleContext)) {
    linkActionBuilder.setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(binary));
  }
  CppLinkAction.Context linkContext=new CppLinkAction.Context(linkActionBuilder);
  if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) {
    linkActionBuilder.setLTOIndexing(true);
    CppLinkAction indexAction=linkActionBuilder.build();
    ruleContext.registerAction(indexAction);
    for (    LTOBackendArtifacts ltoArtifacts : indexAction.getAllLTOBackendArtifacts()) {
      boolean usePic=CppHelper.usePic(ruleContext,!isLinkShared(ruleContext));
      ltoArtifacts.scheduleLTOBackendAction(ruleContext,featureConfiguration,usePic);
    }
    linkActionBuilder.setLTOIndexing(false);
  }
  CppLinkAction linkAction=linkActionBuilder.build();
  ruleContext.registerAction(linkAction);
  LibraryToLink outputLibrary=linkAction.getOutputLibrary();
  Iterable<Artifact> fakeLinkerInputs=fake ? linkAction.getInputs() : ImmutableList.<Artifact>of();
  Artifact executable=linkAction.getLinkOutput();
  CcLinkingOutputs.Builder linkingOutputsBuilder=new CcLinkingOutputs.Builder();
  if (isLinkShared(ruleContext)) {
    linkingOutputsBuilder.addDynamicLibrary(outputLibrary);
    linkingOutputsBuilder.addExecutionDynamicLibrary(outputLibrary);
  }
  for (  Artifact library : precompiledFiles.getSharedLibraries()) {
    Artifact symlink=common.getDynamicLibrarySymlink(library,true);
    LibraryToLink symlinkLibrary=LinkerInputs.solibLibraryToLink(symlink,library,CcLinkingOutputs.libraryIdentifierOf(library));
    linkingOutputsBuilder.addDynamicLibrary(symlinkLibrary);
    linkingOutputsBuilder.addExecutionDynamicLibrary(symlinkLibrary);
  }
  CcLinkingOutputs linkingOutputs=linkingOutputsBuilder.build();
  NestedSet<Artifact> filesToBuild=NestedSetBuilder.create(Order.STABLE_ORDER,executable);
  Artifact strippedFile=ruleContext.getImplicitOutputArtifact(CppRuleClasses.CC_BINARY_STRIPPED);
  CppHelper.createStripAction(ruleContext,cppConfiguration,executable,strippedFile);
  DwoArtifactsCollector dwoArtifacts=collectTransitiveDwoArtifacts(ruleContext,ccCompilationOutputs,linkStaticness);
  Artifact dwpFile=ruleContext.getImplicitOutputArtifact(CppRuleClasses.CC_BINARY_DEBUG_PACKAGE);
  createDebugPackagerActions(ruleContext,cppConfiguration,dwpFile,dwoArtifacts);
  Artifact explicitDwpFile=dwpFile;
  if (!cppConfiguration.useFission()) {
    explicitDwpFile=null;
  }
 else {
    if (TargetUtils.isTestRule(ruleContext.getRule()) && linkStaticness != LinkStaticness.DYNAMIC && cppConfiguration.shouldBuildTestDwp()) {
      filesToBuild=NestedSetBuilder.fromNestedSet(filesToBuild).add(dwpFile).build();
    }
  }
  Runfiles runfiles=collectRunfiles(ruleContext,linkingOutputs,info,linkStaticness,filesToBuild,fakeLinkerInputs,fake,helper.getCompilationUnitSources());
  RunfilesSupport runfilesSupport=RunfilesSupport.withExecutable(ruleContext,runfiles,executable,ruleContext.getConfiguration().buildRunfiles());
  TransitiveLipoInfoProvider transitiveLipoInfo;
  if (cppConfiguration.isLipoContextCollector()) {
    transitiveLipoInfo=common.collectTransitiveLipoLabels(ccCompilationOutputs);
  }
 else {
    transitiveLipoInfo=TransitiveLipoInfoProvider.EMPTY;
  }
  RuleConfiguredTargetBuilder ruleBuilder=new RuleConfiguredTargetBuilder(ruleContext);
  addTransitiveInfoProviders(ruleContext,cppConfiguration,common,ruleBuilder,filesToBuild,ccCompilationOutputs,cppCompilationContext,linkingOutputs,dwoArtifacts,transitiveLipoInfo,fake);
  Map<Artifact,IncludeScannable> scannableMap=new LinkedHashMap<>();
  Map<PathFragment,Artifact> sourceFileMap=new LinkedHashMap<>();
  if (cppConfiguration.isLipoContextCollector()) {
    for (    IncludeScannable scannable : transitiveLipoInfo.getTransitiveIncludeScannables()) {
      Artifact source=Iterables.getOnlyElement(scannable.getIncludeScannerSources());
      scannableMap.put(source,scannable);
      sourceFileMap.put(source.getExecPath(),source);
    }
  }
  if (Platform.isApplePlatform(cppConfiguration.getTargetCpu()) && TargetUtils.isTestRule(ruleContext.getRule())) {
    ruleBuilder.addNativeDeclaredProvider(new ExecutionInfoProvider(ImmutableMap.of("String_Node_Str","String_Node_Str")));
  }
  return ruleBuilder.addProvider(RunfilesProvider.class,RunfilesProvider.simple(runfiles)).addProvider(CppDebugPackageProvider.class,new CppDebugPackageProvider(ruleContext.getLabel(),strippedFile,executable,explicitDwpFile)).setRunfilesSupport(runfilesSupport,executable).addProvider(LipoContextProvider.class,new LipoContextProvider(cppCompilationContext,ImmutableMap.copyOf(scannableMap),ImmutableMap.copyOf(sourceFileMap))).addProvider(CppLinkAction.Context.class,linkContext).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME,new CcSkylarkApiProvider()).build();
}

Fixed version (ground truth):
public static ConfiguredTarget init(CppSemantics semantics,RuleContext ruleContext,boolean fake) throws InterruptedException, RuleErrorException {
  ruleContext.checkSrcsSamePackage(true);
  FeatureConfiguration featureConfiguration=CcCommon.configureFeatures(ruleContext);
  CcCommon common=new CcCommon(ruleContext);
  CppConfiguration cppConfiguration=ruleContext.getFragment(CppConfiguration.class);
  PrecompiledFiles precompiledFiles=new PrecompiledFiles(ruleContext);
  LinkTargetType linkType=isLinkShared(ruleContext) ? LinkTargetType.DYNAMIC_LIBRARY : LinkTargetType.EXECUTABLE;
  semantics.validateAttributes(ruleContext);
  if (ruleContext.hasErrors()) {
    return null;
  }
  CcLibraryHelper helper=new CcLibraryHelper(ruleContext,semantics,featureConfiguration).fromCommon(common).addSources(common.getSources()).addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext))).setFake(fake).addPrecompiledFiles(precompiledFiles).enableInterfaceSharedObjects();
  helper.setLinkType(ruleContext.isTestTarget() ? LinkTargetType.STATIC_LIBRARY : linkType);
  CcLibraryHelper.Info info=helper.build();
  CppCompilationContext cppCompilationContext=info.getCppCompilationContext();
  CcCompilationOutputs ccCompilationOutputs=info.getCcCompilationOutputs();
  PathFragment binaryPath=new PathFragment(ruleContext.getTarget().getName());
  if (!isLinkShared(ruleContext)) {
    binaryPath=new PathFragment(binaryPath.getPathString() + OsUtils.executableExtension());
  }
  Artifact binary=ruleContext.getBinArtifact(binaryPath);
  if (isLinkShared(ruleContext) && !CppFileTypes.SHARED_LIBRARY.matches(binary.getFilename()) && !CppFileTypes.VERSIONED_SHARED_LIBRARY.matches(binary.getFilename())) {
    ruleContext.attributeError("String_Node_Str","String_Node_Str");
    return null;
  }
  List<String> linkopts=common.getLinkopts();
  LinkStaticness linkStaticness=getLinkStaticness(ruleContext,linkopts,cppConfiguration);
  CppLinkActionBuilder linkActionBuilder=determineLinkerArguments(ruleContext,common,precompiledFiles,info,cppCompilationContext.getTransitiveCompilationPrerequisites(),fake,binary,linkStaticness,linkopts);
  linkActionBuilder.setUseTestOnlyFlags(ruleContext.isTestTarget());
  CcToolchainProvider ccToolchain=CppHelper.getToolchain(ruleContext);
  if (linkStaticness == LinkStaticness.DYNAMIC) {
    linkActionBuilder.setRuntimeInputs(ArtifactCategory.DYNAMIC_LIBRARY,ccToolchain.getDynamicRuntimeLinkMiddleman(),ccToolchain.getDynamicRuntimeLinkInputs());
  }
 else {
    linkActionBuilder.setRuntimeInputs(ArtifactCategory.STATIC_LIBRARY,ccToolchain.getStaticRuntimeLinkMiddleman(),ccToolchain.getStaticRuntimeLinkInputs());
    if (!ccToolchain.getStaticRuntimeLinkInputs().isEmpty()) {
      linkActionBuilder.addLinkopt("String_Node_Str");
    }
  }
  linkActionBuilder.setLinkType(linkType);
  linkActionBuilder.setLinkStaticness(linkStaticness);
  linkActionBuilder.setFake(fake);
  linkActionBuilder.setFeatureConfiguration(featureConfiguration);
  if (CppLinkAction.enableSymbolsCounts(cppConfiguration,fake,linkType)) {
    linkActionBuilder.setSymbolCountsOutput(ruleContext.getBinArtifact(CppLinkAction.symbolCountsFileName(binaryPath)));
  }
  if (isLinkShared(ruleContext)) {
    linkActionBuilder.setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(binary));
  }
  CppLinkAction.Context linkContext=new CppLinkAction.Context(linkActionBuilder);
  if (featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) {
    linkActionBuilder.setLTOIndexing(true);
    CppLinkAction indexAction=linkActionBuilder.build();
    ruleContext.registerAction(indexAction);
    for (    LTOBackendArtifacts ltoArtifacts : indexAction.getAllLTOBackendArtifacts()) {
      boolean usePic=CppHelper.usePic(ruleContext,!isLinkShared(ruleContext));
      ltoArtifacts.scheduleLTOBackendAction(ruleContext,featureConfiguration,usePic);
    }
    linkActionBuilder.setLTOIndexing(false);
  }
  CppLinkAction linkAction=linkActionBuilder.build();
  ruleContext.registerAction(linkAction);
  LibraryToLink outputLibrary=linkAction.getOutputLibrary();
  Iterable<Artifact> fakeLinkerInputs=fake ? linkAction.getInputs() : ImmutableList.<Artifact>of();
  Artifact executable=linkAction.getLinkOutput();
  CcLinkingOutputs.Builder linkingOutputsBuilder=new CcLinkingOutputs.Builder();
  if (isLinkShared(ruleContext)) {
    linkingOutputsBuilder.addDynamicLibrary(outputLibrary);
    linkingOutputsBuilder.addExecutionDynamicLibrary(outputLibrary);
  }
  for (  Artifact library : precompiledFiles.getSharedLibraries()) {
    Artifact symlink=common.getDynamicLibrarySymlink(library,true);
    LibraryToLink symlinkLibrary=LinkerInputs.solibLibraryToLink(symlink,library,CcLinkingOutputs.libraryIdentifierOf(library));
    linkingOutputsBuilder.addDynamicLibrary(symlinkLibrary);
    linkingOutputsBuilder.addExecutionDynamicLibrary(symlinkLibrary);
  }
  CcLinkingOutputs linkingOutputs=linkingOutputsBuilder.build();
  NestedSet<Artifact> filesToBuild=NestedSetBuilder.create(Order.STABLE_ORDER,executable);
  Artifact strippedFile=ruleContext.getImplicitOutputArtifact(CppRuleClasses.CC_BINARY_STRIPPED);
  CppHelper.createStripAction(ruleContext,cppConfiguration,executable,strippedFile);
  DwoArtifactsCollector dwoArtifacts=collectTransitiveDwoArtifacts(ruleContext,ccCompilationOutputs,linkStaticness);
  Artifact dwpFile=ruleContext.getImplicitOutputArtifact(CppRuleClasses.CC_BINARY_DEBUG_PACKAGE);
  createDebugPackagerActions(ruleContext,cppConfiguration,dwpFile,dwoArtifacts);
  Artifact explicitDwpFile=dwpFile;
  if (!cppConfiguration.useFission()) {
    explicitDwpFile=null;
  }
 else {
    if (TargetUtils.isTestRule(ruleContext.getRule()) && linkStaticness != LinkStaticness.DYNAMIC && cppConfiguration.shouldBuildTestDwp()) {
      filesToBuild=NestedSetBuilder.fromNestedSet(filesToBuild).add(dwpFile).build();
    }
  }
  Runfiles runfiles=collectRunfiles(ruleContext,linkingOutputs,info,linkStaticness,filesToBuild,fakeLinkerInputs,fake,helper.getCompilationUnitSources());
  RunfilesSupport runfilesSupport=RunfilesSupport.withExecutable(ruleContext,runfiles,executable,ruleContext.getConfiguration().buildRunfiles());
  TransitiveLipoInfoProvider transitiveLipoInfo;
  if (cppConfiguration.isLipoContextCollector()) {
    transitiveLipoInfo=common.collectTransitiveLipoLabels(ccCompilationOutputs);
  }
 else {
    transitiveLipoInfo=TransitiveLipoInfoProvider.EMPTY;
  }
  RuleConfiguredTargetBuilder ruleBuilder=new RuleConfiguredTargetBuilder(ruleContext);
  addTransitiveInfoProviders(ruleContext,cppConfiguration,common,ruleBuilder,filesToBuild,ccCompilationOutputs,cppCompilationContext,linkingOutputs,dwoArtifacts,transitiveLipoInfo,fake);
  Map<Artifact,IncludeScannable> scannableMap=new LinkedHashMap<>();
  Map<PathFragment,Artifact> sourceFileMap=new LinkedHashMap<>();
  if (cppConfiguration.isLipoContextCollector()) {
    for (    IncludeScannable scannable : transitiveLipoInfo.getTransitiveIncludeScannables()) {
      Artifact source=Iterables.getOnlyElement(scannable.getIncludeScannerSources());
      scannableMap.put(source,scannable);
      sourceFileMap.put(source.getExecPath(),source);
    }
  }
  if (Platform.isApplePlatform(cppConfiguration.getTargetCpu()) && TargetUtils.isTestRule(ruleContext.getRule())) {
    ruleBuilder.addNativeDeclaredProvider(new ExecutionInfoProvider(ImmutableMap.of("String_Node_Str","String_Node_Str")));
  }
  return ruleBuilder.addProvider(RunfilesProvider.class,RunfilesProvider.simple(runfiles)).addProvider(CppDebugPackageProvider.class,new CppDebugPackageProvider(ruleContext.getLabel(),strippedFile,executable,explicitDwpFile)).setRunfilesSupport(runfilesSupport,executable).addProvider(LipoContextProvider.class,new LipoContextProvider(cppCompilationContext,ImmutableMap.copyOf(scannableMap),ImmutableMap.copyOf(sourceFileMap))).addProvider(CppLinkAction.Context.class,linkContext).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME,new CcSkylarkApiProvider()).build();
}