Program: 22780
Project: 22780
Buggy source:
/** 
 * Create multi-channel probability distribution image from image
 * @param testImage test image (2D single image or stack)
 * @param numThreads number of threads to be used
 * @return result image (probability distribution)
 */
public ImagePlus createProbImgFromTestData(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 int numFurtherThreads=Math.max(1,(numThreads - testImage.getStackSize()) / testImage.getStackSize() + 1);
  final ImagePlus[] probSlices=new ImagePlus[testImage.getStackSize() * numOfClasses];
class ProbImageThread extends Thread {
    final int startSlice;
    final int numSlices;
    final int numFurtherThreads;
    final ArrayList<String> classNames;
    public ProbImageThread(    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[] testClassImages=getClassifierDistribution(testData,testSlice.getWidth(),testSlice.getHeight(),numFurtherThreads);
        for (int c=0; c < numOfClasses; c++)         probSlices[(i - 1) * numOfClasses + c]=testClassImages[c];
      }
    }
  }
  final ProbImageThread[] threads=new ProbImageThread[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 ProbImageThread(startSlice,numSlices,numFurtherThreads,classNames);
    threads[i].start();
  }
  final ImageStack probStack=new ImageStack(testImage.getWidth(),testImage.getHeight());
  for (  Thread thread : threads) {
    try {
      thread.join();
    }
 catch (    InterruptedException e) {
    }
  }
  for (int i=0; i < testImage.getStackSize() * numOfClasses; i++)   probStack.addSlice(probSlices[i].getTitle(),probSlices[i].getProcessor().convertToByte(true).duplicate());
  ImagePlus probImage=new ImagePlus("String_Node_Str",probStack);
  probImage.setDimensions(numOfClasses,testImage.getNSlices(),testImage.getNFrames());
  probImage.setOpenAsHyperStack(true);
  return probImage;
}

Fixed version (ground truth):
/** 
 * Create multi-channel probability distribution image from image
 * @param testImage test image (2D single image or stack)
 * @param numThreads number of threads to be used
 * @return result image (probability distribution)
 */
public ImagePlus createProbImgFromTestData(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 int numFurtherThreads=Math.max(1,(numThreads - testImage.getStackSize()) / testImage.getStackSize() + 1);
  final ImagePlus[] probSlices=new ImagePlus[testImage.getStackSize() * numOfClasses];
class ProbImageThread extends Thread {
    final int startSlice;
    final int numSlices;
    final int numFurtherThreads;
    final ArrayList<String> classNames;
    public ProbImageThread(    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[] testClassImages=getClassifierDistribution(testData,testSlice.getWidth(),testSlice.getHeight(),numFurtherThreads);
        for (int c=0; c < numOfClasses; c++)         probSlices[(i - 1) * numOfClasses + c]=testClassImages[c];
      }
    }
  }
  final ProbImageThread[] threads=new ProbImageThread[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 ProbImageThread(startSlice,numSlices,numFurtherThreads,classNames);
    threads[i].start();
  }
  final ImageStack probStack=new ImageStack(testImage.getWidth(),testImage.getHeight());
  for (  Thread thread : threads) {
    try {
      thread.join();
    }
 catch (    InterruptedException e) {
    }
  }
  for (int i=0; i < testImage.getStackSize() * numOfClasses; i++)   probStack.addSlice(probSlices[i].getTitle(),probSlices[i].getProcessor().convertToByte(true).duplicate());
  ImagePlus probImage=new ImagePlus("String_Node_Str",probStack);
  probImage.setDimensions(numOfClasses,testImage.getNSlices(),testImage.getNFrames());
  probImage.setOpenAsHyperStack(true);
  return probImage;
}