Program: 93567
Project: 93567
Buggy source:
private IDiffContainer buildDiffContainer(Repository repository,RevCommit headCommit,RevCommit ancestorCommit,List<String> filterPaths,RevWalk rw,IProgressMonitor monitor) throws IOException, InterruptedException {
  monitor.setTaskName(UIText.GitMergeEditorInput_CalculatingDiffTaskName);
  IDiffContainer result=new DiffNode(Differencer.CONFLICTING);
  TreeWalk tw=new TreeWalk(repository);
  try {
    int dirCacheIndex=tw.addTree(new DirCacheIterator(repository.readDirCache()));
    int fileTreeIndex=tw.addTree(new FileTreeIterator(repository));
    int repositoryTreeIndex=tw.addTree(rw.parseTree(repository.resolve(Constants.HEAD)));
    NotIgnoredFilter notIgnoredFilter=new NotIgnoredFilter(fileTreeIndex);
    if (filterPaths.size() > 1) {
      List<TreeFilter> suffixFilters=new ArrayList<TreeFilter>();
      for (      String filterPath : filterPaths) {
        suffixFilters.add(PathFilter.create(filterPath));
      }
      TreeFilter otf=OrTreeFilter.create(suffixFilters);
      tw.setFilter(AndTreeFilter.create(otf,notIgnoredFilter));
    }
 else     if (filterPaths.size() > 0) {
      String path=filterPaths.get(0);
      if (path.length() == 0) {
        tw.setFilter(notIgnoredFilter);
      }
 else {
        tw.setFilter(AndTreeFilter.create(PathFilter.create(path),notIgnoredFilter));
      }
    }
 else {
      tw.setFilter(notIgnoredFilter);
    }
    tw.setRecursive(true);
    while (tw.next()) {
      if (monitor.isCanceled()) {
        throw new InterruptedException();
      }
      String gitPath=tw.getPathString();
      monitor.setTaskName(gitPath);
      FileTreeIterator fit=tw.getTree(fileTreeIndex,FileTreeIterator.class);
      if (fit == null) {
        continue;
      }
      DirCacheIterator dit=tw.getTree(dirCacheIndex,DirCacheIterator.class);
      final DirCacheEntry dirCacheEntry=dit == null ? null : dit.getDirCacheEntry();
      boolean conflicting=dirCacheEntry != null && dirCacheEntry.getStage() > 0;
      AbstractTreeIterator rt=tw.getTree(repositoryTreeIndex,AbstractTreeIterator.class);
      boolean modified=rt != null && !fit.getEntryObjectId().equals(rt.getEntryObjectId());
      if (!conflicting && !modified) {
        continue;
      }
      ITypedElement right;
      if (conflicting) {
        GitFileRevision revision=GitFileRevision.inIndex(repository,gitPath,DirCacheEntry.STAGE_3);
        String encoding=CompareCoreUtils.getResourceEncoding(repository,gitPath);
        right=new FileRevisionTypedElement(revision,encoding);
      }
 else {
        right=CompareUtils.getFileRevisionTypedElement(gitPath,headCommit,repository);
      }
      if (right instanceof EmptyTypedElement) {
        continue;
      }
      IFileRevision rev;
      Path repositoryPath=new Path(repository.getWorkTree().getAbsolutePath());
      IPath location=repositoryPath.append(fit.getEntryPathString());
      IFile file=ModelEGitResourceUtil.getFileForLocation(location);
      if (!conflicting || useWorkspace) {
        if (file != null) {
          rev=new LocalFileRevision(file);
        }
 else {
          rev=new WorkingTreeFileRevision(location.toFile());
        }
      }
 else {
        rev=GitFileRevision.inIndex(repository,gitPath,DirCacheEntry.STAGE_2);
      }
      IRunnableContext runnableContext=getContainer();
      if (runnableContext == null) {
        runnableContext=PlatformUI.getWorkbench().getProgressService();
      }
      EditableRevision leftEditable;
      if (file != null) {
        leftEditable=new ResourceEditableRevision(rev,file,runnableContext);
      }
 else {
        leftEditable=new LocationEditableRevision(rev,location,runnableContext);
      }
      try {
        leftEditable.cacheContents(monitor);
      }
 catch (      CoreException e) {
        throw new IOException(e.getMessage());
      }
      int kind=Differencer.NO_CHANGE;
      if (conflicting) {
        kind=Differencer.CONFLICTING;
      }
 else       if (modified) {
        kind=Differencer.PSEUDO_CONFLICT;
      }
      IDiffContainer fileParent=getFileParent(result,repositoryPath,file,location);
      ITypedElement anc;
      if (ancestorCommit != null) {
        anc=CompareUtils.getFileRevisionTypedElement(gitPath,ancestorCommit,repository);
      }
 else {
        anc=null;
      }
      if (anc instanceof EmptyTypedElement) {
        anc=null;
      }
      new DiffNode(fileParent,kind,anc,leftEditable,right);
    }
    return result;
  }
  finally {
    tw.close();
  }
}

