Program: 22784
Project: 22784
Buggy source:
/** 
 * Create training instances out of the user markings
 * @return set of instances
 */
public Instances createTrainingInstances(){
  ArrayList<Attribute> attributes=new ArrayList<Attribute>();
  for (int i=1; i <= featureStack.getSize(); i++) {
    String attString=featureStack.getSliceLabel(i) + "String_Node_Str";
    attributes.add(new Attribute(attString));
  }
  final ArrayList<String> classes=new ArrayList<String>();
  int numOfInstances=0;
  for (int i=0; i < numOfClasses; i++) {
    if (examples[i].size() > 0)     classes.add(classLabels[i]);
    numOfInstances+=examples[i].size();
  }
  attributes.add(new Attribute("String_Node_Str",classes));
  final Instances trainingData=new Instances("String_Node_Str",attributes,numOfInstances);
  IJ.log("String_Node_Str");
  for (int l=0; l < numOfClasses; l++) {
    int nl=0;
    for (int j=0; j < examples[l].size(); j++) {
      Roi r=examples[l].get(j);
      if (r instanceof PolygonRoi && r.getType() != Roi.FREEROI) {
        if (r.getStrokeWidth() == 1) {
          int[] x=r.getPolygon().xpoints;
          int[] y=r.getPolygon().ypoints;
          final int n=r.getPolygon().npoints;
          for (int i=0; i < n; i++) {
            double[] values=new double[featureStack.getSize() + 1];
            for (int z=1; z <= featureStack.getSize(); z++)             values[z - 1]=featureStack.getProcessor(z).getPixelValue(x[i],y[i]);
            values[featureStack.getSize()]=(double)l;
            trainingData.add(new DenseInstance(1.0,values));
            nl++;
          }
        }
 else {
          final int width=(int)Math.round(r.getStrokeWidth());
          FloatPolygon p=r.getFloatPolygon();
          int n=p.npoints;
          double x1, y1;
          double x2=p.xpoints[0] - (p.xpoints[1] - p.xpoints[0]);
          double y2=p.ypoints[0] - (p.ypoints[1] - p.ypoints[0]);
          for (int i=0; i < n; i++) {
            x1=x2;
            y1=y2;
            x2=p.xpoints[i];
            y2=p.ypoints[i];
            double dx=x2 - x1;
            double dy=y1 - y2;
            double length=(float)Math.sqrt(dx * dx + dy * dy);
            dx/=length;
            dy/=length;
            double x=x2 - dy * width / 2.0;
            double y=y2 - dx * width / 2.0;
            int n2=width;
            do {
              double[] values=new double[featureStack.getSize() + 1];
              for (int z=1; z <= featureStack.getSize(); z++)               values[z - 1]=featureStack.getProcessor(z).getInterpolatedValue(x,y);
              values[featureStack.getSize()]=(double)l;
              trainingData.add(new DenseInstance(1.0,values));
              nl++;
              x+=dy;
              y+=dx;
            }
 while (--n2 > 0);
          }
        }
      }
 else {
        final ShapeRoi shapeRoi=new ShapeRoi(r);
        final Rectangle rect=shapeRoi.getBounds();
        final int lastX=rect.x + rect.width;
        final int lastY=rect.y + rect.height;
        for (int x=rect.x; x < lastX; x++)         for (int y=rect.y; y < lastY; y++)         if (shapeRoi.contains(x,y)) {
          double[] values=new double[featureStack.getSize() + 1];
          for (int z=1; z <= featureStack.getSize(); z++)           values[z - 1]=featureStack.getProcessor(z).getPixelValue(x,y);
          values[featureStack.getSize()]=(double)l;
          trainingData.add(new DenseInstance(1.0,values));
          nl++;
        }
      }
    }
    IJ.log("String_Node_Str" + classLabels[l] + "String_Node_Str"+ nl);
  }
  return trainingData;
}

