Program: 52826
Project: 52826
Buggy source:
@VisibleForTesting static NdkCxxPlatform build(CxxBuckConfig config,AndroidBuckConfig androidConfig,ProjectFilesystem filesystem,Flavor flavor,Platform platform,Path ndkRoot,NdkCxxPlatformTargetConfiguration targetConfiguration,NdkCxxRuntime cxxRuntime,NdkCxxRuntimeType runtimeType,ExecutableFinder executableFinder,boolean strictToolchainPaths){
  NdkCompilerType compilerType=targetConfiguration.getCompiler().getType();
  String version=Joiner.on('-').join(ImmutableList.of(readVersion(ndkRoot),targetConfiguration.getToolchain(),targetConfiguration.getTargetAppPlatform(),compilerType,targetConfiguration.getCompiler().getVersion(),targetConfiguration.getCompiler().getGccVersion(),cxxRuntime));
  Host host=Preconditions.checkNotNull(BUILD_PLATFORMS.get(platform));
  String ndkVersion=readVersion(ndkRoot);
  NdkCxxToolchainPaths toolchainPaths=new NdkCxxToolchainPaths(filesystem,ndkRoot,targetConfiguration,host.toString(),cxxRuntime,strictToolchainPaths,getUseUnifiedHeaders(androidConfig,ndkVersion));
  NdkCxxToolchainPaths sanitizedPaths=toolchainPaths.getSanitizedPaths();
  ImmutableBiMap.Builder<Path,String> sanitizePathsBuilder=ImmutableBiMap.builder();
  sanitizePathsBuilder.put(toolchainPaths.getNdkToolRoot(),sanitizedPaths.getNdkToolRoot().toString());
  if (compilerType != NdkCompilerType.GCC) {
    sanitizePathsBuilder.put(toolchainPaths.getNdkGccToolRoot(),sanitizedPaths.getNdkGccToolRoot().toString());
  }
  sanitizePathsBuilder.put(ndkRoot,AndroidNdkConstants.ANDROID_NDK_ROOT);
  CxxToolProvider.Type type=compilerType == NdkCompilerType.CLANG ? CxxToolProvider.Type.CLANG : CxxToolProvider.Type.GCC;
  ToolProvider ccTool=new ConstantToolProvider(getCTool(toolchainPaths,compilerType.cc,version,executableFinder));
  ToolProvider cxxTool=new ConstantToolProvider(getCTool(toolchainPaths,compilerType.cxx,version,executableFinder));
  CompilerProvider cc=new CompilerProvider(ccTool,type);
  PreprocessorProvider cpp=new PreprocessorProvider(ccTool,type);
  CompilerProvider cxx=new CompilerProvider(cxxTool,type);
  PreprocessorProvider cxxpp=new PreprocessorProvider(cxxTool,type);
  CxxPlatform.Builder cxxPlatformBuilder=CxxPlatform.builder();
  ImmutableBiMap<Path,String> sanitizePaths=sanitizePathsBuilder.build();
  PrefixMapDebugPathSanitizer compilerDebugPathSanitizer=new PrefixMapDebugPathSanitizer("String_Node_Str",sanitizePaths);
  MungingDebugPathSanitizer assemblerDebugPathSanitizer=new MungingDebugPathSanitizer(config.getDebugPathSanitizerLimit(),File.separatorChar,Paths.get("String_Node_Str"),sanitizePaths);
  cxxPlatformBuilder.setFlavor(flavor).setAs(cc).addAllAsflags(getAsflags(targetConfiguration,toolchainPaths)).setAspp(cpp).setCc(cc).addAllCflags(getCCompilationFlags(targetConfiguration,toolchainPaths,androidConfig)).setCpp(cpp).addAllCppflags(getCPreprocessorFlags(targetConfiguration,toolchainPaths,androidConfig)).setCxx(cxx).addAllCxxflags(getCxxCompilationFlags(targetConfiguration,toolchainPaths,androidConfig)).setCxxpp(cxxpp).addAllCxxppflags(getCxxPreprocessorFlags(targetConfiguration,toolchainPaths,androidConfig)).setLd(new DefaultLinkerProvider(LinkerProvider.Type.GNU,new ConstantToolProvider(getCcLinkTool(targetConfiguration,toolchainPaths,compilerType.cxx,version,cxxRuntime,executableFinder)))).addAllLdflags(getLdFlags(targetConfiguration,androidConfig)).setStrip(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)).setSymbolNameTool(new PosixNmSymbolNameTool(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder))).setAr(ArchiverProvider.from(new GnuArchiver(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)))).setRanlib(new ConstantToolProvider(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder))).setCompilerDebugPathSanitizer(compilerDebugPathSanitizer).setAssemblerDebugPathSanitizer(assemblerDebugPathSanitizer).setSharedLibraryExtension("String_Node_Str").setSharedLibraryVersionedExtensionFormat("String_Node_Str").setStaticLibraryExtension("String_Node_Str").setObjectFileExtension("String_Node_Str").setSharedLibraryInterfaceParams(config.getSharedLibraryInterfaces() != SharedLibraryInterfaceParams.Type.DISABLED ? Optional.of(ElfSharedLibraryInterfaceParams.of(new ConstantToolProvider(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)),ImmutableList.of(),config.getSharedLibraryInterfaces() == SharedLibraryInterfaceParams.Type.DEFINED_ONLY)) : Optional.empty()).setPublicHeadersSymlinksEnabled(config.getPublicHeadersSymlinksEnabled()).setPrivateHeadersSymlinksEnabled(config.getPrivateHeadersSymlinksEnabled());
  HeaderVerification headerVerification=config.getHeaderVerificationOrIgnore();
  try {
    headerVerification=headerVerification.withPlatformWhitelist(ImmutableList.of("String_Node_Str" + Pattern.quote(ndkRoot.toRealPath().toString() + File.separatorChar) + "String_Node_Str"));
  }
 catch (  IOException e) {
    LOG.warn(e,"String_Node_Str",ndkRoot);
  }
  cxxPlatformBuilder.setHeaderVerification(headerVerification);
  LOG.debug("String_Node_Str",ndkRoot.toString());
  LOG.debug("String_Node_Str",headerVerification.getPlatformWhitelist());
  if (cxxRuntime != NdkCxxRuntime.SYSTEM) {
    cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.SHARED,"String_Node_Str" + cxxRuntime.sharedName);
    cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str" + cxxRuntime.staticName);
    if (getNdkMajorVersion(ndkVersion) >= 12 && cxxRuntime == NdkCxxRuntime.LIBCXX) {
      cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str");
      if (targetConfiguration.getTargetArchAbi() == NdkTargetArchAbi.ARMEABI) {
        cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str");
      }
    }
  }
  CxxPlatform cxxPlatform=cxxPlatformBuilder.build();
  NdkCxxPlatform.Builder builder=NdkCxxPlatform.builder();
  builder.setCxxPlatform(cxxPlatform).setCxxRuntime(cxxRuntime).setCxxRuntimeType(runtimeType).setObjdump(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder));
  if ((cxxRuntime != NdkCxxRuntime.SYSTEM) && (runtimeType != NdkCxxRuntimeType.STATIC)) {
    builder.setCxxSharedRuntimePath(toolchainPaths.getCxxRuntimeLibsDirectory().resolve(cxxRuntime.getSoname()));
  }
  return builder.build();
}