Fixed version (ground truth):
private IDiffContainer buildDiffContainer(Repository repository,RevCommit headCommit,RevCommit ancestorCommit,List<String> filterPaths,RevWalk rw,IProgressMonitor monitor) throws IOException, InterruptedException {
  monitor.setTaskName(UIText.GitMergeEditorInput_CalculatingDiffTaskName);
  IDiffContainer result=new DiffNode(Differencer.CONFLICTING);
  TreeWalk tw=new TreeWalk(repository);
  try {
    int dirCacheIndex=tw.addTree(new DirCacheIterator(repository.readDirCache()));
    int fileTreeIndex=tw.addTree(new FileTreeIterator(repository));
    int repositoryTreeIndex=tw.addTree(rw.parseTree(repository.resolve(Constants.HEAD)));
    NotIgnoredFilter notIgnoredFilter=new NotIgnoredFilter(fileTreeIndex);
    if (filterPaths.size() > 1) {
      List<TreeFilter> suffixFilters=new ArrayList<TreeFilter>();
      for (      String filterPath : filterPaths) {
        suffixFilters.add(PathFilter.create(filterPath));
      }
      TreeFilter otf=OrTreeFilter.create(suffixFilters);
      tw.setFilter(AndTreeFilter.create(otf,notIgnoredFilter));
    }
 else     if (filterPaths.size() > 0) {
      String path=filterPaths.get(0);
      if (path.length() == 0) {
        tw.setFilter(notIgnoredFilter);
      }
 else {
        tw.setFilter(AndTreeFilter.create(PathFilter.create(path),notIgnoredFilter));
      }
    }
 else {
      tw.setFilter(notIgnoredFilter);
    }
    tw.setRecursive(true);
    while (tw.next()) {
      if (monitor.isCanceled()) {
        throw new InterruptedException();
      }
      String gitPath=tw.getPathString();
      monitor.setTaskName(gitPath);
      FileTreeIterator fit=tw.getTree(fileTreeIndex,FileTreeIterator.class);
      if (fit == null) {
        continue;
      }
      DirCacheIterator dit=tw.getTree(dirCacheIndex,DirCacheIterator.class);
      final DirCacheEntry dirCacheEntry=dit == null ? null : dit.getDirCacheEntry();
      boolean conflicting=dirCacheEntry != null && dirCacheEntry.getStage() > 0;
      AbstractTreeIterator rt=tw.getTree(repositoryTreeIndex,AbstractTreeIterator.class);
      boolean modified=rt != null && !fit.getEntryObjectId().equals(rt.getEntryObjectId());
      if (!conflicting && !modified) {
        continue;
      }
      ITypedElement right;
      if (conflicting) {
        GitFileRevision revision=GitFileRevision.inIndex(repository,gitPath,DirCacheEntry.STAGE_3);
        String encoding=CompareCoreUtils.getResourceEncoding(repository,gitPath);
        right=new FileRevisionTypedElement(revision,encoding);
      }
 else {
        right=CompareUtils.getFileRevisionTypedElement(gitPath,headCommit,repository);
      }
      if (right instanceof EmptyTypedElement) {
        continue;
      }
      IFileRevision rev;
      Path repositoryPath=new Path(repository.getWorkTree().getAbsolutePath());
      IPath location=repositoryPath.append(fit.getEntryPathString());
      IFile file=ModelEGitResourceUtil.getFileForLocation(location,false);
      if (!conflicting || useWorkspace) {
        if (file != null) {
          rev=new LocalFileRevision(file);
        }
 else {
          rev=new WorkingTreeFileRevision(location.toFile());
        }
      }
 else {
        rev=GitFileRevision.inIndex(repository,gitPath,DirCacheEntry.STAGE_2);
      }
      IRunnableContext runnableContext=getContainer();
      if (runnableContext == null) {
        runnableContext=PlatformUI.getWorkbench().getProgressService();
      }
      EditableRevision leftEditable;
      if (file != null) {
        leftEditable=new ResourceEditableRevision(rev,file,runnableContext);
      }
 else {
        leftEditable=new LocationEditableRevision(rev,location,runnableContext);
      }
      try {
        leftEditable.cacheContents(monitor);
      }
 catch (      CoreException e) {
        throw new IOException(e.getMessage());
      }
      int kind=Differencer.NO_CHANGE;
      if (conflicting) {
        kind=Differencer.CONFLICTING;
      }
 else       if (modified) {
        kind=Differencer.PSEUDO_CONFLICT;
      }
      IDiffContainer fileParent=getFileParent(result,repositoryPath,file,location);
      ITypedElement anc;
      if (ancestorCommit != null) {
        anc=CompareUtils.getFileRevisionTypedElement(gitPath,ancestorCommit,repository);
      }
 else {
        anc=null;
      }
      if (anc instanceof EmptyTypedElement) {
        anc=null;
      }
      new DiffNode(fileParent,kind,anc,leftEditable,right);
    }
    return result;
  }
  finally {
    tw.close();
  }
}