Program: 22781
Project: 22781
Buggy source:
/** 
 * Apply current classifier to image
 * @param testImage test image (2D single image or stack)
 * @return result image (classification)
 */
public ImagePlus applyClassifierToTestImage(final ImagePlus testImage,final int numThreads){
  IJ.log("String_Node_Str" + testImage.getTitle() + "String_Node_Str"+ numThreads+ "String_Node_Str");
  ArrayList<String> classNames=new ArrayList<String>();
  if (null == loadedClassNames) {
    for (int i=0; i < numOfClasses; i++)     if (examples[i].size() > 0)     classNames.add(classLabels[i]);
  }
 else   classNames=loadedClassNames;
  final ImagePlus[] classifiedSlices=new ImagePlus[testImage.getStackSize()];
class ApplyClassifierThread extends Thread {
    final int startSlice;
    final int numSlices;
    final int numFurtherThreads;
    final ArrayList<String> classNames;
    public ApplyClassifierThread(    int startSlice,    int numSlices,    int numFurtherThreads,    ArrayList<String> classNames){
      this.startSlice=startSlice;
      this.numSlices=numSlices;
      this.numFurtherThreads=numFurtherThreads;
      this.classNames=classNames;
    }
    public void run(){
      for (int i=startSlice; i < startSlice + numSlices; i++) {
        final ImagePlus testSlice=new ImagePlus(testImage.getImageStack().getSliceLabel(i),testImage.getImageStack().getProcessor(i).convertToByte(true));
        IJ.showStatus("String_Node_Str");
        IJ.log("String_Node_Str" + i + "String_Node_Str");
        final FeatureStack testImageFeatures=new FeatureStack(testSlice);
        testImageFeatures.setEnableFeatures(featureStack.getEnableFeatures());
        testImageFeatures.updateFeatures();
        final Instances testData=testImageFeatures.createInstances(classNames);
        testData.setClassIndex(testData.numAttributes() - 1);
        final ImagePlus testClassImage=applyClassifier(testData,testSlice.getWidth(),testSlice.getHeight(),numFurtherThreads);
        testClassImage.setTitle("String_Node_Str" + testSlice.getTitle());
        testClassImage.setProcessor(testClassImage.getProcessor().convertToByte(true).duplicate());
        classifiedSlices[i - 1]=testClassImage;
      }
    }
  }
  final int numFurtherThreads=Math.max(1,(numThreads - testImage.getStackSize()) / testImage.getStackSize() + 1);
  final ApplyClassifierThread[] threads=new ApplyClassifierThread[numThreads];
  for (int i=0; i < numThreads; i++) {
    int startSlice=i * testImage.getStackSize() / numThreads + 1;
    int numSlices;
    if (i < numThreads - 1)     numSlices=testImage.getStackSize() / numThreads;
 else     numSlices=testImage.getStackSize() - (numThreads - 1) * (testImage.getStackSize() / numThreads);
    threads[i]=new ApplyClassifierThread(startSlice,numSlices,numFurtherThreads,classNames);
    threads[i].start();
  }
  final ImageStack classified=new ImageStack(testImage.getWidth(),testImage.getHeight());
  for (  Thread thread : threads)   try {
    thread.join();
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
  for (int i=0; i < testImage.getStackSize(); i++)   classified.addSlice(classifiedSlices[i].getTitle(),classifiedSlices[i].getProcessor());
  return new ImagePlus("String_Node_Str",classified);
}

Fixed version (ground truth):
/** 
 * Apply current classifier to image
 * @param testImage test image (2D single image or stack)
 * @return result image (classification)
 */
public ImagePlus applyClassifierToTestImage(final ImagePlus testImage,final int numThreads){
  IJ.log("String_Node_Str" + testImage.getTitle() + "String_Node_Str"+ numThreads+ "String_Node_Str");
  ArrayList<String> classNames=new ArrayList<String>();
  if (null == loadedClassNames) {
    for (int i=0; i < numOfClasses; i++)     if (examples[i].size() > 0)     classNames.add(classLabels[i]);
  }
 else   classNames=loadedClassNames;
  final ImagePlus[] classifiedSlices=new ImagePlus[testImage.getStackSize()];
class ApplyClassifierThread extends Thread {
    final int startSlice;
    final int numSlices;
    final int numFurtherThreads;
    final ArrayList<String> classNames;
    public ApplyClassifierThread(    int startSlice,    int numSlices,    int numFurtherThreads,    ArrayList<String> classNames){
      this.startSlice=startSlice;
      this.numSlices=numSlices;
      this.numFurtherThreads=numFurtherThreads;
      this.classNames=classNames;
    }
    public void run(){
      for (int i=startSlice; i < startSlice + numSlices; i++) {
        final ImagePlus testSlice=new ImagePlus(testImage.getImageStack().getSliceLabel(i),testImage.getImageStack().getProcessor(i).convertToByte(true));
        IJ.showStatus("String_Node_Str");
        IJ.log("String_Node_Str" + i + "String_Node_Str");
        final FeatureStack testImageFeatures=new FeatureStack(testSlice);
        testImageFeatures.setEnableFeatures(featureStack.getEnableFeatures());
        testImageFeatures.updateFeatures();
        final Instances testData=testImageFeatures.createInstances(classNames);
        testData.setClassIndex(testData.numAttributes() - 1);
        final ImagePlus testClassImage=applyClassifier(testData,testSlice.getWidth(),testSlice.getHeight(),numFurtherThreads);
        testClassImage.setTitle("String_Node_Str" + testSlice.getTitle());
        testClassImage.setProcessor(testClassImage.getProcessor().convertToByte(true).duplicate());
        classifiedSlices[i - 1]=testClassImage;
      }
    }
  }
  final int numFurtherThreads=Math.max(1,(numThreads - testImage.getStackSize()) / testImage.getStackSize() + 1);
  final ApplyClassifierThread[] threads=new ApplyClassifierThread[numThreads];
  int numSlices=testImage.getStackSize() / numThreads;
  for (int i=0; i < numThreads; i++) {
    int startSlice=i * numSlices + 1;
    if (i == numThreads - 1)     numSlices=testImage.getStackSize() - (numThreads - 1) * (testImage.getStackSize() / numThreads);
    IJ.log("String_Node_Str" + i + "String_Node_Str"+ numSlices+ "String_Node_Str"+ startSlice);
    threads[i]=new ApplyClassifierThread(startSlice,numSlices,numFurtherThreads,classNames);
    threads[i].start();
  }
  final ImageStack classified=new ImageStack(testImage.getWidth(),testImage.getHeight());
  for (  Thread thread : threads)   try {
    thread.join();
  }
 catch (  InterruptedException e) {
    e.printStackTrace();
  }
  for (int i=0; i < testImage.getStackSize(); i++)   classified.addSlice(classifiedSlices[i].getTitle(),classifiedSlices[i].getProcessor());
  return new ImagePlus("String_Node_Str",classified);
}