Program: 11724
Project: 11724
Buggy source:
protected void referencedGenModelsAddSelected(CheckboxTreeViewer treeViewer){
  IPath path=null;
  Resource resource=getModelConverter().getGenModel().eResource();
  if (resource != null) {
    if (resource.getURI().isPlatformResource()) {
      path=new Path(resource.getURI().toPlatformString(true)).makeAbsolute();
    }
  }
  final IPath genModelPath=path;
  ResourceSet resourceSet=null;
  List<GenModel> genModels=new UniqueEList.FastCompare<GenModel>();
  final Set<URI> genModelURIs=new HashSet<URI>();
  Object input=treeViewer.getInput();
  if (input instanceof ItemProvider) {
    Collection<?> elements=((ItemProvider)input).getChildren();
    for (    Object element : elements) {
      if (element instanceof GenModel) {
        GenModel genModel=(GenModel)element;
        URI genModelURI=genModel.eResource().getURI();
        genModels.add(genModel);
        genModelURIs.add(genModelURI);
        if (resourceSet == null && genModelURI.isPlatformResource()) {
          resourceSet=genModel.eResource().getResourceSet();
        }
      }
    }
  }
  ViewerFilter genModelFilter=new ViewerFilter(){
    @Override public boolean select(    Viewer viewer,    Object parentElement,    Object element){
      if (element instanceof IFile) {
        IFile file=(IFile)element;
        URI uri=URI.createPlatformResourceURI(file.getFullPath().toString(),true);
        return "String_Node_Str".equals(file.getFileExtension()) && !file.getFullPath().equals(genModelPath) && !genModelURIs.contains(uri);
      }
      return true;
    }
  }
;
  IFile[] files=WorkspaceResourceDialog.openFileSelection(getShell(),null,ConverterPlugin.INSTANCE.getString("String_Node_Str"),true,null,Collections.singletonList(genModelFilter));
  if (files.length > 0) {
    ResourceSet referencedGenModels=resourceSet != null ? resourceSet : getModelConverter().createResourceSet();
    for (int i=0; i < files.length; ++i) {
      URI genModelURI=URI.createPlatformResourceURI(files[i].getFullPath().toString(),true);
      Resource genModelResource=referencedGenModels.getResource(genModelURI,true);
      GenModel genModel=(GenModel)genModelResource.getContents().get(0);
      genModels.add(genModel);
    }
    addExternalGenModels(genModels);
    addReferencedGenModels(genModels);
    List<GenPackage> genPackagesToCheck=new ArrayList<GenPackage>();
    Object[] checkedElements=treeViewer.getCheckedElements();
    LOOP:     for (int i=0; i < checkedElements.length; i++) {
      if (checkedElements[i] instanceof GenPackage) {
        GenPackage checkedGenPackage=(GenPackage)checkedElements[i];
        String nsURI=checkedGenPackage.getNSURI();
        for (        GenModel genModel : genModels) {
          for (          GenPackage genPackage : genModel.getGenPackages()) {
            if (nsURI.equals(genPackage.getNSURI())) {
              genPackagesToCheck.add(genPackage);
              continue LOOP;
            }
          }
        }
      }
    }
    treeViewer.getTree().deselectAll();
    treeViewer.cancelEditing();
    treeViewer.setInput(new ItemProvider(genModels));
    for (Iterator<?> i=genModels.iterator(); i.hasNext(); ) {
      treeViewer.expandToLevel(i.next(),AbstractTreeViewer.ALL_LEVELS);
    }
    treeViewer.setCheckedElements(genPackagesToCheck.toArray());
    referencedGenModelsCheckboxTreeViewerCheckStateChanged(null);
  }
}

Fixed version (ground truth):
protected void referencedGenModelsAddSelected(CheckboxTreeViewer treeViewer){
  IPath path=null;
  Resource resource=getModelConverter().getGenModel().eResource();
  if (resource != null) {
    if (resource.getURI().isPlatformResource()) {
      path=new Path(resource.getURI().toPlatformString(true)).makeAbsolute();
    }
  }
  final IPath genModelPath=path;
  ResourceSet resourceSet=null;
  List<GenModel> genModels=new UniqueEList.FastCompare<GenModel>();
  final Set<URI> genModelURIs=new HashSet<URI>();
  Object input=treeViewer.getInput();
  if (input instanceof ItemProvider) {
    Collection<?> elements=((ItemProvider)input).getChildren();
    for (    Object element : elements) {
      if (element instanceof GenModel) {
        GenModel genModel=(GenModel)element;
        URI genModelURI=genModel.eResource().getURI();
        genModels.add(genModel);
        genModelURIs.add(genModelURI);
        if (resourceSet == null && genModelURI.isPlatformResource()) {
          resourceSet=genModel.eResource().getResourceSet();
        }
      }
    }
  }
  ViewerFilter genModelFilter=new ViewerFilter(){
    @Override public boolean select(    Viewer viewer,    Object parentElement,    Object element){
      if (element instanceof IFile) {
        IFile file=(IFile)element;
        URI uri=URI.createPlatformResourceURI(file.getFullPath().toString(),true);
        String fileExtension=file.getFileExtension();
        return ("String_Node_Str".equals(fileExtension) || "String_Node_Str".equals(fileExtension)) && !file.getFullPath().equals(genModelPath) && !genModelURIs.contains(uri);
      }
      return true;
    }
  }
;
  IFile[] files=WorkspaceResourceDialog.openFileSelection(getShell(),null,ConverterPlugin.INSTANCE.getString("String_Node_Str"),true,null,Collections.singletonList(genModelFilter));
  if (files.length > 0) {
    ResourceSet referencedGenModels=resourceSet != null ? resourceSet : getModelConverter().createResourceSet();
    for (int i=0; i < files.length; ++i) {
      URI genModelURI=URI.createPlatformResourceURI(files[i].getFullPath().toString(),true);
      Resource genModelResource=referencedGenModels.getResource(genModelURI,true);
      GenModel genModel=(GenModel)EcoreUtil.getObjectByType(genModelResource.getContents(),GenModelPackage.Literals.GEN_MODEL);
      genModels.add(genModel);
    }
    addExternalGenModels(genModels);
    addReferencedGenModels(genModels);
    List<GenPackage> genPackagesToCheck=new ArrayList<GenPackage>();
    Object[] checkedElements=treeViewer.getCheckedElements();
    LOOP:     for (int i=0; i < checkedElements.length; i++) {
      if (checkedElements[i] instanceof GenPackage) {
        GenPackage checkedGenPackage=(GenPackage)checkedElements[i];
        String nsURI=checkedGenPackage.getNSURI();
        for (        GenModel genModel : genModels) {
          for (          GenPackage genPackage : genModel.getGenPackages()) {
            if (nsURI.equals(genPackage.getNSURI())) {
              genPackagesToCheck.add(genPackage);
              continue LOOP;
            }
          }
        }
      }
    }
    treeViewer.getTree().deselectAll();
    treeViewer.cancelEditing();
    treeViewer.setInput(new ItemProvider(genModels));
    for (Iterator<?> i=genModels.iterator(); i.hasNext(); ) {
      treeViewer.expandToLevel(i.next(),AbstractTreeViewer.ALL_LEVELS);
    }
    treeViewer.setCheckedElements(genPackagesToCheck.toArray());
    referencedGenModelsCheckboxTreeViewerCheckStateChanged(null);
  }
}