Program: 123050
Project: 123050
Buggy source:
/** 
 * DOC ycbai Comment method "updateLibrariesAndClasspath".
 * @param process
 * @throws CoreException
 */
private static void updateLibrariesAndClasspath(IProcess process){
  try {
    Set<String> neededLibraries=getNeededLibrariesForProcess(process);
    ILibraryManagerService repositoryBundleService=CorePlugin.getDefault().getRepositoryBundleService();
    File libDir=getJavaProjectLibFolder();
    List<String> jarNamesInLib=new ArrayList<String>();
    File[] jarFiles=libDir.listFiles(FilesUtils.getAcceptJARFilesFilter());
    if (jarFiles != null && jarFiles.length > 0) {
      for (      File file : jarFiles) {
        if (file.isFile()) {
          String fileName=file.getName();
          if (!neededLibraries.contains(fileName)) {
            FilesUtils.removeFile(file);
          }
 else {
            jarNamesInLib.add(file.getName());
          }
        }
      }
    }
    for (    String lib : neededLibraries) {
      if (!jarNamesInLib.contains(lib)) {
        repositoryBundleService.retrieve(lib,libDir.getAbsolutePath());
        jarNamesInLib.add(lib);
      }
    }
    boolean modified=false;
    IClasspathEntry jreClasspathEntry=JavaCore.newContainerEntry(new Path("String_Node_Str"));
    IClasspathEntry classpathEntry=JavaCore.newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));
    IClasspathEntry[] classpathEntryArray=javaProject.getRawClasspath();
    if (!ArrayUtils.contains(classpathEntryArray,jreClasspathEntry)) {
      classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,jreClasspathEntry);
      modified=true;
    }
    if (!ArrayUtils.contains(classpathEntryArray,classpathEntry)) {
      IClasspathEntry source=null;
      for (      IClasspathEntry entry : classpathEntryArray) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
          source=entry;
          break;
        }
      }
      if (source != null) {
        classpathEntryArray=(IClasspathEntry[])ArrayUtils.remove(classpathEntryArray,ArrayUtils.indexOf(classpathEntryArray,source));
      }
      classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,classpathEntry);
      modified=true;
    }
    jarFiles=libDir.listFiles(FilesUtils.getAcceptJARFilesFilter());
    for (    File jarFile : jarFiles) {
      IClasspathEntry newEntry=JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()),null,null);
      if (!ArrayUtils.contains(classpathEntryArray,newEntry)) {
        classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,newEntry);
        modified=true;
      }
    }
    int exchange=2;
    for (    String jar : jarNamesInLib) {
      int index=indexOfEntry(classpathEntryArray,jar);
      if (index < 0) {
        throw new BusinessException("String_Node_Str" + jar);
      }
      if (index >= 0 && index != exchange) {
        IClasspathEntry entry=classpathEntryArray[index];
        IClasspathEntry first=classpathEntryArray[exchange];
        classpathEntryArray[index]=first;
        classpathEntryArray[exchange]=entry;
      }
      exchange++;
    }
    List<IClasspathEntry> classpathEntryList=new ArrayList<IClasspathEntry>(Arrays.asList(classpathEntryArray));
    for (Iterator<IClasspathEntry> iterator=classpathEntryList.iterator(); iterator.hasNext(); ) {
      IClasspathEntry entry=iterator.next();
      if (classpathEntryList.indexOf(entry) > 1) {
        IPath path=entry.getPath();
        if (path != null && !jarNamesInLib.contains(path.lastSegment())) {
          iterator.remove();
          modified=true;
        }
      }
    }
    classpathEntryArray=(IClasspathEntry[])classpathEntryList.toArray(new IClasspathEntry[classpathEntryList.size()]);
    if (modified) {
      javaProject.setRawClasspath(classpathEntryArray,null);
    }
    javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY),null);
  }
 catch (  JavaModelException e) {
    ExceptionHandler.process(e);
  }
catch (  BusinessException e) {
    ExceptionHandler.process(e);
  }
}

Fixed version (ground truth):
/** 
 * DOC ycbai Comment method "updateLibrariesAndClasspath".
 * @param process
 * @throws CoreException
 */
