Program: 52903
Project: 52903
Buggy source:
@Test public void libraryCompilationDatabase() throws InterruptedException, IOException {
  ProjectWorkspace workspace=TestDataHelper.createProjectWorkspaceForScenario(this,"String_Node_Str",tmp);
  workspace.setUp();
  ProjectFilesystem filesystem=new FakeProjectFilesystem();
  BuildTarget target=BuildTargetFactory.newInstance("String_Node_Str");
  Path compilationDatabase=workspace.buildAndReturnOutput(target.getFullyQualifiedName());
  Path rootPath=tmp.getRoot();
  assertEquals(BuildTargets.getGenPath(filesystem,target,"String_Node_Str"),rootPath.relativize(compilationDatabase));
  Path headerSymlinkTreeFolder=BuildTargets.getGenPath(filesystem,target.withFlavors(InternalFlavor.of("String_Node_Str"),CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR),"String_Node_Str");
  Path exportedHeaderSymlinkTreeFolder=CxxDescriptionEnhancer.getHeaderSymlinkTreePath(filesystem,target.withFlavors(),HeaderVisibility.PUBLIC,CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
  System.out.println(workspace.getBuildLog().getAllTargets());
  assertTrue(Files.exists(rootPath.resolve(headerSymlinkTreeFolder)));
  assertTrue(Files.exists(rootPath.resolve(exportedHeaderSymlinkTreeFolder)));
  Map<String,CxxCompilationDatabaseEntry> fileToEntry=CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
  assertEquals(1,fileToEntry.size());
  String path=sandboxSources ? "String_Node_Str" : "String_Node_Str";
  BuildTarget compilationTarget=target.withFlavors(InternalFlavor.of("String_Node_Str"),InternalFlavor.of("String_Node_Str" + sanitize("String_Node_Str")));
  Map<String,String> prefixMap=new TreeMap<>(Comparator.comparingInt(String::length));
  prefixMap.put(headerSymlinkTreeFolder + "String_Node_Str","String_Node_Str");
  prefixMap.put(exportedHeaderSymlinkTreeFolder + "String_Node_Str","String_Node_Str");
  prefixMap.put(rootPath.toString(),"String_Node_Str");
  if (sandboxSources) {
    prefixMap.put("String_Node_Str","String_Node_Str");
  }
  assertHasEntry(fileToEntry,path,new ImmutableList.Builder<String>().add(COMPILER_PATH).add("String_Node_Str").add("String_Node_Str").add("String_Node_Str").add(headerSymlinkTreePath(headerSymlinkTreeFolder).toString()).add("String_Node_Str").add(headerSymlinkTreePath(exportedHeaderSymlinkTreeFolder).toString()).addAll(getExtraFlagsForHeaderMaps(filesystem)).addAll(COMPILER_SPECIFIC_FLAGS).add("String_Node_Str").add("String_Node_Str").addAll(prefixMap.entrySet().stream().map(e -> String.format("String_Node_Str",e.getKey(),e.getValue())).collect(Collectors.toList())).addAll(MORE_COMPILER_SPECIFIC_FLAGS).add("String_Node_Str").add("String_Node_Str").add("String_Node_Str").add(BuildTargets.getGenPath(filesystem,compilationTarget,"String_Node_Str").toString()).add(Paths.get(path).toString()).add("String_Node_Str").add(BuildTargets.getGenPath(filesystem,compilationTarget,"String_Node_Str").toString()).build());
}

Fixed version (ground truth):
@Test public void libraryCompilationDatabase() throws InterruptedException, IOException {
  ProjectWorkspace workspace=TestDataHelper.createProjectWorkspaceForScenario(this,"String_Node_Str",tmp);
  workspace.setUp();
  ProjectFilesystem filesystem=new FakeProjectFilesystem();
  BuildTarget target=BuildTargetFactory.newInstance("String_Node_Str");
  Path compilationDatabase=workspace.buildAndReturnOutput(target.getFullyQualifiedName());
  Path rootPath=tmp.getRoot();
  assertEquals(BuildTargets.getGenPath(filesystem,target,"String_Node_Str"),rootPath.relativize(compilationDatabase));
  Path headerSymlinkTreeFolder=BuildTargets.getGenPath(filesystem,target.withFlavors(InternalFlavor.of("String_Node_Str"),CxxDescriptionEnhancer.HEADER_SYMLINK_TREE_FLAVOR),"String_Node_Str");
  Path exportedHeaderSymlinkTreeFolder=CxxDescriptionEnhancer.getHeaderSymlinkTreePath(filesystem,target.withFlavors(),HeaderVisibility.PUBLIC,CxxPlatformUtils.getHeaderModeForDefaultPlatform(tmp.getRoot()).getFlavor());
  System.out.println(workspace.getBuildLog().getAllTargets());
  assertTrue(Files.exists(rootPath.resolve(headerSymlinkTreeFolder)));
  assertTrue(Files.exists(rootPath.resolve(exportedHeaderSymlinkTreeFolder)));
  Map<String,CxxCompilationDatabaseEntry> fileToEntry=CxxCompilationDatabaseUtils.parseCompilationDatabaseJsonFile(compilationDatabase);
  assertEquals(1,fileToEntry.size());
  String path=sandboxSources ? "String_Node_Str" : "String_Node_Str";
  BuildTarget compilationTarget=target.withFlavors(InternalFlavor.of("String_Node_Str"),InternalFlavor.of("String_Node_Str" + sanitize("String_Node_Str")));
  Map<String,String> prefixMap=new TreeMap<>(Comparator.comparingInt(String::length));
  prefixMap.put(rootPath.toString(),"String_Node_Str");
  if (Platform.detect() == Platform.MACOS) {
    prefixMap.put(headerSymlinkTreeFolder + "String_Node_Str","String_Node_Str");
    prefixMap.put(exportedHeaderSymlinkTreeFolder + "String_Node_Str","String_Node_Str");
    if (sandboxSources) {
      prefixMap.put("String_Node_Str","String_Node_Str");
    }
  }
  assertHasEntry(fileToEntry,path,new ImmutableList.Builder<String>().add(COMPILER_PATH).add("String_Node_Str").add("String_Node_Str").add("String_Node_Str").add(headerSymlinkTreePath(headerSymlinkTreeFolder).toString()).add("String_Node_Str").add(headerSymlinkTreePath(exportedHeaderSymlinkTreeFolder).toString()).addAll(getExtraFlagsForHeaderMaps(filesystem)).addAll(COMPILER_SPECIFIC_FLAGS).add("String_Node_Str").add("String_Node_Str").addAll(prefixMap.entrySet().stream().map(e -> String.format("String_Node_Str",e.getKey(),e.getValue())).collect(Collectors.toList())).addAll(MORE_COMPILER_SPECIFIC_FLAGS).add("String_Node_Str").add("String_Node_Str").add("String_Node_Str").add(BuildTargets.getGenPath(filesystem,compilationTarget,"String_Node_Str").toString()).add(Paths.get(path).toString()).add("String_Node_Str").add(BuildTargets.getGenPath(filesystem,compilationTarget,"String_Node_Str").toString()).build());
}