Fixed version (ground truth):
@VisibleForTesting static NdkCxxPlatform build(CxxBuckConfig config,AndroidBuckConfig androidConfig,ProjectFilesystem filesystem,Flavor flavor,Platform platform,Path ndkRoot,NdkCxxPlatformTargetConfiguration targetConfiguration,NdkCxxRuntime cxxRuntime,NdkCxxRuntimeType runtimeType,ExecutableFinder executableFinder,boolean strictToolchainPaths){
  NdkCompilerType compilerType=targetConfiguration.getCompiler().getType();
  String version=Joiner.on('-').join(ImmutableList.of(readVersion(ndkRoot),targetConfiguration.getToolchain(),targetConfiguration.getTargetAppPlatform(),compilerType,targetConfiguration.getCompiler().getVersion(),targetConfiguration.getCompiler().getGccVersion(),cxxRuntime));
  Host host=Preconditions.checkNotNull(BUILD_PLATFORMS.get(platform));
  String ndkVersion=readVersion(ndkRoot);
  NdkCxxToolchainPaths toolchainPaths=new NdkCxxToolchainPaths(filesystem,ndkRoot,targetConfiguration,host.toString(),cxxRuntime,strictToolchainPaths,getUseUnifiedHeaders(androidConfig,ndkVersion));
  NdkCxxToolchainPaths sanitizedPaths=toolchainPaths.getSanitizedPaths();
  ImmutableBiMap.Builder<Path,String> sanitizePathsBuilder=ImmutableBiMap.builder();
  sanitizePathsBuilder.put(toolchainPaths.getNdkToolRoot(),sanitizedPaths.getNdkToolRoot().toString());
  if (compilerType != NdkCompilerType.GCC) {
    sanitizePathsBuilder.put(toolchainPaths.getNdkGccToolRoot(),sanitizedPaths.getNdkGccToolRoot().toString());
  }
  sanitizePathsBuilder.put(ndkRoot,AndroidNdkConstants.ANDROID_NDK_ROOT);
  CxxToolProvider.Type type=compilerType == NdkCompilerType.CLANG ? CxxToolProvider.Type.CLANG : CxxToolProvider.Type.GCC;
  ToolProvider ccTool=new ConstantToolProvider(getCTool(toolchainPaths,compilerType.cc,version,executableFinder));
  ToolProvider cxxTool=new ConstantToolProvider(getCTool(toolchainPaths,compilerType.cxx,version,executableFinder));
  CompilerProvider cc=new CompilerProvider(ccTool,type);
  PreprocessorProvider cpp=new PreprocessorProvider(ccTool,type);
  CompilerProvider cxx=new CompilerProvider(cxxTool,type);
  PreprocessorProvider cxxpp=new PreprocessorProvider(cxxTool,type);
  CxxPlatform.Builder cxxPlatformBuilder=CxxPlatform.builder();
  ImmutableBiMap<Path,String> sanitizePaths=sanitizePathsBuilder.build();
  PrefixMapDebugPathSanitizer compilerDebugPathSanitizer=new PrefixMapDebugPathSanitizer("String_Node_Str",sanitizePaths);
  cxxPlatformBuilder.setFlavor(flavor).setAs(cc).addAllAsflags(getAsflags(targetConfiguration,toolchainPaths)).setAspp(cpp).setCc(cc).addAllCflags(getCCompilationFlags(targetConfiguration,toolchainPaths,androidConfig)).setCpp(cpp).addAllCppflags(getCPreprocessorFlags(targetConfiguration,toolchainPaths,androidConfig)).setCxx(cxx).addAllCxxflags(getCxxCompilationFlags(targetConfiguration,toolchainPaths,androidConfig)).setCxxpp(cxxpp).addAllCxxppflags(getCxxPreprocessorFlags(targetConfiguration,toolchainPaths,androidConfig)).setLd(new DefaultLinkerProvider(LinkerProvider.Type.GNU,new ConstantToolProvider(getCcLinkTool(targetConfiguration,toolchainPaths,compilerType.cxx,version,cxxRuntime,executableFinder)))).addAllLdflags(getLdFlags(targetConfiguration,androidConfig)).setStrip(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)).setSymbolNameTool(new PosixNmSymbolNameTool(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder))).setAr(ArchiverProvider.from(new GnuArchiver(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)))).setRanlib(new ConstantToolProvider(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder))).setCompilerDebugPathSanitizer(compilerDebugPathSanitizer).setAssemblerDebugPathSanitizer(compilerDebugPathSanitizer).setSharedLibraryExtension("String_Node_Str").setSharedLibraryVersionedExtensionFormat("String_Node_Str").setStaticLibraryExtension("String_Node_Str").setObjectFileExtension("String_Node_Str").setSharedLibraryInterfaceParams(config.getSharedLibraryInterfaces() != SharedLibraryInterfaceParams.Type.DISABLED ? Optional.of(ElfSharedLibraryInterfaceParams.of(new ConstantToolProvider(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder)),ImmutableList.of(),config.getSharedLibraryInterfaces() == SharedLibraryInterfaceParams.Type.DEFINED_ONLY)) : Optional.empty()).setPublicHeadersSymlinksEnabled(config.getPublicHeadersSymlinksEnabled()).setPrivateHeadersSymlinksEnabled(config.getPrivateHeadersSymlinksEnabled());
  HeaderVerification headerVerification=config.getHeaderVerificationOrIgnore();
  try {
    headerVerification=headerVerification.withPlatformWhitelist(ImmutableList.of("String_Node_Str" + Pattern.quote(ndkRoot.toRealPath().toString() + File.separatorChar) + "String_Node_Str"));
  }
 catch (  IOException e) {
    LOG.warn(e,"String_Node_Str",ndkRoot);
  }
  cxxPlatformBuilder.setHeaderVerification(headerVerification);
  LOG.debug("String_Node_Str",ndkRoot.toString());
  LOG.debug("String_Node_Str",headerVerification.getPlatformWhitelist());
  if (cxxRuntime != NdkCxxRuntime.SYSTEM) {
    cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.SHARED,"String_Node_Str" + cxxRuntime.sharedName);
    cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str" + cxxRuntime.staticName);
    if (getNdkMajorVersion(ndkVersion) >= 12 && cxxRuntime == NdkCxxRuntime.LIBCXX) {
      cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str");
      if (targetConfiguration.getTargetArchAbi() == NdkTargetArchAbi.ARMEABI) {
        cxxPlatformBuilder.putRuntimeLdflags(Linker.LinkableDepType.STATIC,"String_Node_Str");
      }
    }
  }
  CxxPlatform cxxPlatform=cxxPlatformBuilder.build();
  NdkCxxPlatform.Builder builder=NdkCxxPlatform.builder();
  builder.setCxxPlatform(cxxPlatform).setCxxRuntime(cxxRuntime).setCxxRuntimeType(runtimeType).setObjdump(getGccTool(toolchainPaths,"String_Node_Str",version,executableFinder));
  if ((cxxRuntime != NdkCxxRuntime.SYSTEM) && (runtimeType != NdkCxxRuntimeType.STATIC)) {
    builder.setCxxSharedRuntimePath(toolchainPaths.getCxxRuntimeLibsDirectory().resolve(cxxRuntime.getSoname()));
  }
  return builder.build();
}