Program: 110869
Project: 110869
Buggy source:
public static void init(CppSemantics semantics,RuleContext ruleContext,RuleConfiguredTargetBuilder targetBuilder,LinkTargetType linkType,boolean neverLink,boolean linkStatic,boolean collectLinkstamp,boolean addDynamicRuntimeInputArtifactsToRunfiles) throws RuleErrorException, InterruptedException {
  FeatureConfiguration featureConfiguration=CcCommon.configureFeatures(ruleContext);
  final CcCommon common=new CcCommon(ruleContext);
  PrecompiledFiles precompiledFiles=new PrecompiledFiles(ruleContext);
  semantics.validateAttributes(ruleContext);
  if (ruleContext.hasErrors()) {
    return;
  }
  CcLibraryHelper helper=new CcLibraryHelper(ruleContext,semantics,featureConfiguration).fromCommon(common).addLinkopts(common.getLinkopts()).addSources(common.getSources()).addPublicHeaders(common.getHeaders()).enableCcNativeLibrariesProvider().enableCompileProviders().enableInterfaceSharedObjects().setGenerateLinkActionsIfEmpty(ruleContext.getRule().getImplicitOutputsFunction() != ImplicitOutputsFunction.NONE).setLinkType(linkType).setNeverLink(neverLink).addPrecompiledFiles(precompiledFiles);
  if (collectLinkstamp) {
    helper.addLinkstamps(ruleContext.getPrerequisites("String_Node_Str",Mode.TARGET));
  }
  Artifact soImplArtifact=null;
  boolean supportsDynamicLinker=ruleContext.getFragment(CppConfiguration.class).supportsDynamicLinker();
  boolean createDynamicLibrary=!linkStatic && appearsToHaveObjectFiles(ruleContext.attributes()) && supportsDynamicLinker;
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",Type.STRING_LIST)) {
    List<String> outs=ruleContext.attributes().get("String_Node_Str",Type.STRING_LIST);
    if (outs.size() > 1) {
      ruleContext.attributeError("String_Node_Str","String_Node_Str");
    }
 else     if (outs.size() == 1) {
      PathFragment soImplFilename=new PathFragment(ruleContext.getLabel().getName());
      if (LinkTargetType.DYNAMIC_LIBRARY != LinkTargetType.EXECUTABLE) {
        soImplFilename=soImplFilename.replaceName("String_Node_Str" + soImplFilename.getBaseName() + LinkTargetType.DYNAMIC_LIBRARY.getExtension());
      }
      soImplFilename=soImplFilename.replaceName(outs.get(0));
      if (!soImplFilename.getPathString().endsWith("String_Node_Str")) {
        ruleContext.attributeError("String_Node_Str","String_Node_Str");
      }
      if (createDynamicLibrary) {
        soImplArtifact=ruleContext.getBinArtifact(soImplFilename);
      }
    }
  }
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",BuildType.LABEL_LIST)) {
    ruleContext.checkSrcsSamePackage(true);
  }
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",BuildType.LABEL_LIST)) {
    helper.addPublicTextualHeaders(ruleContext.getPrerequisiteArtifacts("String_Node_Str",Mode.TARGET).list());
  }
  if (common.getLinkopts().contains("String_Node_Str")) {
    ruleContext.attributeWarning("String_Node_Str","String_Node_Str" + "String_Node_Str");
  }
  helper.setCreateDynamicLibrary(createDynamicLibrary);
  helper.setDynamicLibrary(soImplArtifact);
  if (!createDynamicLibrary && !supportsDynamicLinker) {
    Artifact solibArtifact=CppHelper.getLinuxLinkedArtifact(ruleContext,LinkTargetType.DYNAMIC_LIBRARY);
    ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),ImmutableList.of(solibArtifact),"String_Node_Str"));
  }
 else   if (!createDynamicLibrary && ruleContext.attributes().isConfigurable("String_Node_Str",BuildType.LABEL_LIST)) {
    Artifact solibArtifact=CppHelper.getLinuxLinkedArtifact(ruleContext,LinkTargetType.DYNAMIC_LIBRARY);
    ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),ImmutableList.of(solibArtifact),"String_Node_Str" + "String_Node_Str"));
  }
  Iterable<LibraryToLink> staticLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.STATIC_LIBRARY,precompiledFiles.getStaticLibraries());
  Iterable<LibraryToLink> alwayslinkLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY,precompiledFiles.getAlwayslinkStaticLibraries());
  Iterable<LibraryToLink> picStaticLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.STATIC_LIBRARY,precompiledFiles.getPicStaticLibraries());
  Iterable<LibraryToLink> picAlwayslinkLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY,precompiledFiles.getPicAlwayslinkLibraries());
  helper.addStaticLibraries(staticLibrariesFromSrcs);
  helper.addStaticLibraries(alwayslinkLibrariesFromSrcs);
  helper.addPicStaticLibraries(picStaticLibrariesFromSrcs);
  helper.addPicStaticLibraries(picAlwayslinkLibrariesFromSrcs);
  helper.addDynamicLibraries(Iterables.transform(precompiledFiles.getSharedLibraries(),new Function<Artifact,LibraryToLink>(){
    @Override public LibraryToLink apply(    Artifact library){
      return LinkerInputs.solibLibraryToLink(common.getDynamicLibrarySymlink(library,true),library,CcLinkingOutputs.libraryIdentifierOf(library));
    }
  }
));
  CcLibraryHelper.Info info=helper.build();
  CcLinkingOutputs linkedLibraries=info.getCcLinkingOutputsExcludingPrecompiledLibraries();
  NestedSet<Artifact> artifactsToForce=collectHiddenTopLevelArtifacts(ruleContext,info.getCcCompilationOutputs());
  NestedSetBuilder<Artifact> filesBuilder=NestedSetBuilder.stableOrder();
  filesBuilder.addAll(LinkerInputs.toLibraryArtifacts(linkedLibraries.getStaticLibraries()));
  filesBuilder.addAll(LinkerInputs.toLibraryArtifacts(linkedLibraries.getPicStaticLibraries()));
  filesBuilder.addAll(LinkerInputs.toNonSolibArtifacts(linkedLibraries.getDynamicLibraries()));
  filesBuilder.addAll(LinkerInputs.toNonSolibArtifacts(linkedLibraries.getExecutionDynamicLibraries()));
  CcLinkingOutputs linkingOutputs=info.getCcLinkingOutputs();
  warnAboutEmptyLibraries(ruleContext,info.getCcCompilationOutputs(),linkStatic);
  NestedSet<Artifact> filesToBuild=filesBuilder.build();
  Runfiles staticRunfiles=collectRunfiles(ruleContext,linkingOutputs,neverLink,addDynamicRuntimeInputArtifactsToRunfiles,true);
  Runfiles sharedRunfiles=collectRunfiles(ruleContext,linkingOutputs,neverLink,addDynamicRuntimeInputArtifactsToRunfiles,false);
  List<Artifact> instrumentedObjectFiles=new ArrayList<>();
  instrumentedObjectFiles.addAll(info.getCcCompilationOutputs().getObjectFiles(false));
  instrumentedObjectFiles.addAll(info.getCcCompilationOutputs().getObjectFiles(true));
  InstrumentedFilesProvider instrumentedFilesProvider=common.getInstrumentedFilesProvider(instrumentedObjectFiles,true);
  CppHelper.maybeAddStaticLinkMarkerProvider(targetBuilder,ruleContext);
  targetBuilder.setFilesToBuild(filesToBuild).addProviders(info.getProviders()).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME,new CcSkylarkApiProvider()).addOutputGroups(info.getOutputGroups()).add(InstrumentedFilesProvider.class,instrumentedFilesProvider).add(RunfilesProvider.class,RunfilesProvider.withData(staticRunfiles,sharedRunfiles)).add(CppRunfilesProvider.class,new CppRunfilesProvider(staticRunfiles,sharedRunfiles)).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL,artifactsToForce);
}

