Program: 22715
Project: 22715
Buggy source:
/** 
 * Adjust current segmentation state (attributes and classes) to loaded data
 * @param data loaded instances
 * @return false if error
 */
public boolean adjustSegmentationStateToData(Instances data){
  boolean featuresChanged=false;
  Enumeration<Attribute> attributes=data.enumerateAttributes();
  final int numFeatures=FeatureStack.availableFeatures.length;
  boolean[] usedFeatures=new boolean[numFeatures];
  this.featureNames=new ArrayList<String>();
  float minSigma=Float.MAX_VALUE;
  float maxSigma=Float.MIN_VALUE;
  while (attributes.hasMoreElements()) {
    final Attribute a=attributes.nextElement();
    this.featureNames.add(a.name());
    for (int i=0; i < numFeatures; i++) {
      if (a.name().startsWith(FeatureStack.availableFeatures[i])) {
        usedFeatures[i]=true;
        if (i == FeatureStack.MEMBRANE) {
          int index=a.name().indexOf("String_Node_Str") + 4;
          int index2=a.name().indexOf("String_Node_Str",index + 1);
          final int patchSize=Integer.parseInt(a.name().substring(index,index2));
          if (patchSize != membranePatchSize) {
            membranePatchSize=patchSize;
            this.featureStackArray.setMembranePatchSize(patchSize);
            featuresChanged=true;
          }
          index=a.name().lastIndexOf("String_Node_Str");
          final int thickness=Integer.parseInt(a.name().substring(index + 1));
          if (thickness != membraneThickness) {
            membraneThickness=thickness;
            this.featureStackArray.setMembraneSize(thickness);
            featuresChanged=true;
          }
        }
 else         if (i < FeatureStack.ANISOTROPIC_DIFFUSION) {
          String[] tokens=a.name().split("String_Node_Str");
          for (int j=0; j < tokens.length; j++)           if (tokens[j].indexOf("String_Node_Str") != -1) {
            final float sigma=Float.parseFloat(tokens[j]);
            if (sigma < minSigma)             minSigma=sigma;
            if (sigma > maxSigma)             maxSigma=sigma;
          }
        }
      }
    }
  }
  IJ.log("String_Node_Str" + maxSigma + "String_Node_Str"+ minSigma);
  IJ.log("String_Node_Str" + membraneThickness + "String_Node_Str"+ membranePatchSize);
  if (minSigma != this.minimumSigma && minSigma != 0) {
    this.minimumSigma=minSigma;
    featuresChanged=true;
    this.featureStackArray.setMinimumSigma(minSigma);
  }
  if (maxSigma != this.maximumSigma) {
    this.maximumSigma=maxSigma;
    featuresChanged=true;
    this.featureStackArray.setMaximumSigma(maxSigma);
  }
  Attribute classAttribute=data.classAttribute();
  Enumeration<String> classValues=classAttribute.enumerateValues();
  loadedClassNames=new ArrayList<String>();
  int j=0;
  setNumOfClasses(0);
  while (classValues.hasMoreElements()) {
    final String className=classValues.nextElement().trim();
    loadedClassNames.add(className);
  }
  for (  String className : loadedClassNames) {
    IJ.log("String_Node_Str" + className);
    setClassLabel(j,className);
    addClass();
    j++;
  }
  final boolean[] oldEnableFeatures=this.featureStackArray.getEnabledFeatures();
  for (int i=0; i < numFeatures; i++) {
    if (usedFeatures[i] != oldEnableFeatures[i])     featuresChanged=true;
  }
  if (featuresChanged) {
    this.setEnabledFeatures(usedFeatures);
    updateFeatures=true;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Adjust current segmentation state (attributes and classes) to loaded data
 * @param data loaded instances
 * @return false if error
 */
public boolean adjustSegmentationStateToData(Instances data){
  boolean featuresChanged=false;
  Enumeration<Attribute> attributes=data.enumerateAttributes();
  final int numFeatures=FeatureStack.availableFeatures.length;
  boolean[] usedFeatures=new boolean[numFeatures];
  this.featureNames=new ArrayList<String>();
  float minSigma=Float.MAX_VALUE;
  float maxSigma=Float.MIN_VALUE;
  while (attributes.hasMoreElements()) {
    final Attribute a=attributes.nextElement();
    this.featureNames.add(a.name());
    for (int i=0; i < numFeatures; i++) {
      if (a.name().startsWith(FeatureStack.availableFeatures[i])) {
        usedFeatures[i]=true;
        if (i == FeatureStack.MEMBRANE) {
          int index=a.name().indexOf("String_Node_Str") + 4;
          int index2=a.name().indexOf("String_Node_Str",index + 1);
          final int patchSize=Integer.parseInt(a.name().substring(index,index2));
          if (patchSize != membranePatchSize) {
            membranePatchSize=patchSize;
            this.featureStackArray.setMembranePatchSize(patchSize);
            featuresChanged=true;
          }
          index=a.name().lastIndexOf("String_Node_Str");
          final int thickness=Integer.parseInt(a.name().substring(index + 1));
          if (thickness != membraneThickness) {
            membraneThickness=thickness;
            this.featureStackArray.setMembraneSize(thickness);
            featuresChanged=true;
          }
        }
 else         if (i < FeatureStack.ANISOTROPIC_DIFFUSION) {
          String[] tokens=a.name().split("String_Node_Str");
          for (int j=0; j < tokens.length; j++)           if (tokens[j].indexOf("String_Node_Str") != -1) {
            final float sigma=Float.parseFloat(tokens[j]);
            if (sigma < minSigma)             minSigma=sigma;
            if (sigma > maxSigma)             maxSigma=sigma;
          }
        }
 else {
          String[] tokens=a.name().split("String_Node_Str");
          final float sigma=Float.parseFloat(tokens[3]);
          if (sigma < minSigma)           minSigma=sigma;
          if (sigma > maxSigma)           maxSigma=sigma;
        }
      }
    }
  }
  IJ.log("String_Node_Str" + maxSigma + "String_Node_Str"+ minSigma);
  IJ.log("String_Node_Str" + membraneThickness + "String_Node_Str"+ membranePatchSize);
  if (minSigma != this.minimumSigma && minSigma != 0) {
    this.minimumSigma=minSigma;
    featuresChanged=true;
    this.featureStackArray.setMinimumSigma(minSigma);
  }
  if (maxSigma != this.maximumSigma) {
    this.maximumSigma=maxSigma;
    featuresChanged=true;
    this.featureStackArray.setMaximumSigma(maxSigma);
  }
  Attribute classAttribute=data.classAttribute();
  Enumeration<String> classValues=classAttribute.enumerateValues();
  loadedClassNames=new ArrayList<String>();
  int j=0;
  setNumOfClasses(0);
  while (classValues.hasMoreElements()) {
    final String className=classValues.nextElement().trim();
    loadedClassNames.add(className);
  }
  for (  String className : loadedClassNames) {
    IJ.log("String_Node_Str" + className);
    setClassLabel(j,className);
    addClass();
    j++;
  }
  final boolean[] oldEnableFeatures=this.featureStackArray.getEnabledFeatures();
  for (int i=0; i < numFeatures; i++) {
    if (usedFeatures[i] != oldEnableFeatures[i])     featuresChanged=true;
  }
  if (featuresChanged) {
    this.setEnabledFeatures(usedFeatures);
    updateFeatures=true;
  }
  return true;
}