Program: 53110
Project: 53110
Buggy source:
public static PythonPackageComponents getAllComponents(BuildRuleParams params,BuildRuleResolver ruleResolver,SourcePathResolver pathResolver,final PythonPackageComponents packageComponents,final PythonPlatform pythonPlatform,final CxxPlatform cxxPlatform,ImmutableList<? extends Arg> extraLdflags,final NativeLinkStrategy nativeLinkStrategy) throws NoSuchBuildTargetException {
  final PythonPackageComponents.Builder allComponents=new PythonPackageComponents.Builder(params.getBuildTarget());
  final Map<BuildTarget,CxxPythonExtension> extensions=new LinkedHashMap<>();
  final Map<BuildTarget,SharedNativeLinkTarget> nativeLinkTargetRoots=new LinkedHashMap<>();
  final Map<BuildTarget,NativeLinkable> nativeLinkableRoots=new LinkedHashMap<>();
  final Set<BuildTarget> excludedNativeLinkableRoots=new LinkedHashSet<>();
  allComponents.addComponent(packageComponents,params.getBuildTarget());
  new AbstractBreadthFirstThrowingTraversal<BuildRule,NoSuchBuildTargetException>(params.getDeps()){
    private final ImmutableList<BuildRule> empty=ImmutableList.of();
    @Override public Iterable<BuildRule> visit(    BuildRule rule) throws NoSuchBuildTargetException {
      Iterable<BuildRule> deps=empty;
      Optional<SharedNativeLinkTarget> linkTarget=nativeLinkStrategy == NativeLinkStrategy.MERGED ? NativeLinkables.getSharedNativeLinkTarget(rule,cxxPlatform) : Optional.<SharedNativeLinkTarget>absent();
      if (rule instanceof CxxPythonExtension) {
        extensions.put(rule.getBuildTarget(),(CxxPythonExtension)rule);
      }
 else       if (rule instanceof PythonPackagable) {
        PythonPackagable packagable=(PythonPackagable)rule;
        PythonPackageComponents comps=packagable.getPythonPackageComponents(pythonPlatform,cxxPlatform);
        allComponents.addComponent(comps,rule.getBuildTarget());
        if (hasNativeCode(cxxPlatform,comps)) {
          for (          BuildRule dep : rule.getDeps()) {
            if (dep instanceof NativeLinkable) {
              NativeLinkable linkable=(NativeLinkable)dep;
              excludedNativeLinkableRoots.add(linkable.getBuildTarget());
              nativeLinkableRoots.put(linkable.getBuildTarget(),linkable);
            }
          }
        }
        deps=rule.getDeps();
      }
 else       if (linkTarget.isPresent()) {
        nativeLinkTargetRoots.put(linkTarget.get().getBuildTarget(),linkTarget.get());
      }
 else       if (rule instanceof NativeLinkable) {
        nativeLinkableRoots.put(rule.getBuildTarget(),(NativeLinkable)rule);
      }
      return deps;
    }
  }
.start();
  if (nativeLinkStrategy == NativeLinkStrategy.MERGED) {
    Map<BuildTarget,SharedNativeLinkTarget> includedNativeLinkTargetRoots=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,SharedNativeLinkTarget> ent : nativeLinkTargetRoots.entrySet()) {
      if (!excludedNativeLinkableRoots.contains(ent.getKey())) {
        includedNativeLinkTargetRoots.put(ent.getKey(),ent.getValue());
      }
    }
    Map<BuildTarget,CxxPythonExtension> includedExtensions=new LinkedHashMap<>();
    for (    CxxPythonExtension extension : extensions.values()) {
      SharedNativeLinkTarget target=extension.getNativeLinkTarget(pythonPlatform);
      includedExtensions.put(target.getBuildTarget(),extension);
      includedNativeLinkTargetRoots.put(target.getBuildTarget(),target);
    }
    OmnibusLibraries libraries=Omnibus.getSharedLibraries(params,ruleResolver,pathResolver,cxxPlatform,extraLdflags,includedNativeLinkTargetRoots.values(),Maps.filterKeys(nativeLinkableRoots,Predicates.not(Predicates.in(includedNativeLinkTargetRoots.keySet()))).values());
    for (    Map.Entry<BuildTarget,SharedLibrary> root : libraries.getRoots().entrySet()) {
      CxxPythonExtension extension=includedExtensions.get(root.getKey());
      if (extension != null) {
        allComponents.addModule(extension.getModule(),root.getValue().getPath(),root.getKey());
      }
 else {
        allComponents.addNativeLibraries(Paths.get(root.getValue().getSoname()),root.getValue().getPath(),root.getKey());
      }
    }
    for (    SharedLibrary library : libraries.getLibraries()) {
      allComponents.addNativeLibraries(Paths.get(library.getSoname()),library.getPath(),params.getBuildTarget());
    }
  }
 else {
    Map<BuildTarget,NativeLinkable> allNativeRoots=new LinkedHashMap<>();
    allNativeRoots.putAll(nativeLinkableRoots);
    for (    Map.Entry<BuildTarget,CxxPythonExtension> entry : extensions.entrySet()) {
      allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform,cxxPlatform),entry.getKey());
      allNativeRoots.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform).getSharedNativeLinkTargetDeps(cxxPlatform),HasBuildTarget.TO_TARGET));
    }
    ImmutableMap<BuildTarget,NativeLinkable> nativeLinkables=NativeLinkables.getTransitiveNativeLinkables(cxxPlatform,allNativeRoots.values());
    for (    NativeLinkable nativeLinkable : nativeLinkables.values()) {
      NativeLinkable.Linkage linkage=nativeLinkable.getPreferredLinkage(cxxPlatform);
      if (linkage != NativeLinkable.Linkage.STATIC) {
        ImmutableMap<String,SourcePath> libs=nativeLinkable.getSharedLibraries(cxxPlatform);
        for (        Map.Entry<String,SourcePath> ent : libs.entrySet()) {
          allComponents.addNativeLibraries(Paths.get(ent.getKey()),ent.getValue(),params.getBuildTarget());
        }
      }
    }
  }
  return allComponents.build();
}

