Program: 128111
Project: 128111
Buggy source:
protected void createSystemRoutines() throws PersistenceException {
  ILibrariesService service=null;
  if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
    return;
  }
  service=(ILibrariesService)GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
  Project project=getRepositoryContext().getProject();
  FolderHelper folderHelper=getFolderHelper(project.getEmfProject());
  List<URL> routines=service.getSystemRoutines();
  Path path=new Path(RepositoryConstants.SYSTEM_DIRECTORY);
  IPath systemRoutinePath=new Path(ERepositoryObjectType.getFolderName(ERepositoryObjectType.ROUTINES));
  systemRoutinePath=systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY);
  FolderItem folderItem=folderHelper.getFolder(systemRoutinePath);
  if (folderItem == null) {
    folderItem=folderHelper.createFolder(systemRoutinePath.toString());
  }
  IPath systemRoutineApiPath=new Path(ERepositoryObjectType.getFolderName(ERepositoryObjectType.ROUTINES));
  systemRoutineApiPath=systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY).append("String_Node_Str");
  FolderItem folderItemApi=folderHelper.getFolder(systemRoutineApiPath);
  if (folderItemApi == null) {
    folderItemApi=folderHelper.createFolder(systemRoutineApiPath.toString());
  }
  List<IRepositoryViewObject> repositoryObjects=getAll(project,ERepositoryObjectType.ROUTINES,false,false);
  Map<String,List<LibraryInfo>> routineAndJars=coreSerivce.getRoutineAndJars();
  for (  URL url : routines) {
    String[] fragments=url.toString().split("String_Node_Str");
    String label=fragments[fragments.length - 1];
    String[] tmp=label.split("String_Node_Str");
    String routineLabel=tmp[0];
    if (routineLabel.equals(coreSerivce.getTemplateString())) {
      continue;
    }
    RoutineItem existingItem=null;
    for (    IRepositoryViewObject object : repositoryObjects) {
      if (object.getLabel().equals(routineLabel) && object.getProperty().getItem() instanceof RoutineItem) {
        existingItem=(RoutineItem)object.getProperty().getItem();
        break;
      }
    }
    if (existingItem == null) {
      createRoutine(url,path,routineLabel,routineAndJars != null ? routineAndJars.get(routineLabel) : null);
    }
 else {
      updateRoutine(url,existingItem);
      existingItem.setParent(folderItem);
    }
  }
}

Fixed version (ground truth):
protected void createSystemRoutines() throws PersistenceException {
  ERepositoryObjectType routinesType=ERepositoryObjectType.ROUTINES;
  if (routinesType == null) {
    return;
  }
  ILibrariesService service=null;
  if (!GlobalServiceRegister.getDefault().isServiceRegistered(ILibrariesService.class)) {
    return;
  }
  service=(ILibrariesService)GlobalServiceRegister.getDefault().getService(ILibrariesService.class);
  Project project=getRepositoryContext().getProject();
  FolderHelper folderHelper=getFolderHelper(project.getEmfProject());
  List<URL> routines=service.getSystemRoutines();
  Path path=new Path(RepositoryConstants.SYSTEM_DIRECTORY);
  IPath systemRoutinePath=new Path(ERepositoryObjectType.getFolderName(routinesType));
  systemRoutinePath=systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY);
  FolderItem folderItem=folderHelper.getFolder(systemRoutinePath);
  if (folderItem == null) {
    folderItem=folderHelper.createFolder(systemRoutinePath.toString());
  }
  IPath systemRoutineApiPath=new Path(ERepositoryObjectType.getFolderName(routinesType));
  systemRoutineApiPath=systemRoutinePath.append(RepositoryConstants.SYSTEM_DIRECTORY).append("String_Node_Str");
  FolderItem folderItemApi=folderHelper.getFolder(systemRoutineApiPath);
  if (folderItemApi == null) {
    folderItemApi=folderHelper.createFolder(systemRoutineApiPath.toString());
  }
  List<IRepositoryViewObject> repositoryObjects=getAll(project,routinesType,false,false);
  Map<String,List<LibraryInfo>> routineAndJars=coreSerivce.getRoutineAndJars();
  for (  URL url : routines) {
    String[] fragments=url.toString().split("String_Node_Str");
    String label=fragments[fragments.length - 1];
    String[] tmp=label.split("String_Node_Str");
    String routineLabel=tmp[0];
    if (routineLabel.equals(coreSerivce.getTemplateString())) {
      continue;
    }
    RoutineItem existingItem=null;
    for (    IRepositoryViewObject object : repositoryObjects) {
      if (object.getLabel().equals(routineLabel) && object.getProperty().getItem() instanceof RoutineItem) {
        existingItem=(RoutineItem)object.getProperty().getItem();
        break;
      }
    }
    if (existingItem == null) {
      createRoutine(url,path,routineLabel,routineAndJars != null ? routineAndJars.get(routineLabel) : null);
    }
 else {
      updateRoutine(url,existingItem);
      existingItem.setParent(folderItem);
    }
  }
}