Program: 22756
Project: 22756
Buggy source:
/** 
 * Apply current classifier to set of instances
 * @param data set of instances
 * @param w image width
 * @param h image height
 * @param numThreads The number of threads to use. Set to zero forauto-detection.
 * @return result image
 */
public ImagePlus applyClassifier(final Instances data,int w,int h,int numThreads,boolean probabilityMaps){
  if (numThreads == 0)   numThreads=Runtime.getRuntime().availableProcessors();
  final int numClasses=data.numClasses();
  final int numInstances=data.numInstances();
  final int numChannels=(probabilityMaps ? numClasses : 1);
  final int numSlices=(numChannels * numInstances) / (w * h);
  IJ.showStatus("String_Node_Str");
  final long start=System.currentTimeMillis();
  exe=Executors.newFixedThreadPool(numThreads);
  final double[][][] results=new double[numThreads][][];
  final Instances[] partialData=new Instances[numThreads];
  final int partialSize=numInstances / numThreads;
  Future<double[][]> fu[]=new Future[numThreads];
  final AtomicInteger counter=new AtomicInteger();
  for (int i=0; i < numThreads; i++) {
    if (Thread.currentThread().isInterrupted())     return null;
    if (i == numThreads - 1)     partialData[i]=new Instances(data,i * partialSize,numInstances - i * partialSize);
 else     partialData[i]=new Instances(data,i * partialSize,partialSize);
    fu[i]=exe.submit(classifyInstances(partialData[i],classifier,counter,probabilityMaps));
  }
  ScheduledExecutorService monitor=Executors.newScheduledThreadPool(1);
  ScheduledFuture task=monitor.scheduleWithFixedDelay(new Runnable(){
    public void run(){
      IJ.showProgress(counter.get(),numInstances);
    }
  }
,0,1,TimeUnit.SECONDS);
  for (int i=0; i < numThreads; i++) {
    try {
      results[i]=fu[i].get();
    }
 catch (    InterruptedException e) {
      return null;
    }
catch (    ExecutionException e) {
      e.printStackTrace();
      return null;
    }
 finally {
      exe.shutdown();
      task.cancel(true);
      monitor.shutdownNow();
      IJ.showProgress(1);
    }
  }
  exe.shutdown();
  double[][] classificationResult;
  classificationResult=new double[numChannels][numInstances];
  for (int i=0; i < numThreads; i++)   for (int c=0; c < numChannels; c++)   System.arraycopy(results[i][c],0,classificationResult[c],i * partialSize,results[i][c].length);
  IJ.showProgress(1.0);
  final long end=System.currentTimeMillis();
  IJ.log("String_Node_Str" + (end - start) + "String_Node_Str");
  double[] classifiedSlice=new double[w * h];
  final ImageStack classStack=new ImageStack(w,h);
  for (int i=0; i < numSlices / numChannels; i++) {
    for (int c=0; c < numChannels; c++) {
      System.arraycopy(classificationResult[c],i * (w * h),classifiedSlice,0,w * h);
      ImageProcessor classifiedSliceProcessor=new FloatProcessor(w,h,classifiedSlice);
      classStack.addSlice(probabilityMaps ? classLabels[c] : "String_Node_Str",classifiedSliceProcessor);
    }
  }
  ImagePlus classImg=new ImagePlus(probabilityMaps ? "String_Node_Str" : "String_Node_Str",classStack);
  return classImg;
}

Fixed version (ground truth):
/** 
 * Apply current classifier to set of instances
 * @param data set of instances
 * @param w image width
 * @param h image height
 * @param numThreads The number of threads to use. Set to zero forauto-detection.
 * @return result image
 */
public ImagePlus applyClassifier(final Instances data,int w,int h,int numThreads,boolean probabilityMaps){
  if (numThreads == 0)   numThreads=Runtime.getRuntime().availableProcessors();
  final int numClasses=data.numClasses();
  final int numInstances=data.numInstances();
  final int numChannels=(probabilityMaps ? numClasses : 1);
  final int numSlices=(numChannels * numInstances) / (w * h);
  IJ.showStatus("String_Node_Str");
  final long start=System.currentTimeMillis();
  exe=Executors.newFixedThreadPool(numThreads);
  final double[][][] results=new double[numThreads][][];
  final Instances[] partialData=new Instances[numThreads];
  final int partialSize=numInstances / numThreads;
  Future<double[][]> fu[]=new Future[numThreads];
  final AtomicInteger counter=new AtomicInteger();
  for (int i=0; i < numThreads; i++) {
    if (Thread.currentThread().isInterrupted())     return null;
    if (i == numThreads - 1)     partialData[i]=new Instances(data,i * partialSize,numInstances - i * partialSize);
 else     partialData[i]=new Instances(data,i * partialSize,partialSize);
    AbstractClassifier classifierCopy=null;
    try {
      classifierCopy=(AbstractClassifier)(AbstractClassifier.makeCopy(classifier));
    }
 catch (    Exception e) {
      IJ.log("String_Node_Str");
      e.printStackTrace();
    }
    fu[i]=exe.submit(classifyInstances(partialData[i],classifierCopy,counter,probabilityMaps));
  }
  ScheduledExecutorService monitor=Executors.newScheduledThreadPool(1);
  ScheduledFuture task=monitor.scheduleWithFixedDelay(new Runnable(){
    public void run(){
      IJ.showProgress(counter.get(),numInstances);
    }
  }
,0,1,TimeUnit.SECONDS);
  for (int i=0; i < numThreads; i++) {
    try {
      results[i]=fu[i].get();
    }
 catch (    InterruptedException e) {
      return null;
    }
catch (    ExecutionException e) {
      e.printStackTrace();
      return null;
    }
 finally {
      exe.shutdown();
      task.cancel(true);
      monitor.shutdownNow();
      IJ.showProgress(1);
    }
  }
  exe.shutdown();
  double[][] classificationResult;
  classificationResult=new double[numChannels][numInstances];
  for (int i=0; i < numThreads; i++)   for (int c=0; c < numChannels; c++)   System.arraycopy(results[i][c],0,classificationResult[c],i * partialSize,results[i][c].length);
  IJ.showProgress(1.0);
  final long end=System.currentTimeMillis();
  IJ.log("String_Node_Str" + (end - start) + "String_Node_Str");
  double[] classifiedSlice=new double[w * h];
  final ImageStack classStack=new ImageStack(w,h);
  for (int i=0; i < numSlices / numChannels; i++) {
    for (int c=0; c < numChannels; c++) {
      System.arraycopy(classificationResult[c],i * (w * h),classifiedSlice,0,w * h);
      ImageProcessor classifiedSliceProcessor=new FloatProcessor(w,h,classifiedSlice);
      classStack.addSlice(probabilityMaps ? classLabels[c] : "String_Node_Str",classifiedSliceProcessor);
    }
  }
  ImagePlus classImg=new ImagePlus(probabilityMaps ? "String_Node_Str" : "String_Node_Str",classStack);
  return classImg;
}