Program: 124281
Project: 124281
Buggy source:
private static void sortClasspath(Set<String> jobModuleList,IProcess process) throws CoreException, BusinessException {
  IClasspathEntry[] entries=javaProject.getRawClasspath();
  IClasspathEntry jreClasspathEntry=JavaCore.newContainerEntry(new Path("String_Node_Str"));
  IClasspathEntry classpathEntry=JavaCore.newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));
  boolean changesDone=false;
  if (!ArrayUtils.contains(entries,jreClasspathEntry)) {
    entries=(IClasspathEntry[])ArrayUtils.add(entries,jreClasspathEntry);
    changesDone=true;
  }
  if (!ArrayUtils.contains(entries,classpathEntry)) {
    IClasspathEntry source=null;
    for (    IClasspathEntry entry : entries) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        source=entry;
        break;
      }
    }
    if (source != null) {
      entries=(IClasspathEntry[])ArrayUtils.remove(entries,ArrayUtils.indexOf(entries,source));
    }
    entries=(IClasspathEntry[])ArrayUtils.add(entries,classpathEntry);
    changesDone=true;
  }
  Set<String> listModulesReallyNeeded=jobModuleList;
  if (listModulesReallyNeeded == null) {
    listModulesReallyNeeded=new HashSet<String>();
  }
 else {
    if (process != null && process instanceof IProcess2 && ((IProcess2)process).getProperty() != null && ((IProcess2)process).getProperty().getItem() instanceof ProcessItem) {
      List<ModuleNeeded> modulesNeededs=ModulesNeededProvider.getModulesNeededForRoutines((ProcessItem)((IProcess2)process).getProperty().getItem());
      for (      ModuleNeeded moduleNeeded : modulesNeededs) {
        listModulesReallyNeeded.add(moduleNeeded.getModuleName());
      }
    }
 else {
      for (      ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeededForRoutines()) {
        listModulesReallyNeeded.add(moduleNeeded.getModuleName());
      }
    }
  }
  File libDir=getJavaProjectLibFolder();
  if ((libDir != null) && (libDir.isDirectory())) {
    Set<String> jarsNeedRetrieve=new HashSet<String>(listModulesReallyNeeded);
    for (    File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
      jarsNeedRetrieve.remove(externalLib.getName());
    }
    if (!jarsNeedRetrieve.isEmpty()) {
      ILibraryManagerService repositoryBundleService=CorePlugin.getDefault().getRepositoryBundleService();
      repositoryBundleService.retrieve(jarsNeedRetrieve,libDir.getAbsolutePath());
    }
    for (    File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
      if (externalLib.isFile() && listModulesReallyNeeded.contains(externalLib.getName())) {
        IClasspathEntry newEntry=JavaCore.newLibraryEntry(new Path(externalLib.getAbsolutePath()),null,null);
        if (!ArrayUtils.contains(entries,newEntry)) {
          entries=(IClasspathEntry[])ArrayUtils.add(entries,newEntry);
          changesDone=true;
        }
      }
    }
  }
  String missingJars=null;
  int exchange=2;
  for (  String jar : listModulesReallyNeeded) {
    int index=indexOfEntry(entries,jar);
    if (index < 0) {
      if (missingJars == null) {
        missingJars="String_Node_Str" + jar;
      }
 else {
        missingJars=missingJars + "String_Node_Str" + jar;
      }
    }
    if (index >= 0 && index != exchange) {
      IClasspathEntry entry=entries[index];
      IClasspathEntry first=entries[exchange];
      entries[index]=first;
      entries[exchange]=entry;
      changesDone=true;
      exchange++;
    }
  }
  if (changesDone) {
    javaProject.setRawClasspath(entries,null);
    javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY),null);
  }
  if (missingJars != null) {
    throw new BusinessException(missingJars);
  }
}

