Program: 22704
Project: 22704
Buggy source:
/** 
 * Apply classifier to test data. As it is implemented right now,  it will use one thread per input image and slice. 
 */
public void applyClassifierToTestData(){
  File[] imageFiles;
  String storeDir="String_Node_Str";
  String dir=OpenDialog.getLastDirectory();
  if (null == dir)   dir=OpenDialog.getDefaultDirectory();
  JFileChooser fileChooser=new JFileChooser(dir);
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setMultiSelectionEnabled(true);
  int returnVal=fileChooser.showOpenDialog(null);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    imageFiles=fileChooser.getSelectedFiles();
    OpenDialog.setLastDirectory(imageFiles[0].getParent());
  }
 else {
    return;
  }
  boolean showResults=true;
  boolean storeResults=false;
  if (imageFiles.length >= 3) {
    int decision=JOptionPane.showConfirmDialog(null,"String_Node_Str" + "String_Node_Str","String_Node_Str",JOptionPane.YES_NO_OPTION);
    if (decision == JOptionPane.YES_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      fileChooser.setMultiSelectionEnabled(false);
      returnVal=fileChooser.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        storeDir=fileChooser.getSelectedFile().getPath();
      }
 else {
        return;
      }
      showResults=false;
      storeResults=true;
    }
  }
  final boolean probabilityMaps;
  int decision=JOptionPane.showConfirmDialog(null,"String_Node_Str","String_Node_Str",JOptionPane.YES_NO_OPTION);
  if (decision == JOptionPane.YES_OPTION)   probabilityMaps=true;
 else   probabilityMaps=false;
  final int numProcessors=Prefs.getThreads();
  final int numThreads=Math.min(imageFiles.length,numProcessors);
  final int numFurtherThreads=(int)Math.ceil((double)(numProcessors - numThreads) / imageFiles.length) + 1;
  IJ.log("String_Node_Str" + imageFiles.length + "String_Node_Str"+ numThreads+ "String_Node_Str");
  win.setButtonsEnabled(false);
  Thread[] threads=new Thread[numThreads];
class ImageProcessingThread extends Thread {
    private final int numThread;
    private final int numThreads;
    private final File[] imageFiles;
    private final boolean storeResults;
    private final boolean showResults;
    private final String storeDir;
    public ImageProcessingThread(    int numThread,    int numThreads,    File[] imageFiles,    boolean storeResults,    boolean showResults,    String storeDir){
      this.numThread=numThread;
      this.numThreads=numThreads;
      this.imageFiles=imageFiles;
      this.storeResults=storeResults;
      this.showResults=showResults;
      this.storeDir=storeDir;
    }
    public void run(){
      for (int i=numThread; i < imageFiles.length; i+=numThreads) {
        File file=imageFiles[i];
        ImagePlus testImage=IJ.openImage(file.getPath());
        if (null == testImage) {
          IJ.log("String_Node_Str" + file.getPath() + "String_Node_Str");
          IJ.error("String_Node_Str","String_Node_Str" + file.getPath() + "String_Node_Str");
          return;
        }
        IJ.log("String_Node_Str" + file.getName() + "String_Node_Str"+ numThread);
        ImagePlus segmentation=wekaSegmentation.applyClassifier(testImage,numFurtherThreads,probabilityMaps);
        if (showResults && null != segmentation) {
          if (!probabilityMaps) {
            convertTo8bitNoScaling(segmentation);
            segmentation.getProcessor().setColorModel(overlayLUT);
            segmentation.getImageStack().setColorModel(overlayLUT);
            segmentation.updateAndDraw();
          }
          segmentation.show();
          testImage.show();
        }
        if (storeResults) {
          String filename=storeDir + File.separator + file.getName();
          IJ.log("String_Node_Str" + filename);
          IJ.save(segmentation,filename);
          segmentation.close();
          testImage.close();
        }
      }
    }
  }
  for (int i=0; i < numThreads; i++) {
    threads[i]=new ImageProcessingThread(i,numThreads,imageFiles,storeResults,showResults,storeDir);
    String[] arg=new String[]{imageFiles[i].getParent(),imageFiles[i].getName(),"String_Node_Str" + showResults,"String_Node_Str" + storeResults,"String_Node_Str" + probabilityMaps,storeDir};
    record(APPLY_CLASSIFIER,arg);
    threads[i].start();
  }
  for (  Thread thread : threads) {
    try {
      thread.join();
    }
 catch (    InterruptedException e) {
    }
  }
  win.updateButtonsEnabling();
}

Fixed version (ground truth):
/** 
 * Apply classifier to test data. As it is implemented right now,  it will use one thread per input image and slice. 
 */