private static void updateLibrariesAndClasspath(IProcess process){
  try {
    Set<String> neededLibraries=getNeededLibrariesForProcess(process);
    ILibraryManagerService repositoryBundleService=CorePlugin.getDefault().getRepositoryBundleService();
    File libDir=getJavaProjectLibFolder();
    List<String> jarNamesInLib=new ArrayList<String>();
    File[] jarFiles=libDir.listFiles(FilesUtils.getAcceptJARFilesFilter());
    if (jarFiles != null && jarFiles.length > 0) {
      for (      File file : jarFiles) {
        if (file.isFile()) {
          String fileName=file.getName();
          if (!neededLibraries.contains(fileName)) {
            FilesUtils.removeFile(file);
          }
 else {
            jarNamesInLib.add(file.getName());
          }
        }
      }
    }
    for (    String lib : neededLibraries) {
      if (!jarNamesInLib.contains(lib)) {
        repositoryBundleService.retrieve(lib,libDir.getAbsolutePath());
        jarNamesInLib.add(lib);
      }
    }
    boolean modified=false;
    IClasspathEntry jreClasspathEntry=JavaCore.newContainerEntry(new Path("String_Node_Str"));
    IClasspathEntry classpathEntry=JavaCore.newSourceEntry(javaProject.getPath().append(JavaUtils.JAVA_SRC_DIRECTORY));
    IClasspathEntry[] classpathEntryArray=javaProject.getRawClasspath();
    if (!ArrayUtils.contains(classpathEntryArray,jreClasspathEntry)) {
      classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,jreClasspathEntry);
      modified=true;
    }
    if (!ArrayUtils.contains(classpathEntryArray,classpathEntry)) {
      IClasspathEntry source=null;
      for (      IClasspathEntry entry : classpathEntryArray) {
        if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
          source=entry;
          break;
        }
      }
      if (source != null) {
        classpathEntryArray=(IClasspathEntry[])ArrayUtils.remove(classpathEntryArray,ArrayUtils.indexOf(classpathEntryArray,source));
      }
      classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,classpathEntry);
      modified=true;
    }
    jarFiles=libDir.listFiles(FilesUtils.getAcceptJARFilesFilter());
    for (    File jarFile : jarFiles) {
      IClasspathEntry newEntry=JavaCore.newLibraryEntry(new Path(jarFile.getAbsolutePath()),null,null);
      if (!ArrayUtils.contains(classpathEntryArray,newEntry)) {
        classpathEntryArray=(IClasspathEntry[])ArrayUtils.add(classpathEntryArray,newEntry);
        modified=true;
      }
    }
    int exchange=2;
    for (    String jar : jarNamesInLib) {
      int index=indexOfEntry(classpathEntryArray,jar);
      if (index < 0) {
        throw new BusinessException("String_Node_Str" + jar);
      }
      if (index >= 0 && index != exchange) {
        IClasspathEntry entry=classpathEntryArray[index];
        IClasspathEntry first=classpathEntryArray[exchange];
        classpathEntryArray[index]=first;
        classpathEntryArray[exchange]=entry;
      }
      exchange++;
    }
    List<IClasspathEntry> classpathEntryList=new ArrayList<IClasspathEntry>(Arrays.asList(classpathEntryArray));
    for (Iterator<IClasspathEntry> iterator=classpathEntryList.iterator(); iterator.hasNext(); ) {
      IClasspathEntry entry=iterator.next();
      if (classpathEntryList.indexOf(entry) > 1) {
        IPath path=entry.getPath();
        if (path != null && !jarNamesInLib.contains(path.lastSegment())) {
          iterator.remove();
          modified=true;
        }
      }
    }
    classpathEntryArray=classpathEntryList.toArray(new IClasspathEntry[classpathEntryList.size()]);
    if (modified) {
      javaProject.setRawClasspath(classpathEntryArray,null);
    }
    javaProject.setOutputLocation(javaProject.getPath().append(JavaUtils.JAVA_CLASSES_DIRECTORY),null);
  }
 catch (  JavaModelException e) {
    ExceptionHandler.process(e);
  }
catch (  BusinessException e) {
    ExceptionHandler.process(e);
  }
}