Program: 128849
Project: 128849
Buggy source:
/** 
 * DOC smallet Comment method "addFolderMembers".
 * @param < T > - DOC smallet
 * @param type - DOC smallet
 * @param toReturn - DOC smallet
 * @param objectFolder - DOC smallet
 * @param onlyLastVersion specify <i>true</i> if only the last version of an object must be returned, false for allversion
 * @throws PersistenceException - DOC smallet
 */
@Override protected <K,T>void addFolderMembers(Project project,ERepositoryObjectType type,Container<K,T> toReturn,Object objectFolder,boolean onlyLastVersion,boolean... options) throws PersistenceException {
  FolderHelper folderHelper=getFolderHelper(project.getEmfProject());
  FolderItem currentFolderItem=null;
  IFolder physicalFolder;
  if (objectFolder instanceof IFolder) {
    if (!((IFolder)objectFolder).getName().equals(BIN)) {
      currentFolderItem=folderHelper.getFolder(((IFolder)objectFolder).getProjectRelativePath());
      if (currentFolderItem == null) {
        currentFolderItem=folderHelper.createFolder(((IFolder)objectFolder).getProjectRelativePath().toPortableString());
      }
    }
    physicalFolder=(IFolder)objectFolder;
  }
 else {
    currentFolderItem=(FolderItem)objectFolder;
    physicalFolder=getPhysicalProject(project).getFolder(folderHelper.getFullFolderPath(currentFolderItem));
  }
  List<String> propertyFounds=new ArrayList<String>();
  List<String> folderNamesFounds=new ArrayList<String>();
  List<Item> invalidItems=new ArrayList<Item>();
  if (currentFolderItem != null) {
    for (    Item curItem : new ArrayList<Item>(currentFolderItem.getChildren())) {
      Property property=curItem.getProperty();
      if (property != null) {
        if (curItem instanceof FolderItem) {
          FolderItem subFolder=(FolderItem)curItem;
          Container<K,T> cont=toReturn.addSubContainer(subFolder.getProperty().getLabel());
          subFolder.setParent(currentFolderItem);
          cont.setProperty(property);
          cont.setId(property.getId());
          addFolderMembers(project,type,cont,curItem,onlyLastVersion,options);
          folderNamesFounds.add(curItem.getProperty().getLabel());
        }
 else {
          if (property.eResource() != null) {
            property.getItem().setParent(currentFolderItem);
            IRepositoryViewObject currentObject;
            if (options.length > 0 && options[0] == true) {
              currentObject=new RepositoryViewObject(property);
              ImageUtils.propertyImgCachedImages.clear();
            }
 else {
              currentObject=new RepositoryObject(property);
            }
            propertyFounds.add(property.eResource().getURI().lastSegment());
            addItemToContainer(toReturn,currentObject,onlyLastVersion);
            addToHistory(property.getId(),type,property.getItem().getState().getPath());
          }
 else {
            invalidItems.add(curItem);
          }
        }
      }
 else {
        invalidItems.add(curItem);
      }
    }
    for (    Item item : invalidItems) {
      item.setParent(null);
    }
    currentFolderItem.getChildren().removeAll(invalidItems);
  }
  if (physicalFolder.exists()) {
    List<String> physicalPropertyFounds=new ArrayList<String>();
    List<String> physicalDirectoryFounds=new ArrayList<String>();
    for (    IResource current : ResourceUtils.getMembers(physicalFolder)) {
      if (current instanceof IFile) {
        try {
          String fileName=((IFile)current).getName();
          IRepositoryViewObject currentObject=null;
          physicalPropertyFounds.add(fileName);
          if (xmiResourceManager.isPropertyFile((IFile)current) && !propertyFounds.contains(fileName)) {
            Property property=null;
            try {
              property=xmiResourceManager.loadProperty(current);
            }
 catch (            RuntimeException e) {
              ExceptionHandler.process(e);
            }
            if (property != null) {
              if (property.getItem() == null || property.getItem().getState() == null) {
                if (type != null) {
                  log.error("String_Node_Str" + property.getLabel() + "String_Node_Str"+ type);
                }
 else {
                  log.error("String_Node_Str" + property.getLabel());
                }
                continue;
              }
              if (currentFolderItem != null && !currentFolderItem.getChildren().contains(property.getItem())) {
                currentFolderItem.getChildren().add(property.getItem());
                property.getItem().setParent(currentFolderItem);
              }
              if (options.length > 0 && options[0] == true) {
                currentObject=new RepositoryViewObject(property);
              }
 else {
                currentObject=new RepositoryObject(property);
              }
            }
 else {
              log.error(Messages.getString("String_Node_Str") + current);
            }
            addItemToContainer(toReturn,currentObject,onlyLastVersion);
          }
        }
 catch (        IncorrectFileException e) {
          ExceptionHandler.process(e);
        }
catch (        PersistenceException e) {
          ExceptionHandler.process(e);
        }
      }
 else       if (current instanceof IFolder) {
        if (!((IFolder)current).getName().startsWith("String_Node_Str") && !FilesUtils.isSVNFolder(current)) {
          physicalDirectoryFounds.add(((IFolder)current).getName());
          if (!folderNamesFounds.contains(((IFolder)current).getName())) {
            Container<K,T> cont=toReturn.addSubContainer(current.getName());
            FolderItem folder=folderHelper.getFolder(current.getProjectRelativePath());
            Property property=null;
            if (folder == null) {
              folder=folderHelper.createFolder(current.getProjectRelativePath().toString());
            }
            property=folder.getProperty();
            folder.setParent(currentFolderItem);
            cont.setProperty(property);
            cont.setId(property.getId());
            addFolderMembers(project,type,cont,current,onlyLastVersion,options);
          }
          if (current.getName().equals(BIN)) {
            IResource[] binFolder=ResourceUtils.getMembers((IFolder)current);
            if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
              try {
                ((IFolder)current).delete(true,null);
              }
 catch (              CoreException e) {
              }
            }
          }
        }
      }
    }
    if (currentFolderItem != null) {
      List<Item> itemsDeleted=new ArrayList<Item>();
      for (      Item curItem : (List<Item>)currentFolderItem.getChildren()) {
        if (!(curItem instanceof FolderItem)) {
          String name;
          if (curItem.eResource() != null) {
            name=curItem.eResource().getURI().lastSegment();
          }
 else {
            name=curItem.getProperty().getLabel() + "String_Node_Str" + curItem.getProperty().getVersion()+ "String_Node_Str"+ FileConstants.PROPERTIES_EXTENSION;
          }
          if (!physicalPropertyFounds.contains(name)) {
            itemsDeleted.add(curItem);
          }
        }
 else {
          if (!physicalDirectoryFounds.contains(curItem.getProperty().getLabel())) {
            itemsDeleted.add(curItem);
          }
        }
      }
      for (      Item item : itemsDeleted) {
        item.setParent(null);
        Iterator<IRepositoryViewObject> it=(Iterator<IRepositoryViewObject>)toReturn.getMembers().iterator();
        while (it.hasNext()) {
          IRepositoryViewObject object=it.next();
          if (object.getLabel().equals(item.getProperty().getLabel()) && object.getId().equals(item.getProperty().getId()) && object.getVersion().equals(item.getProperty().getVersion())) {
            it.remove();
          }
        }
      }
      currentFolderItem.getChildren().removeAll(itemsDeleted);
    }
  }
}