Fixed version (ground truth):
private static void sortClasspath(Set<String> jobModuleList,IProcess process) throws CoreException, BusinessException {
  IClasspathEntry[] entries=javaProject.getRawClasspath();
  IClasspathEntry jreClasspathEntry=JavaCore.newContainerEntry(new Path("String_Node_Str"));
  IClasspathEntry classpathEntry=JavaCore.newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));
  boolean changesDone=false;
  if (!ArrayUtils.contains(entries,jreClasspathEntry)) {
    entries=(IClasspathEntry[])ArrayUtils.add(entries,jreClasspathEntry);
    changesDone=true;
  }
  if (!ArrayUtils.contains(entries,classpathEntry)) {
    IClasspathEntry source=null;
    for (    IClasspathEntry entry : entries) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
        source=entry;
        break;
      }
    }
    if (source != null) {
      entries=(IClasspathEntry[])ArrayUtils.remove(entries,ArrayUtils.indexOf(entries,source));
    }
    entries=(IClasspathEntry[])ArrayUtils.add(entries,classpathEntry);
    changesDone=true;
  }
  Set<String> listModulesReallyNeeded=jobModuleList;
  if (listModulesReallyNeeded == null) {
    listModulesReallyNeeded=new HashSet<String>();
  }
 else {
    if (process != null && process instanceof IProcess2 && ((IProcess2)process).getProperty() != null && ((IProcess2)process).getProperty().getItem() instanceof ProcessItem) {
      List<ModuleNeeded> modulesNeededs=ModulesNeededProvider.getModulesNeededForRoutines((ProcessItem)((IProcess2)process).getProperty().getItem());
      for (      ModuleNeeded moduleNeeded : modulesNeededs) {
        listModulesReallyNeeded.add(moduleNeeded.getModuleName());
      }
    }
 else {
      for (      ModuleNeeded moduleNeeded : ModulesNeededProvider.getModulesNeededForRoutines()) {
        listModulesReallyNeeded.add(moduleNeeded.getModuleName());
      }
    }
  }
  File libDir=getJavaProjectLibFolder();
  if ((libDir != null) && (libDir.isDirectory())) {
    Set<String> jarsNeedRetrieve=new HashSet<String>(listModulesReallyNeeded);
    for (    File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
      jarsNeedRetrieve.remove(externalLib.getName());
    }
    List<IClasspathEntry> entriesToRemove=new ArrayList<IClasspathEntry>();
    for (    IClasspathEntry entry : entries) {
      if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
        boolean found=false;
        for (        File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
          if (entry.getPath().toPortableString().endsWith(externalLib.getName())) {
            found=true;
            break;
          }
        }
        if (!found) {
          entriesToRemove.add(entry);
        }
      }
    }
    for (    IClasspathEntry entry : entriesToRemove) {
      entries=(IClasspathEntry[])ArrayUtils.remove(entries,ArrayUtils.indexOf(entries,entry));
      changesDone=true;
    }
    if (!jarsNeedRetrieve.isEmpty()) {
      ILibraryManagerService repositoryBundleService=CorePlugin.getDefault().getRepositoryBundleService();
      repositoryBundleService.retrieve(jarsNeedRetrieve,libDir.getAbsolutePath());
    }
    for (    File externalLib : libDir.listFiles(FilesUtils.getAcceptJARFilesFilter())) {
      if (externalLib.isFile() && listModulesReallyNeeded.contains(externalLib.getName())) {
        IClasspathEntry newEntry=JavaCore.newLibraryEntry(new Path(externalLib.getAbsolutePath()),null,null);
        if (!ArrayUtils.contains(entries,newEntry)) {
          entries=(IClasspathEntry[])ArrayUtils.add(entries,newEntry);
          changesDone=true;
        }
      }
    }
  }
  String missingJars=null;
  int exchange=2;
  for (  String jar : listModulesReallyNeeded) {
    int index=indexOfEntry(entries,jar);
    if (index < 0) {
      if (missingJars == null) {
        missingJars="String_Node_Str" + jar;
      }
 else {
        missingJars=missingJars + "String_Node_Str" + jar;
      }
    }
    if (index >= 0 && index != exchange) {
      IClasspathEntry entry=entries[index];
      IClasspathEntry first=entries[exchange];
      entries[index]=first;
      entries[exchange]=entry;
      changesDone=true;
      exchange++;
    }
  }
  if (changesDone) {
    javaProject.setRawClasspath(entries,null);
    javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY),null);
  }
  if (missingJars != null) {
    throw new BusinessException(missingJars);
  }
}