Program: 121174
Project: 121174
Buggy source:
protected void checkRoutineDependencies(){
  if (routinesDependencies == null) {
    routinesDependencies=new ArrayList<RoutinesParameterType>();
  }
  try {
    List<String> possibleRoutines=new ArrayList<String>();
    List<String> routinesToAdd=new ArrayList<String>();
    String additionalString=LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "String_Node_Str" : "String_Node_Str";
    List<String> routinesAlreadySetup=new ArrayList<String>();
    for (    RoutinesParameterType routine : routinesDependencies) {
      routinesAlreadySetup.add(routine.getName());
    }
    IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
    List<IRepositoryViewObject> routines=factory.getAll(ProjectManager.getInstance().getCurrentProject(),ERepositoryObjectType.ROUTINES);
    routines.addAll(factory.getAll(ProjectManager.getInstance().getCurrentProject(),ERepositoryObjectType.PIG_UDF));
    for (    Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
      List<IRepositoryViewObject> refRoutines=factory.getAll(project,ERepositoryObjectType.ROUTINES);
      refRoutines.addAll(factory.getAll(project,ERepositoryObjectType.PIG_UDF));
      for (      IRepositoryViewObject object : refRoutines) {
        if (!((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
          if (!possibleRoutines.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
            possibleRoutines.add(object.getLabel());
            routines.add(object);
          }
        }
      }
    }
    for (    IRepositoryViewObject object : routines) {
      if (((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
        if (routinesDependencies.isEmpty()) {
          routinesToAdd.add(object.getLabel());
        }
 else         if (!routinesAlreadySetup.contains(object.getLabel())) {
          routinesToAdd.add(object.getLabel());
        }
      }
 else       if (!routinesAlreadySetup.contains(object.getLabel())) {
        possibleRoutines.add(object.getLabel());
      }
    }
    for (    Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
      List<IRepositoryViewObject> refRoutines=factory.getAll(project,ERepositoryObjectType.ROUTINES);
      refRoutines.addAll(factory.getAll(project,ERepositoryObjectType.PIG_UDF));
      for (      IRepositoryViewObject object : refRoutines) {
        if (!((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
          if (!possibleRoutines.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
            possibleRoutines.add(object.getLabel());
            routines.add(object);
          }
        }
      }
    }
    for (    IElementParameter param : (List<IElementParameter>)getElementParametersWithChildrens()) {
      for (      String routine : possibleRoutines) {
        if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && ((String)param.getValue()).contains(routine + additionalString)) {
          routinesToAdd.add(routine);
        }
        checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
      }
    }
    for (    INode node : ((List<INode>)getGraphicalNodes())) {
      if (node.isExternalNode()) {
        IExternalNode eNode=node.getExternalNode();
        List<String> needToadd=eNode.checkNeededRoutines(possibleRoutines,additionalString);
        if (needToadd != null) {
          routinesToAdd.addAll(needToadd);
        }
      }
      for (      IElementParameter param : (List<IElementParameter>)node.getElementParametersWithChildrens()) {
        for (        String routine : possibleRoutines) {
          if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && ((String)param.getValue()).contains(routine + additionalString)) {
            routinesToAdd.add(routine);
          }
          checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
        }
      }
      for (      IConnection connection : ((List<IConnection>)node.getOutgoingSortedConnections())) {
        for (        IElementParameter param : (List<IElementParameter>)connection.getElementParametersWithChildrens()) {
          for (          String routine : possibleRoutines) {
            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && ((String)param.getValue()).contains(routine + additionalString)) {
              routinesToAdd.add(routine);
            }
            checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
          }
        }
      }
    }
    for (    IRepositoryViewObject object : routines) {
      if (routinesToAdd.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
        RoutinesParameterType routinesParameterType=TalendFileFactory.eINSTANCE.createRoutinesParameterType();
        routinesParameterType.setId(object.getId());
        routinesParameterType.setName(object.getLabel());
        routinesDependencies.add(routinesParameterType);
      }
    }
  }
 catch (  PersistenceException e) {
    ExceptionHandler.process(e);
  }
}

Fixed version (ground truth):
protected void checkRoutineDependencies(){
  if (routinesDependencies == null) {
    routinesDependencies=new ArrayList<RoutinesParameterType>();
  }
  try {
    List<String> possibleRoutines=new ArrayList<String>();
    List<String> routinesToAdd=new ArrayList<String>();
    String additionalString=LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA ? "String_Node_Str" : "String_Node_Str";
    List<String> routinesAlreadySetup=new ArrayList<String>();
    for (    RoutinesParameterType routine : routinesDependencies) {
      routinesAlreadySetup.add(routine.getName());
    }
    IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
    List<IRepositoryViewObject> routines=factory.getAll(ProjectManager.getInstance().getCurrentProject(),ERepositoryObjectType.ROUTINES);
    routines.addAll(factory.getAll(ProjectManager.getInstance().getCurrentProject(),ERepositoryObjectType.PIG_UDF));
    for (    Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
      List<IRepositoryViewObject> refRoutines=factory.getAll(project,ERepositoryObjectType.ROUTINES);
      refRoutines.addAll(factory.getAll(project,ERepositoryObjectType.PIG_UDF));
      for (      IRepositoryViewObject object : refRoutines) {
        if (!((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
          if (!possibleRoutines.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
            possibleRoutines.add(object.getLabel());
            routines.add(object);
          }
        }
      }
    }
    for (    IRepositoryViewObject object : routines) {
      if (((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
        if (routinesDependencies.isEmpty()) {
          routinesToAdd.add(object.getLabel());
        }
 else         if (!routinesAlreadySetup.contains(object.getLabel())) {
          routinesToAdd.add(object.getLabel());
        }
      }
 else       if (!routinesAlreadySetup.contains(object.getLabel())) {
        possibleRoutines.add(object.getLabel());
      }
    }
    for (    Project project : ProjectManager.getInstance().getAllReferencedProjects()) {
      List<IRepositoryViewObject> refRoutines=factory.getAll(project,ERepositoryObjectType.ROUTINES);
      refRoutines.addAll(factory.getAll(project,ERepositoryObjectType.PIG_UDF));
      for (      IRepositoryViewObject object : refRoutines) {
        if (!((RoutineItem)object.getProperty().getItem()).isBuiltIn()) {
          if (!possibleRoutines.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
            possibleRoutines.add(object.getLabel());
            routines.add(object);
          }
        }
      }
    }
    for (    IElementParameter param : (List<IElementParameter>)getElementParametersWithChildrens()) {
      for (      String routine : possibleRoutines) {
        if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && ((String)param.getValue()).contains(routine + additionalString)) {
          routinesToAdd.add(routine);
        }
        checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
      }
    }
    for (    INode node : ((List<INode>)getGraphicalNodes())) {
      if (node.isExternalNode()) {
        IExternalNode eNode=node.getExternalNode();
        List<String> needToadd=eNode.checkNeededRoutines(possibleRoutines,additionalString);
        if (needToadd != null) {
          routinesToAdd.addAll(needToadd);
        }
      }
      for (      IElementParameter param : (List<IElementParameter>)node.getElementParametersWithChildrens()) {
        for (        String routine : possibleRoutines) {
          if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && (((String)param.getValue()).contains(routine + additionalString) || ((String)param.getValue()).contains(SOURCE_JAVA_PIGUDF + additionalString + routine))) {
            routinesToAdd.add(routine);
          }
          checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
        }
      }
      for (      IConnection connection : ((List<IConnection>)node.getOutgoingSortedConnections())) {
        for (        IElementParameter param : (List<IElementParameter>)connection.getElementParametersWithChildrens()) {
          for (          String routine : possibleRoutines) {
            if (!routinesToAdd.contains(routine) && param.getValue() != null && param.getValue() instanceof String && ((String)param.getValue()).contains(routine + additionalString)) {
              routinesToAdd.add(routine);
            }
            checkRoutinesInTable(routinesToAdd,additionalString,param,routine);
          }
        }
      }
    }
    for (    IRepositoryViewObject object : routines) {
      if (routinesToAdd.contains(object.getLabel()) && !routinesAlreadySetup.contains(object.getLabel())) {
        RoutinesParameterType routinesParameterType=TalendFileFactory.eINSTANCE.createRoutinesParameterType();
        routinesParameterType.setId(object.getId());
        routinesParameterType.setName(object.getLabel());
        routinesDependencies.add(routinesParameterType);
      }
    }
  }
 catch (  PersistenceException e) {
    ExceptionHandler.process(e);
  }
}