Fixed version (ground truth):
/** 
 * Create training instances out of the user markings
 * @return set of instances
 */
public Instances createTrainingInstances(){
  ArrayList<Attribute> attributes=new ArrayList<Attribute>();
  for (int i=1; i <= featureStack.getSize(); i++) {
    String attString=featureStack.getSliceLabel(i) + "String_Node_Str";
    attributes.add(new Attribute(attString));
  }
  final ArrayList<String> classes=new ArrayList<String>();
  int numOfInstances=0;
  for (int i=0; i < numOfClasses; i++) {
    if (examples[i].size() > 0)     classes.add(classLabels[i]);
    numOfInstances+=examples[i].size();
  }
  attributes.add(new Attribute("String_Node_Str",classes));
  final Instances trainingData=new Instances("String_Node_Str",attributes,numOfInstances);
  IJ.log("String_Node_Str");
  for (int l=0; l < numOfClasses; l++) {
    int nl=0;
    for (int j=0; j < examples[l].size(); j++) {
      Roi r=examples[l].get(j);
      if (r instanceof PolygonRoi && r.getType() != Roi.FREEROI) {
        if (r.getStrokeWidth() == 1) {
          int[] x=r.getPolygon().xpoints;
          int[] y=r.getPolygon().ypoints;
          final int n=r.getPolygon().npoints;
          for (int i=0; i < n; i++) {
            double[] values=new double[featureStack.getSize() + 1];
            for (int z=1; z <= featureStack.getSize(); z++)             values[z - 1]=featureStack.getProcessor(z).getPixelValue(x[i],y[i]);
            values[featureStack.getSize()]=(double)l;
            trainingData.add(new DenseInstance(1.0,values));
            nl++;
          }
        }
 else {
          final int width=(int)Math.round(r.getStrokeWidth());
          FloatPolygon p=r.getFloatPolygon();
          int n=p.npoints;
          double x1, y1;
          double x2=p.xpoints[0] - (p.xpoints[1] - p.xpoints[0]);
          double y2=p.ypoints[0] - (p.ypoints[1] - p.ypoints[0]);
          for (int i=0; i < n; i++) {
            x1=x2;
            y1=y2;
            x2=p.xpoints[i];
            y2=p.ypoints[i];
            double dx=x2 - x1;
            double dy=y1 - y2;
            double length=(float)Math.sqrt(dx * dx + dy * dy);
            dx/=length;
            dy/=length;
            double x=x2 - dy * width / 2.0;
            double y=y2 - dx * width / 2.0;
            int n2=width;
            do {
              if (x >= 0 && x < featureStack.getWidth() && y >= 0 && y < featureStack.getHeight()) {
                double[] values=new double[featureStack.getSize() + 1];
                for (int z=1; z <= featureStack.getSize(); z++)                 values[z - 1]=featureStack.getProcessor(z).getInterpolatedValue(x,y);
                values[featureStack.getSize()]=(double)l;
                trainingData.add(new DenseInstance(1.0,values));
                nl++;
              }
              x+=dy;
              y+=dx;
            }
 while (--n2 > 0);
          }
        }
      }
 else {
        final ShapeRoi shapeRoi=new ShapeRoi(r);
        final Rectangle rect=shapeRoi.getBounds();
        final int lastX=rect.x + rect.width;
        final int lastY=rect.y + rect.height;
        for (int x=rect.x; x < lastX; x++)         for (int y=rect.y; y < lastY; y++)         if (shapeRoi.contains(x,y)) {
          double[] values=new double[featureStack.getSize() + 1];
          for (int z=1; z <= featureStack.getSize(); z++)           values[z - 1]=featureStack.getProcessor(z).getPixelValue(x,y);
          values[featureStack.getSize()]=(double)l;
          trainingData.add(new DenseInstance(1.0,values));
          nl++;
        }
      }
    }
    IJ.log("String_Node_Str" + classLabels[l] + "String_Node_Str"+ nl);
  }
  return trainingData;
}