Program: 149583
Project: 149583
Buggy source:
/** 
 * Show a dialog to configure the fit solver. The updated settings are saved to the settings file. An error message is shown if the dialog is cancelled or the configuration is invalid.
 * @param settings
 * @param filename
 * @param extraOptions True if extra configuration options should be allowed
 * @return True if the configuration succeeded
 */
public static boolean configureFitSolver(GlobalSettings settings,String filename,boolean extraOptions){
  FitConfiguration fitConfig=settings.getFitEngineConfiguration().getFitConfiguration();
  Calibration calibration=settings.getCalibration();
  if (fitConfig.getFitSolver() == FitSolver.MLE) {
    GenericDialog gd=new GenericDialog(TITLE);
    gd.addMessage("String_Node_Str");
    gd.addNumericField("String_Node_Str",calibration.bias,2);
    gd.addCheckbox("String_Node_Str",fitConfig.isModelCamera());
    gd.addNumericField("String_Node_Str",calibration.readNoise,2);
    gd.addNumericField("String_Node_Str",calibration.gain,2);
    gd.addCheckbox("String_Node_Str",calibration.emCCD);
    String[] searchNames=SettingsManager.getNames((Object[])MaximumLikelihoodFitter.SearchMethod.values());
    gd.addChoice("String_Node_Str",searchNames,searchNames[fitConfig.getSearchMethod().ordinal()]);
    gd.addStringField("String_Node_Str","String_Node_Str" + fitConfig.getRelativeThreshold());
    gd.addStringField("String_Node_Str","String_Node_Str" + fitConfig.getAbsoluteThreshold());
    gd.addNumericField("String_Node_Str",fitConfig.getMaxIterations(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getMaxFunctionEvaluations(),0);
    if (extraOptions)     gd.addCheckbox("String_Node_Str",fitConfig.isGradientLineMinimisation());
    gd.showDialog();
    if (gd.wasCanceled())     return false;
    calibration.bias=Math.abs(gd.getNextNumber());
    fitConfig.setModelCamera(gd.getNextBoolean());
    calibration.readNoise=Math.abs(gd.getNextNumber());
    calibration.gain=Math.abs(gd.getNextNumber());
    calibration.emCCD=gd.getNextBoolean();
    fitConfig.setBias(calibration.bias);
    fitConfig.setReadNoise(calibration.readNoise);
    fitConfig.setGain(calibration.gain);
    fitConfig.setEmCCD(calibration.emCCD);
    fitConfig.setSearchMethod(gd.getNextChoiceIndex());
    try {
      fitConfig.setRelativeThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
      fitConfig.setAbsoluteThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
    }
 catch (    NumberFormatException e) {
      fitConfig.setRelativeThreshold(0);
      fitConfig.setAbsoluteThreshold(0);
    }
    fitConfig.setMaxIterations((int)gd.getNextNumber());
    fitConfig.setMaxFunctionEvaluations((int)gd.getNextNumber());
    if (extraOptions)     fitConfig.setGradientLineMinimisation(gd.getNextBoolean());
 else     fitConfig.setGradientLineMinimisation(false);
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
    try {
      Parameters.isAboveZero("String_Node_Str",fitConfig.getRelativeThreshold());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getAbsoluteThreshold());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxIterations());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxFunctionEvaluations());
    }
 catch (    IllegalArgumentException e) {
      IJ.error(TITLE,e.getMessage());
      return false;
    }
  }
 else   if (fitConfig.getFitSolver() == FitSolver.LVM || fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
    GenericDialog gd=new GenericDialog(TITLE);
    gd.addMessage("String_Node_Str");
    String[] criteriaNames=SettingsManager.getNames((Object[])FitCriteria.values());
    gd.addChoice("String_Node_Str",criteriaNames,criteriaNames[fitConfig.getFitCriteria().ordinal()]);
    gd.addNumericField("String_Node_Str",fitConfig.getSignificantDigits(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getDelta(),4);
    gd.addNumericField("String_Node_Str",fitConfig.getLambda(),4);
    if (extraOptions)     gd.addNumericField("String_Node_Str",fitConfig.getMinIterations(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getMaxIterations(),0);
    if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
      gd.addMessage("String_Node_Str");
      gd.addNumericField("String_Node_Str",calibration.readNoise,2);
      gd.addNumericField("String_Node_Str",calibration.bias,2);
    }
    gd.showDialog();
    if (gd.wasCanceled())     return false;
    fitConfig.setFitCriteria(gd.getNextChoiceIndex());
    fitConfig.setSignificantDigits((int)gd.getNextNumber());
    fitConfig.setDelta(gd.getNextNumber());
    fitConfig.setLambda(gd.getNextNumber());
    if (extraOptions)     fitConfig.setMinIterations((int)gd.getNextNumber());
    fitConfig.setMaxIterations((int)gd.getNextNumber());
    if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
      calibration.readNoise=Math.abs(gd.getNextNumber());
      calibration.bias=Math.abs(gd.getNextNumber());
      fitConfig.setNoiseModel(CameraNoiseModel.createNoiseModel(calibration.readNoise,calibration.bias,calibration.emCCD));
    }
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
    try {
      Parameters.isAboveZero("String_Node_Str",fitConfig.getSignificantDigits());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getDelta());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getLambda());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxIterations());
    }
 catch (    IllegalArgumentException e) {
      IJ.error(TITLE,e.getMessage());
      return false;
    }
  }
 else   if (fitConfig.getFitSolver() == FitSolver.LVM_QUASI_NEWTON) {
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Show a dialog to configure the fit solver. The updated settings are saved to the settings file. An error message is shown if the dialog is cancelled or the configuration is invalid.
 * @param settings
 * @param filename
 * @param extraOptions True if extra configuration options should be allowed
 * @return True if the configuration succeeded
 */
public static boolean configureFitSolver(GlobalSettings settings,String filename,boolean extraOptions){
  FitConfiguration fitConfig=settings.getFitEngineConfiguration().getFitConfiguration();
  Calibration calibration=settings.getCalibration();
  if (fitConfig.getFitSolver() == FitSolver.MLE) {
    GenericDialog gd=new GenericDialog(TITLE);
    gd.addMessage("String_Node_Str");
    gd.addNumericField("String_Node_Str",calibration.bias,2);
    gd.addCheckbox("String_Node_Str",fitConfig.isModelCamera());
    gd.addNumericField("String_Node_Str",calibration.readNoise,2);
    gd.addNumericField("String_Node_Str",calibration.gain,2);
    gd.addCheckbox("String_Node_Str",calibration.emCCD);
    String[] searchNames=SettingsManager.getNames((Object[])MaximumLikelihoodFitter.SearchMethod.values());
    gd.addChoice("String_Node_Str",searchNames,searchNames[fitConfig.getSearchMethod().ordinal()]);
    gd.addStringField("String_Node_Str","String_Node_Str" + fitConfig.getRelativeThreshold());
    gd.addStringField("String_Node_Str","String_Node_Str" + fitConfig.getAbsoluteThreshold());
    gd.addNumericField("String_Node_Str",fitConfig.getMaxIterations(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getMaxFunctionEvaluations(),0);
    if (extraOptions)     gd.addCheckbox("String_Node_Str",fitConfig.isGradientLineMinimisation());
    gd.showDialog();
    if (gd.wasCanceled())     return false;
    calibration.bias=Math.abs(gd.getNextNumber());
    fitConfig.setModelCamera(gd.getNextBoolean());
    calibration.readNoise=Math.abs(gd.getNextNumber());
    calibration.gain=Math.abs(gd.getNextNumber());
    calibration.emCCD=gd.getNextBoolean();
    fitConfig.setBias(calibration.bias);
    fitConfig.setReadNoise(calibration.readNoise);
    fitConfig.setGain(calibration.gain);
    fitConfig.setEmCCD(calibration.emCCD);
    fitConfig.setSearchMethod(gd.getNextChoiceIndex());
    try {
      fitConfig.setRelativeThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
      fitConfig.setAbsoluteThreshold(Math.abs(Double.parseDouble(gd.getNextString())));
    }
 catch (    NumberFormatException e) {
      fitConfig.setRelativeThreshold(0);
      fitConfig.setAbsoluteThreshold(0);
    }
    fitConfig.setMaxIterations((int)gd.getNextNumber());
    fitConfig.setMaxFunctionEvaluations((int)gd.getNextNumber());
    if (extraOptions)     fitConfig.setGradientLineMinimisation(gd.getNextBoolean());
 else     fitConfig.setGradientLineMinimisation(false);
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
    try {
      Parameters.isAboveZero("String_Node_Str",fitConfig.getRelativeThreshold());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getAbsoluteThreshold());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxIterations());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxFunctionEvaluations());
      fitConfig.getFunctionSolver();
    }
 catch (    IllegalArgumentException e) {
      IJ.error(TITLE,e.getMessage());
      return false;
    }
  }
 else   if (fitConfig.getFitSolver() == FitSolver.LVM || fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
    GenericDialog gd=new GenericDialog(TITLE);
    gd.addMessage("String_Node_Str");
    String[] criteriaNames=SettingsManager.getNames((Object[])FitCriteria.values());
    gd.addChoice("String_Node_Str",criteriaNames,criteriaNames[fitConfig.getFitCriteria().ordinal()]);
    gd.addNumericField("String_Node_Str",fitConfig.getSignificantDigits(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getDelta(),4);
    gd.addNumericField("String_Node_Str",fitConfig.getLambda(),4);
    if (extraOptions)     gd.addNumericField("String_Node_Str",fitConfig.getMinIterations(),0);
    gd.addNumericField("String_Node_Str",fitConfig.getMaxIterations(),0);
    if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
      gd.addMessage("String_Node_Str");
      gd.addNumericField("String_Node_Str",calibration.readNoise,2);
      gd.addNumericField("String_Node_Str",calibration.bias,2);
    }
    gd.showDialog();
    if (gd.wasCanceled())     return false;
    fitConfig.setFitCriteria(gd.getNextChoiceIndex());
    fitConfig.setSignificantDigits((int)gd.getNextNumber());
    fitConfig.setDelta(gd.getNextNumber());
    fitConfig.setLambda(gd.getNextNumber());
    if (extraOptions)     fitConfig.setMinIterations((int)gd.getNextNumber());
    fitConfig.setMaxIterations((int)gd.getNextNumber());
    if (fitConfig.getFitSolver() == FitSolver.LVM_WEIGHTED) {
      calibration.readNoise=Math.abs(gd.getNextNumber());
      calibration.bias=Math.abs(gd.getNextNumber());
      fitConfig.setNoiseModel(CameraNoiseModel.createNoiseModel(calibration.readNoise,calibration.bias,calibration.emCCD));
    }
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
    try {
      Parameters.isAboveZero("String_Node_Str",fitConfig.getSignificantDigits());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getDelta());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getLambda());
      Parameters.isAboveZero("String_Node_Str",fitConfig.getMaxIterations());
    }
 catch (    IllegalArgumentException e) {
      IJ.error(TITLE,e.getMessage());
      return false;
    }
  }
 else   if (fitConfig.getFitSolver() == FitSolver.LVM_QUASI_NEWTON) {
    if (filename != null)     SettingsManager.saveSettings(settings,filename);
  }
  return true;
}