Program: 93568
Project: 93568
Buggy source:
/** 
 * Even if there is a single file involved in this operation, it may have a custom comparator or merger defined. This will be found through its specific ISynchronizationCompareAdapter. <p> If there are multiple files involved, we need them all to be part of the same logical model. Otherwise, we can't be sure that multiple ISynchronizationCompareAdapter aren't interested in the different files, and thus cannot show a valid 'aggregate' compare editor. </p> <p> Then again, even if the multiple files involved are all part of single-file models (i.e. none of them is a part of a larger logical model, and we have as many models involved as there are files), we cannot show them all within the same compare editor input. Comparing the files and determining conflicts is the job of the ISynchronizationCompareAdapter(s), <u>not</u> ours. If we cannot reliably find the appropriate compare adapter, we should not try and compare the files ourselves. The user will have to manually open the merge tool on each individual logical model. </p> <p> Since we cannot determine the logical model of a file that is not in the workspace, this will fall back to the 'old' merge tool (we compute the diffs ourselves without consideration for the file type) iff there are <u>only</u> such files in the locations set. </p>
 * @param repository Repository within which the compared files are located.
 * @param filterPaths repository-relative paths of the resources we are comparing.
 * @param monitor Monitor on which to report progress to the user.
 * @return The useable compare input.
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
private ICompareInput prepareCompareInput(Repository repository,List<String> filterPaths,IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
  try {
    final GitResourceVariantTreeProvider variantTreeProvider=new DirCacheResourceVariantTreeProvider(repository,useWorkspace);
    final Subscriber subscriber=new GitResourceVariantTreeSubscriber(variantTreeProvider);
    checkCanceled(monitor);
    final Set<IProject> projects=new LinkedHashSet<IProject>();
    for (    IResource root : subscriber.roots()) {
      projects.add(root.getProject());
    }
    final Set<IResource> resourcesInOperation=new LinkedHashSet<IResource>();
    boolean outOfWS=false;
    for (    IPath path : locations) {
      boolean foundMatchInWS=false;
      final Iterator<IProject> projectIterator=projects.iterator();
      while (!foundMatchInWS && projectIterator.hasNext()) {
        final IProject project=projectIterator.next();
        final IPath projectLocation=project.getLocation();
        if (projectLocation.equals(path)) {
          resourcesInOperation.addAll(getConflictingFilesFrom(project));
          foundMatchInWS=true;
        }
 else         if (project.getLocation().isPrefixOf(path)) {
          final IResource resource=ModelEGitResourceUtil.getResourceForLocation(path);
          if (resource instanceof IContainer) {
            resourcesInOperation.addAll(getConflictingFilesFrom((IContainer)resource));
          }
 else {
            resourcesInOperation.add(resource);
          }
          foundMatchInWS=true;
        }
      }
      if (!foundMatchInWS) {
        if (!resourcesInOperation.isEmpty()) {
          break;
        }
 else {
          outOfWS=true;
        }
      }
 else       if (outOfWS) {
        break;
      }
    }
    checkCanceled(monitor);
    if (!resourcesInOperation.isEmpty() && outOfWS) {
      throw new InvocationTargetException(new IllegalStateException(EMFCompareEGitUIMessages.getString("String_Node_Str")));
    }
 else     if (resourcesInOperation.isEmpty()) {
    }
 else {
      final RemoteResourceMappingContext remoteMappingContext=new SubscriberResourceMappingContext(subscriber,true);
      Set<IResource> model=null;
      for (      IResource comparedResource : resourcesInOperation) {
        model=LogicalModels.discoverModel(comparedResource,remoteMappingContext);
        if (model.isEmpty()) {
        }
 else {
          if (!model.containsAll(resourcesInOperation)) {
            throw new RuntimeException(EMFCompareEGitUIMessages.getString("String_Node_Str"));
          }
 else {
            break;
          }
        }
      }
      final ISynchronizationCompareAdapter compareAdapter=LogicalModels.findAdapter(model,ISynchronizationCompareAdapter.class);
      if (compareAdapter != null) {
        final Set<ResourceMapping> allMappings=LogicalModels.getResourceMappings(model,remoteMappingContext);
        checkCanceled(monitor);
        final ISynchronizationContext synchronizationContext=prepareSynchronizationContext(repository,subscriber,allMappings,remoteMappingContext);
        final Object modelObject=allMappings.iterator().next().getModelObject();
        if (compareAdapter.hasCompareInput(synchronizationContext,modelObject)) {
          return compareAdapter.asCompareInput(synchronizationContext,modelObject);
        }
 else {
        }
      }
 else {
      }
    }
  }
 catch (  IOException e) {
    throw new InvocationTargetException(e);
  }
catch (  CoreException e) {
    throw new InvocationTargetException(e);
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Even if there is a single file involved in this operation, it may have a custom comparator or merger defined. This will be found through its specific ISynchronizationCompareAdapter. <p> If there are multiple files involved, we need them all to be part of the same logical model. Otherwise, we can't be sure that multiple ISynchronizationCompareAdapter aren't interested in the different files, and thus cannot show a valid 'aggregate' compare editor. </p> <p> Then again, even if the multiple files involved are all part of single-file models (i.e. none of them is a part of a larger logical model, and we have as many models involved as there are files), we cannot show them all within the same compare editor input. Comparing the files and determining conflicts is the job of the ISynchronizationCompareAdapter(s), <u>not</u> ours. If we cannot reliably find the appropriate compare adapter, we should not try and compare the files ourselves. The user will have to manually open the merge tool on each individual logical model. </p> <p> Since we cannot determine the logical model of a file that is not in the workspace, this will fall back to the 'old' merge tool (we compute the diffs ourselves without consideration for the file type) iff there are <u>only</u> such files in the locations set. </p>
 * @param repository Repository within which the compared files are located.
 * @param filterPaths repository-relative paths of the resources we are comparing.
 * @param monitor Monitor on which to report progress to the user.
 * @return The useable compare input.
 * @throws InvocationTargetException
 * @throws InterruptedException
 */