Fixed version (ground truth):
/** 
 * DOC smallet Comment method "addFolderMembers".
 * @param < T > - DOC smallet
 * @param type - DOC smallet
 * @param toReturn - DOC smallet
 * @param objectFolder - DOC smallet
 * @param onlyLastVersion specify <i>true</i> if only the last version of an object must be returned, false for allversion
 * @throws PersistenceException - DOC smallet
 */
@Override protected <K,T>void addFolderMembers(Project project,ERepositoryObjectType type,Container<K,T> toReturn,Object objectFolder,boolean onlyLastVersion,boolean... options) throws PersistenceException {
  FolderHelper folderHelper=getFolderHelper(project.getEmfProject());
  FolderItem currentFolderItem=null;
  IFolder physicalFolder;
  if (objectFolder instanceof IFolder) {
    if (!((IFolder)objectFolder).getName().equals(BIN)) {
      currentFolderItem=folderHelper.getFolder(((IFolder)objectFolder).getProjectRelativePath());
      if (currentFolderItem == null) {
        currentFolderItem=folderHelper.createFolder(((IFolder)objectFolder).getProjectRelativePath().toPortableString());
      }
    }
    physicalFolder=(IFolder)objectFolder;
  }
 else {
    currentFolderItem=(FolderItem)objectFolder;
    physicalFolder=getPhysicalProject(project).getFolder(folderHelper.getFullFolderPath(currentFolderItem));
  }
  List<String> propertyFounds=new ArrayList<String>();
  List<String> folderNamesFounds=new ArrayList<String>();
  List<Item> invalidItems=new ArrayList<Item>();
  if (currentFolderItem != null) {
    for (    Item curItem : new ArrayList<Item>(currentFolderItem.getChildren())) {
      Property property=curItem.getProperty();
      if (property != null) {
        if (curItem instanceof FolderItem) {
          FolderItem subFolder=(FolderItem)curItem;
          Container<K,T> cont=toReturn.addSubContainer(subFolder.getProperty().getLabel());
          subFolder.setParent(currentFolderItem);
          cont.setProperty(property);
          cont.setId(property.getId());
          addFolderMembers(project,type,cont,curItem,onlyLastVersion,options);
          folderNamesFounds.add(curItem.getProperty().getLabel());
        }
 else {
          if (property.eResource() != null) {
            property.getItem().setParent(currentFolderItem);
            IRepositoryViewObject currentObject;
            if (options.length > 0 && options[0] == true) {
              currentObject=new RepositoryViewObject(property);
            }
 else {
              currentObject=new RepositoryObject(property);
            }
            propertyFounds.add(property.eResource().getURI().lastSegment());
            addItemToContainer(toReturn,currentObject,onlyLastVersion);
            addToHistory(property.getId(),type,property.getItem().getState().getPath());
          }
 else {
            invalidItems.add(curItem);
          }
        }
      }
 else {
        invalidItems.add(curItem);
      }
    }
    for (    Item item : invalidItems) {
      item.setParent(null);
    }
    currentFolderItem.getChildren().removeAll(invalidItems);
  }
  if (physicalFolder.exists()) {
    List<String> physicalPropertyFounds=new ArrayList<String>();
    List<String> physicalDirectoryFounds=new ArrayList<String>();
    for (    IResource current : ResourceUtils.getMembers(physicalFolder)) {
      if (current instanceof IFile) {
        try {
          String fileName=((IFile)current).getName();
          IRepositoryViewObject currentObject=null;
          physicalPropertyFounds.add(fileName);
          if (xmiResourceManager.isPropertyFile((IFile)current) && !propertyFounds.contains(fileName)) {
            Property property=null;
            try {
              property=xmiResourceManager.loadProperty(current);
            }
 catch (            RuntimeException e) {
              ExceptionHandler.process(e);
            }
            if (property != null) {
              if (property.getItem() == null || property.getItem().getState() == null) {
                if (type != null) {
                  log.error("String_Node_Str" + property.getLabel() + "String_Node_Str"+ type);
                }
 else {
                  log.error("String_Node_Str" + property.getLabel());
                }
                continue;
              }
              if (currentFolderItem != null && !currentFolderItem.getChildren().contains(property.getItem())) {
                currentFolderItem.getChildren().add(property.getItem());
                property.getItem().setParent(currentFolderItem);
              }
              if (options.length > 0 && options[0] == true) {
                currentObject=new RepositoryViewObject(property);
              }
 else {
                currentObject=new RepositoryObject(property);
              }
            }
 else {
              log.error(Messages.getString("String_Node_Str") + current);
            }
            addItemToContainer(toReturn,currentObject,onlyLastVersion);
          }
        }
 catch (        IncorrectFileException e) {
          ExceptionHandler.process(e);
        }
catch (        PersistenceException e) {
          ExceptionHandler.process(e);
        }
      }
 else       if (current instanceof IFolder) {
        if (!((IFolder)current).getName().startsWith("String_Node_Str") && !FilesUtils.isSVNFolder(current)) {
          physicalDirectoryFounds.add(((IFolder)current).getName());
          if (!folderNamesFounds.contains(((IFolder)current).getName())) {
            Container<K,T> cont=toReturn.addSubContainer(current.getName());
            FolderItem folder=folderHelper.getFolder(current.getProjectRelativePath());
            Property property=null;
            if (folder == null) {
              folder=folderHelper.createFolder(current.getProjectRelativePath().toString());
            }
            property=folder.getProperty();
            folder.setParent(currentFolderItem);
            cont.setProperty(property);
            cont.setId(property.getId());
            addFolderMembers(project,type,cont,current,onlyLastVersion,options);
          }
          if (current.getName().equals(BIN)) {
            IResource[] binFolder=ResourceUtils.getMembers((IFolder)current);
            if (binFolder.length == 0 || (binFolder.length == 1 && FilesUtils.isSVNFolder(binFolder[0]))) {
              try {
                ((IFolder)current).delete(true,null);
              }
 catch (              CoreException e) {
              }
            }
          }
        }
      }
    }
    if (currentFolderItem != null) {
      List<Item> itemsDeleted=new ArrayList<Item>();
      for (      Item curItem : (List<Item>)currentFolderItem.getChildren()) {
        if (!(curItem instanceof FolderItem)) {
          String name;
          if (curItem.eResource() != null) {
            name=curItem.eResource().getURI().lastSegment();
          }
 else {
            name=curItem.getProperty().getLabel() + "String_Node_Str" + curItem.getProperty().getVersion()+ "String_Node_Str"+ FileConstants.PROPERTIES_EXTENSION;
          }
          if (!physicalPropertyFounds.contains(name)) {
            itemsDeleted.add(curItem);
          }
        }
 else {
          if (!physicalDirectoryFounds.contains(curItem.getProperty().getLabel())) {
            itemsDeleted.add(curItem);
          }
        }
      }
      for (      Item item : itemsDeleted) {
        item.setParent(null);
        Iterator<IRepositoryViewObject> it=(Iterator<IRepositoryViewObject>)toReturn.getMembers().iterator();
        while (it.hasNext()) {
          IRepositoryViewObject object=it.next();
          if (object.getLabel().equals(item.getProperty().getLabel()) && object.getId().equals(item.getProperty().getId()) && object.getVersion().equals(item.getProperty().getVersion())) {
            it.remove();
          }
        }
      }
      currentFolderItem.getChildren().removeAll(itemsDeleted);
    }
  }
}