Program: 22702
Project: 22702
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 String[] availableFeatures=isProcessing3D ? FeatureStack3D.availableFeatures : FeatureStack.availableFeatures;
  final int numFeatures=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(availableFeatures[i])) {
        usedFeatures[i]=true;
        String[] tokens;
        float sigma;
        if (!isProcessing3D) {
switch (i) {
case 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;
        if (null != featureStackArray)         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;
  if (null != featureStackArray)   featureStackArray.setMembraneSize(thickness);
  featuresChanged=true;
}
break;
case FeatureStack.KUWAHARA:
tokens=a.name().split("String_Node_Str");
membranePatchSize=Integer.parseInt(tokens[1]);
break;
case FeatureStack.NEIGHBORS:
case FeatureStack.ENTROPY:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[1]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.STRUCTURE:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[2]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.ANISOTROPIC_DIFFUSION:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[3]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.BILATERAL:
case FeatureStack.LIPSCHITZ:
break;
default :
tokens=a.name().split("String_Node_Str");
for (int j=0; j < tokens.length; j++) if (tokens[j].indexOf("String_Node_Str") != -1) {
sigma=Float.parseFloat(tokens[j]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
}
}
}
 else {
switch (i) {
case FeatureStack3D.STRUCTURE:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[2]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
default :
tokens=a.name().split("String_Node_Str");
for (int j=0; j < tokens.length; j++) if (tokens[j].indexOf("String_Node_Str") != -1) {
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 (!isProcessing3D) IJ.log("String_Node_Str" + membraneThickness + "String_Node_Str"+ membranePatchSize);
if (minSigma != this.minimumSigma && minSigma != 0) {
this.minimumSigma=minSigma;
featuresChanged=true;
if (null != featureStackArray) featureStackArray.setMinimumSigma(minSigma);
if (isProcessing3D) this.fs3d.setMinimumSigma(minSigma);
}
if (maxSigma != this.maximumSigma) {
this.maximumSigma=maxSigma;
featuresChanged=true;
if (null != featureStackArray) featureStackArray.setMaximumSigma(maxSigma);
if (isProcessing3D) this.fs3d.setMaximumSigma(maxSigma);
}
Attribute classAttribute=data.classAttribute();
Enumeration<Object> classValues=classAttribute.enumerateValues();
loadedClassNames=new ArrayList<String>();
int j=0;
setNumOfClasses(0);
while (classValues.hasMoreElements()) {
final String className=((String)classValues.nextElement()).trim();
loadedClassNames.add(className);
}
for (String className : loadedClassNames) {
IJ.log("String_Node_Str" + className);
setClassLabel(j,className);
addClass();
j++;
}
if (null != featureStackArray) {
final boolean[] oldEnableFeatures=isProcessing3D ? fs3d.getEnabledFeatures() : this.featureStackArray.getEnabledFeatures();
for (int i=0; i < numFeatures; i++) {
if (usedFeatures[i] != oldEnableFeatures[i]) featuresChanged=true;
}
}
 else 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 String[] availableFeatures=isProcessing3D ? FeatureStack3D.availableFeatures : FeatureStack.availableFeatures;
  final int numFeatures=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(availableFeatures[i])) {
        usedFeatures[i]=true;
        String[] tokens;
        float sigma;
        if (!isProcessing3D) {
switch (i) {
case 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;
        if (null != featureStackArray)         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;
  if (null != featureStackArray)   featureStackArray.setMembraneSize(thickness);
  featuresChanged=true;
}
break;
case FeatureStack.KUWAHARA:
tokens=a.name().split("String_Node_Str");
membranePatchSize=Integer.parseInt(tokens[1]);
break;
case FeatureStack.NEIGHBORS:
case FeatureStack.ENTROPY:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[1]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.GABOR:
case FeatureStack.STRUCTURE:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[2]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.ANISOTROPIC_DIFFUSION:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[3]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
case FeatureStack.BILATERAL:
case FeatureStack.LIPSCHITZ:
break;
default :
tokens=a.name().split("String_Node_Str");
for (int j=0; j < tokens.length; j++) if (tokens[j].indexOf("String_Node_Str") != -1) {
sigma=Float.parseFloat(tokens[j]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
}
}
}
 else {
switch (i) {
case FeatureStack3D.STRUCTURE:
tokens=a.name().split("String_Node_Str");
sigma=Float.parseFloat(tokens[2]);
if (sigma < minSigma) minSigma=sigma;
if (sigma > maxSigma) maxSigma=sigma;
break;
default :
tokens=a.name().split("String_Node_Str");
for (int j=0; j < tokens.length; j++) if (tokens[j].indexOf("String_Node_Str") != -1) {
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 (!isProcessing3D) IJ.log("String_Node_Str" + membraneThickness + "String_Node_Str"+ membranePatchSize);
if (minSigma != this.minimumSigma && minSigma != 0) {
this.minimumSigma=minSigma;
featuresChanged=true;
if (null != featureStackArray) featureStackArray.setMinimumSigma(minSigma);
if (isProcessing3D) this.fs3d.setMinimumSigma(minSigma);
}
if (maxSigma != this.maximumSigma) {
this.maximumSigma=maxSigma;
featuresChanged=true;
if (null != featureStackArray) featureStackArray.setMaximumSigma(maxSigma);
if (isProcessing3D) this.fs3d.setMaximumSigma(maxSigma);
}
Attribute classAttribute=data.classAttribute();
Enumeration<Object> classValues=classAttribute.enumerateValues();
loadedClassNames=new ArrayList<String>();
int j=0;
setNumOfClasses(0);
while (classValues.hasMoreElements()) {
final String className=((String)classValues.nextElement()).trim();
loadedClassNames.add(className);
}
for (String className : loadedClassNames) {
IJ.log("String_Node_Str" + className);
setClassLabel(j,className);
addClass();
j++;
}
if (null != featureStackArray) {
final boolean[] oldEnableFeatures=isProcessing3D ? fs3d.getEnabledFeatures() : this.featureStackArray.getEnabledFeatures();
for (int i=0; i < numFeatures; i++) {
if (usedFeatures[i] != oldEnableFeatures[i]) featuresChanged=true;
}
}
 else featuresChanged=true;
if (featuresChanged) {
this.setEnabledFeatures(usedFeatures);
updateFeatures=true;
}
return true;
}