Program: 126885
Project: 126885
Buggy source:
protected void createSystemSQLPatterns() throws PersistenceException {
  ERepositoryObjectType sqlpatternsType=ERepositoryObjectType.SQLPATTERNS;
  if (sqlpatternsType == 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.getSystemSQLPatterns();
  List<IRepositoryViewObject> repositoryObjects=getAll(project,sqlpatternsType,false,false);
  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");
    Path relativePath=new Path(url.getFile());
    String fileName=relativePath.segment(relativePath.segmentCount() - 1);
    String categoryName=relativePath.segment(relativePath.segmentCount() - 2);
    tmp=fileName.split("String_Node_Str");
    String sqlPatternLabel=tmp[0];
    SQLPatternItem existingItem=null;
    for (    IRepositoryViewObject object : repositoryObjects) {
      if (object.getLabel().equals(sqlPatternLabel) && object.getProperty().getItem() instanceof SQLPatternItem && ((SQLPatternItem)object.getProperty().getItem()).getEltName().equals(categoryName)) {
        existingItem=(SQLPatternItem)object.getProperty().getItem();
        break;
      }
    }
    IPath categoryPath=new Path(categoryName);
    IPath systemPath=categoryPath.append(RepositoryConstants.SYSTEM_DIRECTORY);
    IPath userPath=categoryPath.append(RepositoryConstants.USER_DEFINED);
    IPath parentPath=new Path(ERepositoryObjectType.getFolderName(sqlpatternsType));
    if (folderHelper.getFolder(parentPath.append(categoryPath)) == null) {
      createFolder(getRepositoryContext().getProject(),sqlpatternsType,new Path("String_Node_Str"),categoryPath.lastSegment());
    }
    FolderItem systemFolder=folderHelper.getFolder(parentPath.append(systemPath));
    if (systemFolder == null) {
      Folder folder=createFolder(getRepositoryContext().getProject(),sqlpatternsType,categoryPath,systemPath.lastSegment());
      ((FolderItem)folder.getProperty().getItem()).setType(FolderType.SYSTEM_FOLDER_LITERAL);
    }
    if (folderHelper.getFolder(parentPath.append(userPath)) == null) {
      Folder folder=createFolder(getRepositoryContext().getProject(),sqlpatternsType,categoryPath,userPath.lastSegment());
      ((FolderItem)folder.getProperty().getItem()).setType(FolderType.SYSTEM_FOLDER_LITERAL);
    }
    if (existingItem == null) {
      createSQLPattern(url,sqlPatternLabel,categoryName);
    }
 else {
      updateSQLPattern(url,existingItem);
      existingItem.setParent(systemFolder);
    }
  }
}

Fixed version (ground truth):
protected void createSystemSQLPatterns() throws PersistenceException {
  ERepositoryObjectType sqlpatternsType=ERepositoryObjectType.SQLPATTERNS;
  if (sqlpatternsType == 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.getSystemSQLPatterns();
  List<IRepositoryViewObject> repositoryObjects=getAll(project,sqlpatternsType,false,false);
  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");
    Path relativePath=new Path(url.getFile());
    String fileName=relativePath.segment(relativePath.segmentCount() - 1);
    String categoryName=relativePath.segment(relativePath.segmentCount() - 2);
    tmp=fileName.split("String_Node_Str");
    String sqlPatternLabel=tmp[0];
    SQLPatternItem existingItem=null;
    for (    IRepositoryViewObject object : repositoryObjects) {
      if (object.getLabel().equals(sqlPatternLabel) && object.getProperty().getItem() instanceof SQLPatternItem && ((SQLPatternItem)object.getProperty().getItem()).getEltName().equals(categoryName)) {
        existingItem=(SQLPatternItem)object.getProperty().getItem();
        break;
      }
    }
    IPath categoryPath=new Path(categoryName);
    IPath systemPath=categoryPath.append(RepositoryConstants.SYSTEM_DIRECTORY);
    IPath userPath=categoryPath.append(RepositoryConstants.USER_DEFINED);
    IPath parentPath=new Path(ERepositoryObjectType.getFolderName(sqlpatternsType));
    if (folderHelper.getFolder(parentPath.append(categoryPath)) == null) {
      createFolder(getRepositoryContext().getProject(),sqlpatternsType,new Path("String_Node_Str"),categoryPath.lastSegment());
    }
    FolderItem systemFolder=folderHelper.getFolder(parentPath.append(systemPath));
    if (systemFolder == null) {
      Folder folder=createFolder(getRepositoryContext().getProject(),sqlpatternsType,categoryPath,systemPath.lastSegment());
      ((FolderItem)folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
    }
    if (folderHelper.getFolder(parentPath.append(userPath)) == null) {
      Folder folder=createFolder(getRepositoryContext().getProject(),sqlpatternsType,categoryPath,userPath.lastSegment());
      ((FolderItem)folder.getProperty().getItem()).setType(FolderType.FOLDER_LITERAL);
    }
    if (existingItem == null) {
      createSQLPattern(url,sqlPatternLabel,categoryName);
    }
 else {
      updateSQLPattern(url,existingItem);
      existingItem.setParent(systemFolder);
    }
  }
}