public void applyClassifierToTestData(){
  File[] imageFiles;
  String storeDir="String_Node_Str";
  String dir=OpenDialog.getLastDirectory();
  if (null == dir)   dir=OpenDialog.getDefaultDirectory();
  JFileChooser fileChooser=new JFileChooser(dir);
  fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
  fileChooser.setMultiSelectionEnabled(true);
  int returnVal=fileChooser.showOpenDialog(null);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
    imageFiles=fileChooser.getSelectedFiles();
    OpenDialog.setLastDirectory(imageFiles[0].getParent());
  }
 else {
    return;
  }
  boolean showResults=true;
  boolean storeResults=false;
  if (imageFiles.length >= 3) {
    int decision=JOptionPane.showConfirmDialog(null,"String_Node_Str" + "String_Node_Str","String_Node_Str",JOptionPane.YES_NO_OPTION);
    if (decision == JOptionPane.YES_OPTION) {
      fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      fileChooser.setMultiSelectionEnabled(false);
      returnVal=fileChooser.showOpenDialog(null);
      if (returnVal == JFileChooser.APPROVE_OPTION) {
        storeDir=fileChooser.getSelectedFile().getPath();
      }
 else {
        return;
      }
      showResults=false;
      storeResults=true;
    }
  }
  final boolean probabilityMaps;
  int decision=JOptionPane.showConfirmDialog(null,"String_Node_Str","String_Node_Str",JOptionPane.YES_NO_OPTION);
  if (decision == JOptionPane.YES_OPTION)   probabilityMaps=true;
 else   probabilityMaps=false;
  final int numProcessors=Prefs.getThreads();
  final int numThreads=Math.min(imageFiles.length,numProcessors);
  final int numFurtherThreads=(int)Math.ceil((double)(numProcessors - numThreads) / imageFiles.length) + 1;
  IJ.log("String_Node_Str" + imageFiles.length + "String_Node_Str"+ numThreads+ "String_Node_Str");
  win.setButtonsEnabled(false);
  Thread[] threads=new Thread[numThreads];
class ImageProcessingThread extends Thread {
    private final int numThread;
    private final int numThreads;
    private final File[] imageFiles;
    private final boolean storeResults;
    private final boolean showResults;
    private final String storeDir;
    public ImageProcessingThread(    int numThread,    int numThreads,    File[] imageFiles,    boolean storeResults,    boolean showResults,    String storeDir){
      this.numThread=numThread;
      this.numThreads=numThreads;
      this.imageFiles=imageFiles;
      this.storeResults=storeResults;
      this.showResults=showResults;
      this.storeDir=storeDir;
    }
    public void run(){
      for (int i=numThread; i < imageFiles.length; i+=numThreads) {
        File file=imageFiles[i];
        ImagePlus testImage=IJ.openImage(file.getPath());
        if (null == testImage) {
          IJ.log("String_Node_Str" + file.getPath() + "String_Node_Str");
          IJ.error("String_Node_Str","String_Node_Str" + file.getPath() + "String_Node_Str");
          return;
        }
        IJ.log("String_Node_Str" + file.getName() + "String_Node_Str"+ numThread);
        final ImagePlus segmentation=wekaSegmentation.applyClassifier(testImage,numFurtherThreads,probabilityMaps);
        if (null == segmentation) {
          IJ.log("String_Node_Str" + file.getName() + "String_Node_Str"+ "String_Node_Str");
          return;
        }
        if (!probabilityMaps) {
          convertTo8bitNoScaling(segmentation);
          segmentation.getProcessor().setColorModel(overlayLUT);
          segmentation.getImageStack().setColorModel(overlayLUT);
          segmentation.updateAndDraw();
        }
        if (showResults) {
          segmentation.show();
          testImage.show();
        }
 else         if (storeResults) {
          String filename=storeDir + File.separator + file.getName();
          IJ.log("String_Node_Str" + filename);
          IJ.save(segmentation,filename);
          segmentation.close();
          testImage.close();
        }
      }
    }
  }
  for (int i=0; i < numThreads; i++) {
    threads[i]=new ImageProcessingThread(i,numThreads,imageFiles,storeResults,showResults,storeDir);
    String[] arg=new String[]{imageFiles[i].getParent(),imageFiles[i].getName(),"String_Node_Str" + showResults,"String_Node_Str" + storeResults,"String_Node_Str" + probabilityMaps,storeDir};
    record(APPLY_CLASSIFIER,arg);
    threads[i].start();
  }
  for (  Thread thread : threads) {
    try {
      thread.join();
    }
 catch (    InterruptedException e) {
    }
  }
  win.updateButtonsEnabling();
}