Program: 22765
Project: 22765
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.featureStack.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.featureStack.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);
  if (minSigma != this.minimumSigma) {
    this.minimumSigma=minSigma;
    featuresChanged=true;
    this.featureStack.setMinimumSigma(minSigma);
  }
  if (maxSigma != this.maximumSigma) {
    this.maximumSigma=maxSigma;
    featuresChanged=true;
    this.featureStack.setMaximumSigma(maxSigma);
  }
  Attribute classAttribute=data.classAttribute();
  Enumeration<String> classValues=classAttribute.enumerateValues();
  loadedClassNames=new ArrayList<String>();
  int j=0;
  while (classValues.hasMoreElements()) {
    final String className=classValues.nextElement().trim();
    loadedClassNames.add(className);
  }
  for (  String className : loadedClassNames) {
    IJ.log("String_Node_Str" + className);
    if (!className.equals(this.classLabels[j])) {
      String currentLabels=classLabels[0];
      for (int i=1; i < numOfClasses; i++)       currentLabels=currentLabels.concat("String_Node_Str" + classLabels[i]);
      String loadedLabels=loadedClassNames.get(0);
      for (int i=1; i < loadedClassNames.size(); i++)       loadedLabels=loadedLabels.concat("String_Node_Str" + loadedClassNames.get(i));
      IJ.error("String_Node_Str" + loadedLabels + "String_Node_Str"+ currentLabels);
      return false;
    }
    j++;
  }
  if (j != numOfClasses) {
    IJ.error("String_Node_Str");
    return false;
  }
  final boolean[] oldEnableFeatures=this.featureStack.getEnableFeatures();
  for (int i=0; i < numFeatures; i++) {
    if (usedFeatures[i] != oldEnableFeatures[i])     featuresChanged=true;
  }
  if (featuresChanged) {
    this.featureStack.setEnableFeatures(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.featureStack.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.featureStack.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) {
    this.minimumSigma=minSigma;
    featuresChanged=true;
    this.featureStack.setMinimumSigma(minSigma);
  }
  if (maxSigma != this.maximumSigma) {
    this.maximumSigma=maxSigma;
    featuresChanged=true;
    this.featureStack.setMaximumSigma(maxSigma);
  }
  Attribute classAttribute=data.classAttribute();
  Enumeration<String> classValues=classAttribute.enumerateValues();
  loadedClassNames=new ArrayList<String>();
  int j=0;
  while (classValues.hasMoreElements()) {
    final String className=classValues.nextElement().trim();
    loadedClassNames.add(className);
  }
  for (  String className : loadedClassNames) {
    IJ.log("String_Node_Str" + className);
    if (!className.equals(this.classLabels[j])) {
      String currentLabels=classLabels[0];
      for (int i=1; i < numOfClasses; i++)       currentLabels=currentLabels.concat("String_Node_Str" + classLabels[i]);
      String loadedLabels=loadedClassNames.get(0);
      for (int i=1; i < loadedClassNames.size(); i++)       loadedLabels=loadedLabels.concat("String_Node_Str" + loadedClassNames.get(i));
      IJ.error("String_Node_Str" + loadedLabels + "String_Node_Str"+ currentLabels);
      return false;
    }
    j++;
  }
  if (j != numOfClasses) {
    IJ.error("String_Node_Str");
    return false;
  }
  final boolean[] oldEnableFeatures=this.featureStack.getEnableFeatures();
  for (int i=0; i < numFeatures; i++) {
    if (usedFeatures[i] != oldEnableFeatures[i])     featuresChanged=true;
  }
  if (featuresChanged) {
    this.featureStack.setEnableFeatures(usedFeatures);
    updateFeatures=true;
  }
  return true;
}