private ICompareInput prepareCompareInput(Repository repository,List<String> filterPaths,IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
  try {
    final GitResourceVariantTreeProvider variantTreeProvider=new DirCacheResourceVariantTreeProvider(repository,useWorkspace);
    final Subscriber subscriber=new GitResourceVariantTreeSubscriber(variantTreeProvider);
    checkCanceled(monitor);
    final Set<IProject> projects=new LinkedHashSet<IProject>();
    for (    IResource root : subscriber.roots()) {
      projects.add(root.getProject());
    }
    final Set<IResource> resourcesInOperation=new LinkedHashSet<IResource>();
    boolean outOfWS=false;
    for (    IPath path : locations) {
      boolean foundMatchInWS=false;
      final Iterator<IProject> projectIterator=projects.iterator();
      while (!foundMatchInWS && projectIterator.hasNext()) {
        final IProject project=projectIterator.next();
        final IPath projectLocation=project.getLocation();
        if (projectLocation.equals(path)) {
          resourcesInOperation.addAll(getConflictingFilesFrom(project));
          foundMatchInWS=true;
        }
 else         if (project.getLocation().isPrefixOf(path)) {
          final IResource resource=ModelEGitResourceUtil.getResourceForLocation(path,false);
          if (resource instanceof IContainer) {
            resourcesInOperation.addAll(getConflictingFilesFrom((IContainer)resource));
          }
 else {
            resourcesInOperation.add(resource);
          }
          foundMatchInWS=true;
        }
      }
      if (!foundMatchInWS) {
        if (!resourcesInOperation.isEmpty()) {
          break;
        }
 else {
          outOfWS=true;
        }
      }
 else       if (outOfWS) {
        break;
      }
    }
    checkCanceled(monitor);
    if (!resourcesInOperation.isEmpty() && outOfWS) {
      throw new InvocationTargetException(new IllegalStateException(EMFCompareEGitUIMessages.getString("String_Node_Str")));
    }
 else     if (resourcesInOperation.isEmpty()) {
    }
 else {
      final RemoteResourceMappingContext remoteMappingContext=new SubscriberResourceMappingContext(subscriber,true);
      Set<IResource> model=null;
      for (      IResource comparedResource : resourcesInOperation) {
        model=LogicalModels.discoverModel(comparedResource,remoteMappingContext);
        if (model.isEmpty()) {
        }
 else {
          if (!model.containsAll(resourcesInOperation)) {
            throw new RuntimeException(EMFCompareEGitUIMessages.getString("String_Node_Str"));
          }
 else {
            break;
          }
        }
      }
      final ISynchronizationCompareAdapter compareAdapter=LogicalModels.findAdapter(model,ISynchronizationCompareAdapter.class);
      if (compareAdapter != null) {
        final Set<ResourceMapping> allMappings=LogicalModels.getResourceMappings(model,remoteMappingContext);
        checkCanceled(monitor);
        final ISynchronizationContext synchronizationContext=prepareSynchronizationContext(repository,subscriber,allMappings,remoteMappingContext);
        final Object modelObject=allMappings.iterator().next().getModelObject();
        if (compareAdapter.hasCompareInput(synchronizationContext,modelObject)) {
          return compareAdapter.asCompareInput(synchronizationContext,modelObject);
        }
 else {
        }
      }
 else {
      }
    }
  }
 catch (  IOException e) {
    throw new InvocationTargetException(e);
  }
catch (  CoreException e) {
    throw new InvocationTargetException(e);
  }
  return null;
}