Fixed version (ground truth):
public static void init(CppSemantics semantics,RuleContext ruleContext,RuleConfiguredTargetBuilder targetBuilder,LinkTargetType linkType,boolean neverLink,boolean linkStatic,boolean collectLinkstamp,boolean addDynamicRuntimeInputArtifactsToRunfiles) throws RuleErrorException, InterruptedException {
  FeatureConfiguration featureConfiguration=CcCommon.configureFeatures(ruleContext);
  final CcCommon common=new CcCommon(ruleContext);
  PrecompiledFiles precompiledFiles=new PrecompiledFiles(ruleContext);
  semantics.validateAttributes(ruleContext);
  if (ruleContext.hasErrors()) {
    return;
  }
  CcLibraryHelper helper=new CcLibraryHelper(ruleContext,semantics,featureConfiguration).fromCommon(common).addLinkopts(common.getLinkopts()).addSources(common.getSources()).addPublicHeaders(common.getHeaders()).enableCcNativeLibrariesProvider().enableCompileProviders().enableInterfaceSharedObjects().setGenerateLinkActionsIfEmpty(ruleContext.getRule().getImplicitOutputsFunction() != ImplicitOutputsFunction.NONE).setLinkType(linkType).setNeverLink(neverLink).addPrecompiledFiles(precompiledFiles);
  if (collectLinkstamp) {
    helper.addLinkstamps(ruleContext.getPrerequisites("String_Node_Str",Mode.TARGET));
  }
  Artifact soImplArtifact=null;
  boolean supportsDynamicLinker=ruleContext.getFragment(CppConfiguration.class).supportsDynamicLinker();
  boolean createDynamicLibrary=!linkStatic && appearsToHaveObjectFiles(ruleContext.attributes()) && supportsDynamicLinker;
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",Type.STRING_LIST)) {
    List<String> outs=ruleContext.attributes().get("String_Node_Str",Type.STRING_LIST);
    if (outs.size() > 1) {
      ruleContext.attributeError("String_Node_Str","String_Node_Str");
    }
 else     if (outs.size() == 1) {
      PathFragment soImplFilename=new PathFragment(ruleContext.getLabel().getName());
      if (LinkTargetType.DYNAMIC_LIBRARY != LinkTargetType.EXECUTABLE) {
        soImplFilename=soImplFilename.replaceName("String_Node_Str" + soImplFilename.getBaseName() + LinkTargetType.DYNAMIC_LIBRARY.getExtension());
      }
      soImplFilename=soImplFilename.replaceName(outs.get(0));
      if (!soImplFilename.getPathString().endsWith("String_Node_Str")) {
        ruleContext.attributeError("String_Node_Str","String_Node_Str");
      }
      if (createDynamicLibrary) {
        soImplArtifact=ruleContext.getBinArtifact(soImplFilename);
      }
    }
  }
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",BuildType.LABEL_LIST)) {
    ruleContext.checkSrcsSamePackage(true);
  }
  if (ruleContext.getRule().isAttrDefined("String_Node_Str",BuildType.LABEL_LIST)) {
    helper.addPublicTextualHeaders(ruleContext.getPrerequisiteArtifacts("String_Node_Str",Mode.TARGET).list());
  }
  if (common.getLinkopts().contains("String_Node_Str")) {
    ruleContext.attributeWarning("String_Node_Str","String_Node_Str" + "String_Node_Str");
  }
  helper.setCreateDynamicLibrary(createDynamicLibrary);
  helper.setDynamicLibrary(soImplArtifact);
  if (!createDynamicLibrary && !supportsDynamicLinker) {
    Artifact solibArtifact=CppHelper.getLinuxLinkedArtifact(ruleContext,LinkTargetType.DYNAMIC_LIBRARY);
    ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),ImmutableList.of(solibArtifact),"String_Node_Str"));
  }
 else   if (!createDynamicLibrary && ruleContext.attributes().isConfigurable("String_Node_Str",BuildType.LABEL_LIST)) {
    Artifact solibArtifact=CppHelper.getLinuxLinkedArtifact(ruleContext,LinkTargetType.DYNAMIC_LIBRARY);
    ruleContext.registerAction(new FailAction(ruleContext.getActionOwner(),ImmutableList.of(solibArtifact),"String_Node_Str" + "String_Node_Str"));
  }
  Iterable<LibraryToLink> staticLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.STATIC_LIBRARY,precompiledFiles.getStaticLibraries());
  Iterable<LibraryToLink> alwayslinkLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY,precompiledFiles.getAlwayslinkStaticLibraries());
  Iterable<LibraryToLink> picStaticLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.STATIC_LIBRARY,precompiledFiles.getPicStaticLibraries());
  Iterable<LibraryToLink> picAlwayslinkLibrariesFromSrcs=LinkerInputs.opaqueLibrariesToLink(ArtifactCategory.ALWAYSLINK_STATIC_LIBRARY,precompiledFiles.getPicAlwayslinkLibraries());
  helper.addStaticLibraries(staticLibrariesFromSrcs);
  helper.addStaticLibraries(alwayslinkLibrariesFromSrcs);
  helper.addPicStaticLibraries(picStaticLibrariesFromSrcs);
  helper.addPicStaticLibraries(picAlwayslinkLibrariesFromSrcs);
  helper.addDynamicLibraries(Iterables.transform(precompiledFiles.getSharedLibraries(),new Function<Artifact,LibraryToLink>(){
    @Override public LibraryToLink apply(    Artifact library){
      return LinkerInputs.solibLibraryToLink(common.getDynamicLibrarySymlink(library,true),library,CcLinkingOutputs.libraryIdentifierOf(library));
    }
  }
));
  CcLibraryHelper.Info info=helper.build();
  CcLinkingOutputs linkedLibraries=info.getCcLinkingOutputsExcludingPrecompiledLibraries();
  NestedSetBuilder<Artifact> filesBuilder=NestedSetBuilder.stableOrder();
  filesBuilder.addAll(LinkerInputs.toLibraryArtifacts(linkedLibraries.getStaticLibraries()));
  filesBuilder.addAll(LinkerInputs.toLibraryArtifacts(linkedLibraries.getPicStaticLibraries()));
  filesBuilder.addAll(LinkerInputs.toNonSolibArtifacts(linkedLibraries.getDynamicLibraries()));
  filesBuilder.addAll(LinkerInputs.toNonSolibArtifacts(linkedLibraries.getExecutionDynamicLibraries()));
  CcLinkingOutputs linkingOutputs=info.getCcLinkingOutputs();
  warnAboutEmptyLibraries(ruleContext,info.getCcCompilationOutputs(),linkStatic);
  NestedSet<Artifact> filesToBuild=filesBuilder.build();
  Runfiles staticRunfiles=collectRunfiles(ruleContext,linkingOutputs,neverLink,addDynamicRuntimeInputArtifactsToRunfiles,true);
  Runfiles sharedRunfiles=collectRunfiles(ruleContext,linkingOutputs,neverLink,addDynamicRuntimeInputArtifactsToRunfiles,false);
  List<Artifact> instrumentedObjectFiles=new ArrayList<>();
  instrumentedObjectFiles.addAll(info.getCcCompilationOutputs().getObjectFiles(false));
  instrumentedObjectFiles.addAll(info.getCcCompilationOutputs().getObjectFiles(true));
  InstrumentedFilesProvider instrumentedFilesProvider=common.getInstrumentedFilesProvider(instrumentedObjectFiles,true);
  CppHelper.maybeAddStaticLinkMarkerProvider(targetBuilder,ruleContext);
  targetBuilder.setFilesToBuild(filesToBuild).addProviders(info.getProviders()).addSkylarkTransitiveInfo(CcSkylarkApiProvider.NAME,new CcSkylarkApiProvider()).addOutputGroups(info.getOutputGroups()).add(InstrumentedFilesProvider.class,instrumentedFilesProvider).add(RunfilesProvider.class,RunfilesProvider.withData(staticRunfiles,sharedRunfiles)).add(CppRunfilesProvider.class,new CppRunfilesProvider(staticRunfiles,sharedRunfiles)).addOutputGroup(OutputGroupProvider.HIDDEN_TOP_LEVEL,collectHiddenTopLevelArtifacts(ruleContext,info.getCcCompilationOutputs())).addOutputGroup(CcLibraryHelper.HIDDEN_HEADER_TOKENS,CcLibraryHelper.collectHeaderTokens(ruleContext,info.getCcCompilationOutputs()));
}