Fixed version (ground truth):
public static PythonPackageComponents getAllComponents(BuildRuleParams params,BuildRuleResolver ruleResolver,SourcePathResolver pathResolver,final PythonPackageComponents packageComponents,final PythonPlatform pythonPlatform,final CxxPlatform cxxPlatform,ImmutableList<? extends Arg> extraLdflags,final NativeLinkStrategy nativeLinkStrategy) throws NoSuchBuildTargetException {
  final PythonPackageComponents.Builder allComponents=new PythonPackageComponents.Builder(params.getBuildTarget());
  final Map<BuildTarget,CxxPythonExtension> extensions=new LinkedHashMap<>();
  final Map<BuildTarget,SharedNativeLinkTarget> nativeLinkTargetRoots=new LinkedHashMap<>();
  final Map<BuildTarget,NativeLinkable> nativeLinkableRoots=new LinkedHashMap<>();
  final Set<BuildTarget> excludedNativeLinkableRoots=new LinkedHashSet<>();
  allComponents.addComponent(packageComponents,params.getBuildTarget());
  new AbstractBreadthFirstThrowingTraversal<BuildRule,NoSuchBuildTargetException>(params.getDeps()){
    private final ImmutableList<BuildRule> empty=ImmutableList.of();
    @Override public Iterable<BuildRule> visit(    BuildRule rule) throws NoSuchBuildTargetException {
      Iterable<BuildRule> deps=empty;
      Optional<SharedNativeLinkTarget> linkTarget=nativeLinkStrategy == NativeLinkStrategy.MERGED ? NativeLinkables.getSharedNativeLinkTarget(rule,cxxPlatform) : Optional.<SharedNativeLinkTarget>absent();
      if (rule instanceof CxxPythonExtension) {
        extensions.put(rule.getBuildTarget(),(CxxPythonExtension)rule);
      }
 else       if (rule instanceof PythonPackagable) {
        PythonPackagable packagable=(PythonPackagable)rule;
        PythonPackageComponents comps=packagable.getPythonPackageComponents(pythonPlatform,cxxPlatform);
        allComponents.addComponent(comps,rule.getBuildTarget());
        if (hasNativeCode(cxxPlatform,comps)) {
          for (          BuildRule dep : rule.getDeps()) {
            if (dep instanceof NativeLinkable) {
              NativeLinkable linkable=(NativeLinkable)dep;
              excludedNativeLinkableRoots.add(linkable.getBuildTarget());
              nativeLinkableRoots.put(linkable.getBuildTarget(),linkable);
            }
          }
        }
        deps=rule.getDeps();
      }
 else       if (linkTarget.isPresent()) {
        nativeLinkTargetRoots.put(linkTarget.get().getBuildTarget(),linkTarget.get());
      }
 else       if (rule instanceof NativeLinkable) {
        nativeLinkableRoots.put(rule.getBuildTarget(),(NativeLinkable)rule);
      }
      return deps;
    }
  }
.start();
  if (nativeLinkStrategy == NativeLinkStrategy.MERGED) {
    Map<BuildTarget,SharedNativeLinkTarget> includedNativeLinkTargetRoots=new LinkedHashMap<>();
    for (    Map.Entry<BuildTarget,SharedNativeLinkTarget> ent : nativeLinkTargetRoots.entrySet()) {
      if (!excludedNativeLinkableRoots.contains(ent.getKey())) {
        includedNativeLinkTargetRoots.put(ent.getKey(),ent.getValue());
      }
    }
    Map<BuildTarget,CxxPythonExtension> includedExtensions=new LinkedHashMap<>();
    for (    CxxPythonExtension extension : extensions.values()) {
      SharedNativeLinkTarget target=extension.getNativeLinkTarget(pythonPlatform);
      includedExtensions.put(target.getBuildTarget(),extension);
      includedNativeLinkTargetRoots.put(target.getBuildTarget(),target);
    }
    OmnibusLibraries libraries=Omnibus.getSharedLibraries(params,ruleResolver,pathResolver,cxxPlatform,extraLdflags,includedNativeLinkTargetRoots.values(),Maps.filterKeys(nativeLinkableRoots,Predicates.not(Predicates.in(includedNativeLinkTargetRoots.keySet()))).values());
    for (    Map.Entry<BuildTarget,SharedLibrary> root : libraries.getRoots().entrySet()) {
      CxxPythonExtension extension=includedExtensions.get(root.getKey());
      if (extension != null) {
        allComponents.addModule(extension.getModule(),root.getValue().getPath(),root.getKey());
      }
 else {
        allComponents.addNativeLibraries(Paths.get(root.getValue().getSoname()),root.getValue().getPath(),root.getKey());
      }
    }
    for (    SharedLibrary library : libraries.getLibraries()) {
      allComponents.addNativeLibraries(Paths.get(library.getSoname()),library.getPath(),params.getBuildTarget());
    }
  }
 else {
    Map<BuildTarget,NativeLinkable> allNativeRoots=new LinkedHashMap<>();
    allNativeRoots.putAll(nativeLinkableRoots);
    for (    Map.Entry<BuildTarget,CxxPythonExtension> entry : extensions.entrySet()) {
      allComponents.addComponent(entry.getValue().getPythonPackageComponents(pythonPlatform,cxxPlatform),entry.getKey());
      allNativeRoots.putAll(Maps.uniqueIndex(entry.getValue().getNativeLinkTarget(pythonPlatform).getSharedNativeLinkTargetDeps(cxxPlatform),HasBuildTarget.TO_TARGET));
    }
    ImmutableMap<BuildTarget,NativeLinkable> nativeLinkables=NativeLinkables.getTransitiveNativeLinkables(cxxPlatform,allNativeRoots.values());
    for (    NativeLinkable nativeLinkable : nativeLinkables.values()) {
      NativeLinkable.Linkage linkage=nativeLinkable.getPreferredLinkage(cxxPlatform);
      if (linkage != NativeLinkable.Linkage.STATIC) {
        ImmutableMap<String,SourcePath> libs=nativeLinkable.getSharedLibraries(cxxPlatform);
        for (        Map.Entry<String,SourcePath> ent : libs.entrySet()) {
          allComponents.addNativeLibraries(Paths.get(ent.getKey()),ent.getValue(),nativeLinkable.getBuildTarget());
        }
      }
    }
  }
  return allComponents.build();
}