Program: 149531
Project: 149531
Buggy source:
private void run(){
  long start=System.currentTimeMillis();
  Utils.setShowProgress(false);
  Utils.setShowStatus(false);
  JLabel statusLine=Utils.getStatusLine();
  progressBar=Utils.getProgressBar();
  ExecutorService executor=Executors.newFixedThreadPool(getThreads());
  TurboList<Future<?>> futures=new TurboList<Future<?>>(nThreads);
  TurboList<ImageWorker> workers=new TurboList<ImageWorker>(nThreads);
  double[][][] data=new double[subDirs.size()][2][];
  double[] pixelOffset=null, pixelVariance=null;
  Statistics statsOffset=null, statsVariance=null;
  final int nSubDirs=subDirs.size();
  boolean error=false;
  int width=0, height=0;
  for (int n=0; n < nSubDirs; n++) {
    SubDir sd=subDirs.getf(n);
    statusLine.setText("String_Node_Str" + sd.name);
    SeriesImageSource source=new SeriesImageSource(sd.name,sd.path.getPath());
    if (!source.open()) {
      error=true;
      IJ.error(TITLE,"String_Node_Str" + sd.path.getPath());
      break;
    }
    if (n == 0) {
      width=source.getWidth();
      height=source.getHeight();
    }
 else {
      if (width != source.getWidth() || height != source.getHeight()) {
        error=true;
        IJ.error(TITLE,"String_Node_Str" + sd.path.getPath());
        break;
      }
    }
    totalProgress=source.getFrames() + 1;
    stepProgress=Utils.getProgressInterval(totalProgress);
    progress=0;
    progressBar.show(0);
    ArrayMoment moment=(rollingAlgorithm) ? new RollingArrayMoment() : new SimpleArrayMoment();
    final BlockingQueue<ImageJob> jobs=new ArrayBlockingQueue<ImageJob>(nThreads * 2);
    for (int i=0; i < nThreads; i++) {
      final ImageWorker worker=new ImageWorker(jobs,moment);
      workers.add(worker);
      futures.add(executor.submit(worker));
    }
    for (float[] pixels=source.next(); pixels != null; pixels=source.next()) {
      put(jobs,new ImageJob(pixels));
    }
    for (int i=0; i < nThreads; i++) {
      put(jobs,new ImageJob(null));
    }
    for (int t=futures.size(); t-- > 0; ) {
      try {
        futures.get(t).get();
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    for (    ImageWorker w : workers)     moment.add(w.moment);
    data[n][0]=moment.getFirstMoment();
    data[n][1]=moment.getVariance();
    futures.clear();
    workers.clear();
    Statistics s=new Statistics(data[n][0]);
    if (n != 0) {
      Statistics signal=new Statistics();
      double[] mean=data[n][0];
      for (int i=0; i < pixelOffset.length; i++)       signal.add(mean[i] - pixelOffset[i]);
      Utils.log("String_Node_Str",sd.name,Utils.rounded(s.getMean()),Utils.rounded(s.getStandardDeviation()),Utils.rounded(signal.getMean()),Utils.rounded(signal.getStandardDeviation()));
      ImageStack stack=new ImageStack(source.getWidth(),source.getHeight());
      stack.addSlice("String_Node_Str",SimpleArrayUtils.toFloat(data[n][0]));
      stack.addSlice("String_Node_Str",SimpleArrayUtils.toFloat(data[n][1]));
      IJ.save(new ImagePlus("String_Node_Str",stack),new File(directory,"String_Node_Str" + sd.name + "String_Node_Str").getPath());
    }
 else {
      pixelOffset=data[0][0];
      pixelVariance=data[0][1];
      statsOffset=s;
      statsVariance=new Statistics(pixelVariance);
      Utils.log("String_Node_Str",sd.name,Utils.rounded(s.getMean()),Utils.rounded(s.getStandardDeviation()),Utils.rounded(statsVariance.getMean()),Utils.rounded(statsVariance.getStandardDeviation()));
    }
  }
  Utils.setShowStatus(true);
  Utils.setShowProgress(true);
  IJ.showProgress(1);
  executor.shutdown();
  if (error)   return;
  statusLine.setText("String_Node_Str");
  double[] pixelGain=new double[pixelOffset.length];
  for (int i=0; i < pixelGain.length; i++) {
    double bibiT=0;
    double biaiT=0;
    for (int n=1; n < nSubDirs; n++) {
      double bi=data[n][0][i] - pixelOffset[i];
      double ai=data[n][1][i] - pixelVariance[i];
      bibiT+=bi * bi;
      biaiT+=bi * ai;
    }
    pixelGain[i]=biaiT / bibiT;
  }
  Statistics statsGain=new Statistics(pixelGain);
  Utils.log("String_Node_Str",Utils.rounded(statsGain.getMean()),Utils.rounded(statsGain.getStandardDeviation()));
  int bins=Utils.getBinsSturges(pixelGain.length);
  WindowOrganiser wo=new WindowOrganiser();
  showHistogram("String_Node_Str",pixelOffset,bins,statsOffset,wo);
  showHistogram("String_Node_Str",pixelVariance,bins,statsVariance,wo);
  showHistogram("String_Node_Str",pixelGain,bins,statsGain,wo);
  wo.tile();
  float[] bias=SimpleArrayUtils.toFloat(pixelOffset);
  float[] variance=SimpleArrayUtils.toFloat(pixelVariance);
  float[] gain=SimpleArrayUtils.toFloat(pixelGain);
  measuredStack=new ImageStack(width,height);
  measuredStack.addSlice("String_Node_Str",bias);
  measuredStack.addSlice("String_Node_Str",variance);
  measuredStack.addSlice("String_Node_Str",gain);
  ExtendedGenericDialog egd=new ExtendedGenericDialog(TITLE);
  egd.addMessage("String_Node_Str");
  if (modelDirectory == null) {
    modelDirectory=directory;
    modelName="String_Node_Str";
  }
  egd.addStringField("String_Node_Str",modelName);
  egd.addDirectoryField("String_Node_Str",modelDirectory);
  egd.showDialog();
  if (!egd.wasCanceled()) {
    modelName=egd.getNextString();
    modelDirectory=egd.getNextString();
    PerPixelCameraModel cameraModel=new PerPixelCameraModel(width,height,bias,gain,variance);
    if (!CameraModelManager.save(cameraModel,new File(directory,modelName).getPath()))     IJ.error(TITLE,"String_Node_Str");
  }
  IJ.showStatus("String_Node_Str");
  Utils.log("String_Node_Str" + Utils.timeToString(System.currentTimeMillis() - start));
}

Fixed version (ground truth):
private void run(){
  long start=System.currentTimeMillis();
  Utils.setShowProgress(false);
  Utils.setShowStatus(false);
  JLabel statusLine=Utils.getStatusLine();
  progressBar=Utils.getProgressBar();
  ExecutorService executor=Executors.newFixedThreadPool(getThreads());
  TurboList<Future<?>> futures=new TurboList<Future<?>>(nThreads);
  TurboList<ImageWorker> workers=new TurboList<ImageWorker>(nThreads);
  double[][][] data=new double[subDirs.size()][2][];
  double[] pixelOffset=null, pixelVariance=null;
  Statistics statsOffset=null, statsVariance=null;
  final int nSubDirs=subDirs.size();
  boolean error=false;
  int width=0, height=0;
  for (int n=0; n < nSubDirs; n++) {
    SubDir sd=subDirs.getf(n);
    statusLine.setText("String_Node_Str" + sd.name);
    SeriesImageSource source=new SeriesImageSource(sd.name,sd.path.getPath());
    if (!source.open()) {
      error=true;
      IJ.error(TITLE,"String_Node_Str" + sd.path.getPath());
      break;
    }
    if (n == 0) {
      width=source.getWidth();
      height=source.getHeight();
    }
 else {
      if (width != source.getWidth() || height != source.getHeight()) {
        error=true;
        IJ.error(TITLE,"String_Node_Str" + sd.path.getPath());
        break;
      }
    }
    totalProgress=source.getFrames() + 1;
    stepProgress=Utils.getProgressInterval(totalProgress);
    progress=0;
    progressBar.show(0);
    ArrayMoment moment=(rollingAlgorithm) ? new RollingArrayMoment() : new SimpleArrayMoment();
    final BlockingQueue<ImageJob> jobs=new ArrayBlockingQueue<ImageJob>(nThreads * 2);
    for (int i=0; i < nThreads; i++) {
      final ImageWorker worker=new ImageWorker(jobs,moment);
      workers.add(worker);
      futures.add(executor.submit(worker));
    }
    for (float[] pixels=source.next(); pixels != null; pixels=source.next()) {
      put(jobs,new ImageJob(pixels));
    }
    for (int i=0; i < nThreads; i++) {
      put(jobs,new ImageJob(null));
    }
    for (int t=futures.size(); t-- > 0; ) {
      try {
        futures.get(t).get();
      }
 catch (      Exception e) {
        e.printStackTrace();
      }
    }
    for (    ImageWorker w : workers)     moment.add(w.moment);
    data[n][0]=moment.getFirstMoment();
    data[n][1]=moment.getVariance();
    futures.clear();
    workers.clear();
    Statistics s=new Statistics(data[n][0]);
    if (n != 0) {
      Statistics signal=new Statistics();
      double[] mean=data[n][0];
      for (int i=0; i < pixelOffset.length; i++)       signal.add(mean[i] - pixelOffset[i]);
      Utils.log("String_Node_Str",sd.name,Utils.rounded(s.getMean()),Utils.rounded(s.getStandardDeviation()),Utils.rounded(signal.getMean()),Utils.rounded(signal.getStandardDeviation()));
      ImageStack stack=new ImageStack(source.getWidth(),source.getHeight());
      stack.addSlice("String_Node_Str",SimpleArrayUtils.toFloat(data[n][0]));
      stack.addSlice("String_Node_Str",SimpleArrayUtils.toFloat(data[n][1]));
      IJ.save(new ImagePlus("String_Node_Str",stack),new File(directory,"String_Node_Str" + sd.name + "String_Node_Str").getPath());
    }
 else {
      pixelOffset=data[0][0];
      pixelVariance=data[0][1];
      statsOffset=s;
      statsVariance=new Statistics(pixelVariance);
      Utils.log("String_Node_Str",sd.name,Utils.rounded(s.getMean()),Utils.rounded(s.getStandardDeviation()),Utils.rounded(statsVariance.getMean()),Utils.rounded(statsVariance.getStandardDeviation()));
    }
  }
  Utils.setShowStatus(true);
  Utils.setShowProgress(true);
  IJ.showProgress(1);
  executor.shutdown();
  if (error)   return;
  statusLine.setText("String_Node_Str");
  double[] pixelGain=new double[pixelOffset.length];
  for (int i=0; i < pixelGain.length; i++) {
    double bibiT=0;
    double biaiT=0;
    for (int n=1; n < nSubDirs; n++) {
      double bi=data[n][0][i] - pixelOffset[i];
      double ai=data[n][1][i] - pixelVariance[i];
      bibiT+=bi * bi;
      biaiT+=bi * ai;
    }
    pixelGain[i]=biaiT / bibiT;
  }
  Statistics statsGain=new Statistics(pixelGain);
  Utils.log("String_Node_Str",Utils.rounded(statsGain.getMean()),Utils.rounded(statsGain.getStandardDeviation()));
  int bins=Utils.getBinsSturges(pixelGain.length);
  WindowOrganiser wo=new WindowOrganiser();
  showHistogram("String_Node_Str",pixelOffset,bins,statsOffset,wo);
  showHistogram("String_Node_Str",pixelVariance,bins,statsVariance,wo);
  showHistogram("String_Node_Str",pixelGain,bins,statsGain,wo);
  wo.tile();
  float[] bias=SimpleArrayUtils.toFloat(pixelOffset);
  float[] variance=SimpleArrayUtils.toFloat(pixelVariance);
  float[] gain=SimpleArrayUtils.toFloat(pixelGain);
  measuredStack=new ImageStack(width,height);
  measuredStack.addSlice("String_Node_Str",bias);
  measuredStack.addSlice("String_Node_Str",variance);
  measuredStack.addSlice("String_Node_Str",gain);
  ExtendedGenericDialog egd=new ExtendedGenericDialog(TITLE);
  egd.addMessage("String_Node_Str");
  if (modelDirectory == null) {
    modelDirectory=directory;
    modelName="String_Node_Str";
  }
  egd.addStringField("String_Node_Str",modelName,30);
  egd.addDirectoryField("String_Node_Str",modelDirectory);
  egd.showDialog();
  if (!egd.wasCanceled()) {
    modelName=egd.getNextString();
    modelDirectory=egd.getNextString();
    PerPixelCameraModel cameraModel=new PerPixelCameraModel(width,height,bias,gain,variance);
    if (!CameraModelManager.save(cameraModel,new File(directory,modelName).getPath()))     IJ.error(TITLE,"String_Node_Str");
  }
  IJ.showStatus("String_Node_Str");
  Utils.log("String_Node_Str" + Utils.timeToString(System.currentTimeMillis() - start));
}