Program: 125749
Project: 125749
Buggy source:
private static List<ModuleNeeded> collectModuleNeeded(List<IRepositoryViewObject> routineItems,Set<String> routineIdOrNames,boolean system){
  List<ModuleNeeded> importNeedsList=new ArrayList<ModuleNeeded>();
  if (org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) {
    return importNeedsList;
  }
  if (!routineItems.isEmpty()) {
    for (    IRepositoryViewObject object : routineItems) {
      if (routineIdOrNames.contains(object.getLabel()) && system || routineIdOrNames.contains(object.getId()) && !system) {
        Item item=object.getProperty().getItem();
        if (item instanceof RoutineItem) {
          RoutineItem routine=(RoutineItem)item;
          importNeedsList.addAll(createModuleNeededFromRoutine(routine));
        }
      }
    }
  }
  if (system) {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerUIService.class)) {
      ILibraryManagerUIService libUiService=(ILibraryManagerUIService)GlobalServiceRegister.getDefault().getService(ILibraryManagerUIService.class);
      Set<String> routinesName=new HashSet<>();
      for (      IRoutinesProvider routineProvider : libUiService.getRoutinesProviders(ECodeLanguage.JAVA)) {
        for (        URL url : routineProvider.getSystemRoutines()) {
          String[] fragments=url.toString().split("String_Node_Str");
          String label=fragments[fragments.length - 1];
          String[] tmp=label.split("String_Node_Str");
          String routineName=tmp[0];
          routinesName.add(routineName);
        }
        for (        URL url : routineProvider.getTalendRoutines()) {
          String[] fragments=url.toString().split("String_Node_Str");
          String label=fragments[fragments.length - 1];
          String[] tmp=label.split("String_Node_Str");
          String routineName=tmp[0];
          routinesName.add(routineName);
        }
      }
      Map<String,List<LibraryInfo>> routineAndJars=libUiService.getRoutineAndJars();
      Iterator<Map.Entry<String,List<LibraryInfo>>> iter=routineAndJars.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String,List<LibraryInfo>> entry=iter.next();
        String routineName=entry.getKey();
        if (!routinesName.contains(routineName)) {
          continue;
        }
        List<LibraryInfo> needJars=entry.getValue();
        for (        LibraryInfo jar : needJars) {
          ModuleNeeded toAdd=new ModuleNeeded("String_Node_Str" + routineName,jar.getLibName(),"String_Node_Str",true);
          String bundleId=jar.getBundleId();
          if (bundleId != null) {
            String bundleName=null;
            String bundleVersion=null;
            if (bundleId.contains("String_Node_Str")) {
              String[] nameAndVersion=bundleId.split("String_Node_Str");
              bundleName=nameAndVersion[0];
              bundleVersion=nameAndVersion[1];
            }
 else {
              bundleName=bundleId;
            }
            toAdd.setBundleName(bundleName);
            toAdd.setBundleVersion(bundleVersion);
          }
          importNeedsList.add(toAdd);
        }
      }
    }
  }
  return importNeedsList;
}

Fixed version (ground truth):
private static List<ModuleNeeded> collectModuleNeeded(List<IRepositoryViewObject> routineItems,Set<String> routineIdOrNames,boolean system){
  List<ModuleNeeded> importNeedsList=new ArrayList<ModuleNeeded>();
  if (org.talend.commons.utils.platform.PluginChecker.isOnlyTopLoaded()) {
    return importNeedsList;
  }
  if (!routineItems.isEmpty()) {
    for (    IRepositoryViewObject object : routineItems) {
      if (routineIdOrNames.contains(object.getLabel()) && system || routineIdOrNames.contains(object.getId()) && !system) {
        Item item=object.getProperty().getItem();
        if (item instanceof RoutineItem) {
          RoutineItem routine=(RoutineItem)item;
          importNeedsList.addAll(createModuleNeededFromRoutine(routine));
        }
      }
    }
  }
  if (system) {
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ILibraryManagerUIService.class)) {
      ILibraryManagerUIService libUiService=(ILibraryManagerUIService)GlobalServiceRegister.getDefault().getService(ILibraryManagerUIService.class);
      Set<String> routinesName=new HashSet<>();
      for (      IRoutinesProvider routineProvider : libUiService.getRoutinesProviders(ECodeLanguage.JAVA)) {
        for (        URL url : routineProvider.getSystemRoutines()) {
          String[] fragments=url.toString().split("String_Node_Str");
          String label=fragments[fragments.length - 1];
          String[] tmp=label.split("String_Node_Str");
          String routineName=tmp[0];
          routinesName.add(routineName);
        }
        for (        URL url : routineProvider.getTalendRoutines()) {
          String[] fragments=url.toString().split("String_Node_Str");
          String label=fragments[fragments.length - 1];
          String[] tmp=label.split("String_Node_Str");
          String routineName=tmp[0];
          routinesName.add(routineName);
        }
      }
      Map<String,List<LibraryInfo>> routineAndJars=libUiService.getRoutineAndJars();
      Iterator<Map.Entry<String,List<LibraryInfo>>> iter=routineAndJars.entrySet().iterator();
      while (iter.hasNext()) {
        Map.Entry<String,List<LibraryInfo>> entry=iter.next();
        String routineName=entry.getKey();
        if (!routinesName.contains(routineName)) {
          continue;
        }
        List<LibraryInfo> needJars=entry.getValue();
        for (        LibraryInfo jar : needJars) {
          ModuleNeeded toAdd=new ModuleNeeded("String_Node_Str" + routineName,jar.getLibName(),"String_Node_Str",true);
          String bundleId=jar.getBundleId();
          if (bundleId != null) {
            String bundleName=null;
            String bundleVersion=null;
            if (bundleId.contains("String_Node_Str")) {
              String[] nameAndVersion=bundleId.split("String_Node_Str");
              bundleName=nameAndVersion[0];
              bundleVersion=nameAndVersion[1];
            }
 else {
              bundleName=bundleId;
            }
            toAdd.setBundleName(bundleName);
            toAdd.setBundleVersion(bundleVersion);
          }
          importNeedsList.add(toAdd);
        }
      }
    }
  }
  Set<String> dedupModulesList=new HashSet<String>();
  Iterator<ModuleNeeded> it=importNeedsList.iterator();
  while (it.hasNext()) {
    ModuleNeeded module=it.next();
    if (!module.getModuleName().contains("String_Node_Str")) {
      it.remove();
    }
 else     if (dedupModulesList.contains(module.getModuleName())) {
      it.remove();
    }
 else {
      dedupModulesList.add(module.getModuleName());
    }
  }
  return new ArrayList<ModuleNeeded>(importNeedsList);
}