nus-yam/ex-repair huggingface dataset:
Program: 150792
Project: 150792
Buggy source:
/** 
 * Creates an ellipse detector which will detect all ellipses in the image initially using a binary image and then refine the estimate using a subpixel algorithm in the gray scale image.
 * @param config Configuration for ellipse detector.  null == default
 * @param imageType Input image type
 * @return Detecto
 */
public static <T extends ImageGray>BinaryEllipseDetector<T> ellipse(ConfigEllipseDetector config,Class<T> imageType){
  if (config == null)   config=new ConfigEllipseDetector();
  config.checkValidity();
  BinaryEllipseDetectorPixel detector=new BinaryEllipseDetectorPixel();
  detector.setMaxDistanceFromEllipse(config.maxDistanceFromEllipse);
  detector.setMaximumContour(config.maximumContour);
  detector.setMinimumContour(config.minimumContour);
  SnapToEllipseEdge<T> refine=new SnapToEllipseEdge<T>(config.numSampleContour,config.radialSamples,imageType);
  refine.setConvergenceTol(config.convergenceTol);
  refine.setMaxIterations(config.maxIterations);
  return new BinaryEllipseDetector<T>(detector,refine);
}

Fixed version (ground truth):
/** 
 * Creates an ellipse detector which will detect all ellipses in the image initially using a binary image and then refine the estimate using a subpixel algorithm in the gray scale image.
 * @param config Configuration for ellipse detector.  null == default
 * @param imageType Input image type
 * @return Detecto
 */
public static <T extends ImageGray>BinaryEllipseDetector<T> ellipse(ConfigEllipseDetector config,Class<T> imageType){
  if (config == null)   config=new ConfigEllipseDetector();
  config.checkValidity();
  BinaryEllipseDetectorPixel detector=new BinaryEllipseDetectorPixel();
  detector.setMaxDistanceFromEllipse(config.maxDistanceFromEllipse);
  detector.setMaximumContour(config.maximumContour);
  detector.setMinimumContour(config.minimumContour);
  detector.setInternalContour(config.processInternal);
  SnapToEllipseEdge<T> refine=new SnapToEllipseEdge<T>(config.numSampleContour,config.radialSamples,imageType);
  refine.setConvergenceTol(config.convergenceTol);
  refine.setMaxIterations(config.maxIterations);
  return new BinaryEllipseDetector<T>(detector,refine);
}
Program: 150793
Project: 150793
Buggy source:
/** 
 * Detects ellipses inside the binary image and refines the edges for all detections inside the gray image
 * @param gray Grayscale image
 * @param binary Binary image of grayscale. 1 = ellipse and 0 = ignored background
 */
public void process(T gray,GrayU8 binary){
  refined.reset();
  ellipseDetector.process(binary);
  ellipseRefiner.setImage(gray);
  intensityCheck.setImage(gray);
  List<BinaryEllipseDetectorPixel.Found> found=ellipseDetector.getFound();
  for (  BinaryEllipseDetectorPixel.Found f : found) {
    if (!intensityCheck.process(f.ellipse)) {
      if (verbose)       System.out.println("String_Node_Str");
      continue;
    }
    EllipseRotated_F64 r=refined.grow();
    if (ellipseRefiner != null) {
      if (!ellipseRefiner.process(f.ellipse,r)) {
        refined.removeTail();
      }
    }
 else {
      r.set(f.ellipse);
    }
  }
}

Fixed version (ground truth):
/** 
 * Detects ellipses inside the binary image and refines the edges for all detections inside the gray image
 * @param gray Grayscale image
 * @param binary Binary image of grayscale. 1 = ellipse and 0 = ignored background
 */
public void process(T gray,GrayU8 binary){
  refined.reset();
  ellipseDetector.process(binary);
  if (ellipseRefiner != null)   ellipseRefiner.setImage(gray);
  intensityCheck.setImage(gray);
  List<BinaryEllipseDetectorPixel.Found> found=ellipseDetector.getFound();
  for (  BinaryEllipseDetectorPixel.Found f : found) {
    if (!intensityCheck.process(f.ellipse)) {
      if (verbose)       System.out.println("String_Node_Str");
      continue;
    }
    EllipseRotated_F64 r=refined.grow();
    if (ellipseRefiner != null) {
      if (!ellipseRefiner.process(f.ellipse,r)) {
        refined.removeTail();
      }
    }
 else {
      r.set(f.ellipse);
    }
  }
}
Program: 150794
Project: 150794
Buggy source:
public Class<T> getInputType(){
  return ellipseRefiner.getInputType();
}

Fixed version (ground truth):
public Class<T> getInputType(){
  return inputType;
}
Program: 150795
Project: 150795
Buggy source:
/** 
 * <p>Specifies transforms which can be used to change coordinates from distorted to undistorted. The undistorted image is never explicitly created.</p> <p> WARNING: The undistorted image must have the same bounds as the distorted input image.  This is because several of the bounds checks use the image shape.  This are simplified greatly by this assumption. </p>
 * @param distToUndist Transform from distorted to undistorted image.
 */
public void setLensDistortion(PixelTransform_F32 distToUndist){
  this.ellipseDetector.setLensDistortion(distToUndist);
  this.ellipseRefiner.setTransform(distToUndist);
  this.intensityCheck.setTransform(distToUndist);
}

Fixed version (ground truth):
/** 
 * <p>Specifies transforms which can be used to change coordinates from distorted to undistorted. The undistorted image is never explicitly created.</p> <p> WARNING: The undistorted image must have the same bounds as the distorted input image.  This is because several of the bounds checks use the image shape.  This are simplified greatly by this assumption. </p>
 * @param distToUndist Transform from distorted to undistorted image.
 */
public void setLensDistortion(PixelTransform_F32 distToUndist){
  this.ellipseDetector.setLensDistortion(distToUndist);
  if (this.ellipseRefiner != null)   this.ellipseRefiner.setTransform(distToUndist);
  this.intensityCheck.setTransform(distToUndist);
}
Program: 150796
Project: 150796
Buggy source:
public BinaryEllipseDetector(BinaryEllipseDetectorPixel ellipseDetector,SnapToEllipseEdge<T> ellipseRefiner,EdgeIntensityEllipse<T> intensityCheck){
  this.ellipseDetector=ellipseDetector;
  this.ellipseRefiner=ellipseRefiner;
  this.intensityCheck=intensityCheck;
}

Fixed version (ground truth):
public BinaryEllipseDetector(BinaryEllipseDetectorPixel ellipseDetector,SnapToEllipseEdge<T> ellipseRefiner,EdgeIntensityEllipse<T> intensityCheck,Class<T> inputType){
  this.ellipseDetector=ellipseDetector;
  this.ellipseRefiner=ellipseRefiner;
  this.intensityCheck=intensityCheck;
  this.inputType=inputType;
}
Program: 150797
Project: 150797
Buggy source:
/** 
 * Refines provided list by snapping it to edges found in the image
 * @param input Close approximation of the ellipse in the image
 * @param refined Storage for refined estimate.
 * @return True if a refined estimate could be found, false if it failed
 */
public boolean process(EllipseRotated_F64 input,EllipseRotated_F64 refined){
  previous.set(input);
  for (int iteration=0; iteration < maxIterations; iteration++) {
    refined.set(previous);
    computePointsAndWeights(refined);
    if (fitter.process(samplePts.toList(),weights.data)) {
      UtilEllipse_F64.convert(fitter.getEllipse(),refined);
      double scale=previous.a;
      refined.center.x=refined.center.x * scale + previous.center.x;
      refined.center.y=refined.center.y * scale + previous.center.y;
      refined.a*=scale;
      refined.b*=scale;
    }
 else {
      return false;
    }
    if (change(previous,refined) <= convergenceTol) {
      return true;
    }
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Refines provided list by snapping it to edges found in the image
 * @param input Close approximation of the ellipse in the image
 * @param refined Storage for refined estimate.
 * @return True if a refined estimate could be found, false if it failed
 */
public boolean process(EllipseRotated_F64 input,EllipseRotated_F64 refined){
  refined.set(input);
  previous.set(input);
  for (int iteration=0; iteration < maxIterations; iteration++) {
    refined.set(previous);
    computePointsAndWeights(refined);
    if (fitter.process(samplePts.toList(),weights.data)) {
      UtilEllipse_F64.convert(fitter.getEllipse(),refined);
      double scale=previous.a;
      refined.center.x=refined.center.x * scale + previous.center.x;
      refined.center.y=refined.center.y * scale + previous.center.y;
      refined.a*=scale;
      refined.b*=scale;
    }
 else {
      return false;
    }
    if (change(previous,refined) <= convergenceTol) {
      return true;
    }
  }
  return true;
}
Program: 150798
Project: 150798
Buggy source:
/** 
 * Creates an ellipse detector which will detect all ellipses in the image initially using a binary image and then refine the estimate using a subpixel algorithm in the gray scale image.
 * @param config Configuration for ellipse detector.  null == default
 * @param imageType Input image type
 * @return Detecto
 */
public static <T extends ImageGray>BinaryEllipseDetector<T> ellipse(ConfigEllipseDetector config,Class<T> imageType){
  if (config == null)   config=new ConfigEllipseDetector();
  config.checkValidity();
  BinaryEllipseDetectorPixel detector=new BinaryEllipseDetectorPixel();
  detector.setMaxDistanceFromEllipse(config.maxDistanceFromEllipse);
  detector.setMaximumContour(config.maximumContour);
  detector.setMinimumContour(config.minimumContour);
  detector.setInternalContour(config.processInternal);
  SnapToEllipseEdge<T> refine=new SnapToEllipseEdge<T>(config.numSampleContour,config.refineRadialSamples,imageType);
  refine.setConvergenceTol(config.convergenceTol);
  refine.setMaxIterations(config.maxIterations);
  if (config.numSampleContour <= 0) {
    refine=null;
  }
  EdgeIntensityEllipse<T> check=new EdgeIntensityEllipse<T>(config.checkRadialDistance,config.numSampleContour,config.checkIntensityThreshold,imageType);
  return new BinaryEllipseDetector<T>(detector,refine,check);
}

Fixed version (ground truth):
/** 
 * Creates an ellipse detector which will detect all ellipses in the image initially using a binary image and then refine the estimate using a subpixel algorithm in the gray scale image.
 * @param config Configuration for ellipse detector.  null == default
 * @param imageType Input image type
 * @return Detecto
 */
public static <T extends ImageGray>BinaryEllipseDetector<T> ellipse(ConfigEllipseDetector config,Class<T> imageType){
  if (config == null)   config=new ConfigEllipseDetector();
  config.checkValidity();
  BinaryEllipseDetectorPixel detector=new BinaryEllipseDetectorPixel();
  detector.setMaxDistanceFromEllipse(config.maxDistanceFromEllipse);
  detector.setMaximumContour(config.maximumContour);
  detector.setMinimumContour(config.minimumContour);
  detector.setInternalContour(config.processInternal);
  SnapToEllipseEdge<T> refine=new SnapToEllipseEdge<T>(config.numSampleContour,config.refineRadialSamples,imageType);
  refine.setConvergenceTol(config.convergenceTol);
  refine.setMaxIterations(config.maxIterations);
  if (config.maxIterations <= 0 || config.numSampleContour <= 0) {
    refine=null;
  }
  EdgeIntensityEllipse<T> check=new EdgeIntensityEllipse<T>(config.checkRadialDistance,config.numSampleContour,config.checkIntensityThreshold,imageType);
  return new BinaryEllipseDetector<T>(detector,refine,check,imageType);
}
Program: 150799
Project: 150799
Buggy source:
public static <T extends ImageInterleaved<T>>T convertFrom(IplImage input,T output){
  ImageDataType dataType=depthToBoofType(input.depth());
  int numBands=input.nChannels();
  int width=input.width();
  int height=input.height();
  if (output != null) {
    if (output.isSubimage())     throw new IllegalArgumentException("String_Node_Str");
    if (output.getDataType() != dataType)     throw new IllegalArgumentException("String_Node_Str" + dataType + "String_Node_Str"+ output.getDataType()+ "String_Node_Str");
    output.numBands=numBands;
    output.reshape(width,height);
  }
 else {
    output=GeneralizedImageOps.createInterleaved(dataType,width,height,numBands);
  }
switch (dataType) {
case U8:
case S8:
    convertFrom_I(input,(InterleavedI8)output);
  break;
case S16:
convertFrom_I(input,(InterleavedS16)output);
break;
case S32:
convertFrom_I(input,(InterleavedS32)output);
break;
case F32:
convertFrom_I(input,(InterleavedF32)output);
break;
case F64:
convertFrom_I(input,(InterleavedF64)output);
break;
default :
throw new RuntimeException("String_Node_Str" + dataType);
}
return output;
}

Fixed version (ground truth):
public static <T extends ImageInterleaved>T convertFrom(IplImage input,T output){
  ImageDataType dataType=depthToBoofType(input.depth());
  int numBands=input.nChannels();
  int width=input.width();
  int height=input.height();
  if (output != null) {
    if (output.isSubimage())     throw new IllegalArgumentException("String_Node_Str");
    if (output.getDataType() != dataType)     throw new IllegalArgumentException("String_Node_Str" + dataType + "String_Node_Str"+ output.getDataType()+ "String_Node_Str");
    output.numBands=numBands;
    output.reshape(width,height);
  }
 else {
    output=GeneralizedImageOps.createInterleaved(dataType,width,height,numBands);
  }
switch (dataType) {
case U8:
case S8:
    convertFrom_I(input,(InterleavedI8)output);
  break;
case S16:
convertFrom_I(input,(InterleavedS16)output);
break;
case S32:
convertFrom_I(input,(InterleavedS32)output);
break;
case F32:
convertFrom_I(input,(InterleavedF32)output);
break;
case F64:
convertFrom_I(input,(InterleavedF64)output);
break;
default :
throw new RuntimeException("String_Node_Str" + dataType);
}
return output;
}
Program: 150800
Project: 150800
Buggy source:
/** 
 * Constructor in which the prefered width and height is specified in pixels
 * @param widthPixels preferred width and height
 */
public ConfusionMatrixPanel(int widthPixels){
  int heightPixels=widthPixels;
  if (labels != null) {
    heightPixels*=1.0 - labelViewFraction;
  }
  setPreferredSize(new Dimension(widthPixels,heightPixels));
}

Fixed version (ground truth):
/** 
 * Constructor in which the prefered width and height is specified in pixels
 * @param widthPixels preferred width and height
 */
public ConfusionMatrixPanel(int widthPixels,List<String> labels){
  setLabels(labels);
  int heightPixels=widthPixels;
  if (labels != null) {
    heightPixels*=1.0 - labelViewFraction;
  }
  setPreferredSize(new Dimension(widthPixels,heightPixels));
}
Program: 150801
Project: 150801
Buggy source:
/** 
 * Checks to see if its a valid polygon or a false positive by looking at edge intensity
 * @param polygon The polygon being tested
 * @param ccw True if the polygon is counter clockwise
 * @return true if it could compute the edge intensity, otherwise false
 */
public boolean computeEdge(Polygon2D_F64 polygon,boolean ccw){
  averageInside=0;
  averageOutside=0;
  double tagentSign=ccw ? 1 : -1;
  int totalSides=0;
  for (int i=polygon.size() - 1, j=0; j < polygon.size(); i=j, j++) {
    Point2D_F64 a=polygon.get(i);
    Point2D_F64 b=polygon.get(j);
    double dx=b.x - a.x;
    double dy=b.y - a.y;
    double t=Math.sqrt(dx * dx + dy * dy);
    dx/=t;
    dy/=t;
    if (t <= 3 * cornerOffset)     return false;
    offsetA.x=a.x + cornerOffset * dx;
    offsetA.y=a.y + cornerOffset * dy;
    offsetB.x=b.x - cornerOffset * dx;
    offsetB.y=b.y - cornerOffset * dy;
    double tanX=-dy * tangentDistance * tagentSign;
    double tanY=dx * tangentDistance * tagentSign;
    scorer.computeAverageDerivative(offsetA,offsetB,tanX,tanY);
    if (scorer.getSamplesInside() > 0) {
      totalSides++;
      averageInside+=scorer.getAverageUp() / tangentDistance;
      averageOutside+=scorer.getAverageDown() / tangentDistance;
    }
  }
  if (totalSides > 0) {
    averageInside/=totalSides;
    averageOutside/=totalSides;
  }
 else {
    averageInside=averageOutside=0;
    return false;
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Checks to see if its a valid polygon or a false positive by looking at edge intensity
 * @param polygon The polygon being tested
 * @param ccw True if the polygon is counter clockwise
 * @return true if it could compute the edge intensity, otherwise false
 */
public boolean computeEdge(Polygon2D_F64 polygon,boolean ccw){
  averageInside=0;
  averageOutside=0;
  double tangentSign=ccw ? 1 : -1;
  int totalSides=0;
  for (int i=polygon.size() - 1, j=0; j < polygon.size(); i=j, j++) {
    Point2D_F64 a=polygon.get(i);
    Point2D_F64 b=polygon.get(j);
    double dx=b.x - a.x;
    double dy=b.y - a.y;
    double t=Math.sqrt(dx * dx + dy * dy);
    dx/=t;
    dy/=t;
    if (t <= 3 * cornerOffset)     return false;
    offsetA.x=a.x + cornerOffset * dx;
    offsetA.y=a.y + cornerOffset * dy;
    offsetB.x=b.x - cornerOffset * dx;
    offsetB.y=b.y - cornerOffset * dy;
    double tanX=-dy * tangentDistance * tangentSign;
    double tanY=dx * tangentDistance * tangentSign;
    scorer.computeAverageDerivative(offsetA,offsetB,tanX,tanY);
    if (scorer.getSamplesInside() > 0) {
      totalSides++;
      averageInside+=scorer.getAverageUp() / tangentDistance;
      averageOutside+=scorer.getAverageDown() / tangentDistance;
    }
  }
  if (totalSides > 0) {
    averageInside/=totalSides;
    averageOutside/=totalSides;
  }
 else {
    averageInside=averageOutside=0;
    return false;
  }
  return true;
}
Program: 150802
Project: 150802
Buggy source:
private void global(Graphics2D g2){
  int cell=hog.getWidthCell();
  int rows=hog.getCellRows();
  int cols=hog.getCellCols();
  int width=cell * cols;
  int height=cell * rows;
  int numAngles=hog.getOrientationBins();
  float r=cell / 2;
  float maxValue=0;
  for (int y=0; y < rows; y++) {
    for (int x=0; x < cols; x++) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y,x);
      for (int i=0; i < numAngles; i++) {
        maxValue=Math.max(maxValue,c.histogram[i]);
      }
    }
  }
  System.out.println("String_Node_Str" + maxValue);
  Line2D.Float line=new Line2D.Float();
  for (int y=0; y < height; y+=cell) {
    float c_y=y + r;
    for (int x=0; x < width; x+=cell) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y / cell,x / cell);
      float c_x=x + r;
      for (int i=0; i < numAngles; i++) {
        int a=(int)(255.0f * c.histogram[i] / maxValue + 0.5f);
        g2.setColor(colors[a]);
        float x0=c_x - r * cos[i] + 0.5f;
        float x1=c_x + r * cos[i] + 0.5f;
        float y0=c_y - r * sin[i] + 0.5f;
        float y1=c_y + r * sin[i] + 0.5f;
        line.setLine(x0,y0,x1,y1);
        g2.draw(line);
      }
    }
  }
}

Fixed version (ground truth):
private void global(Graphics2D g2){
  int cell=hog.getWidthCell();
  int rows=hog.getCellRows();
  int cols=hog.getCellCols();
  int width=cell * cols;
  int height=cell * rows;
  int numAngles=hog.getOrientationBins();
  float r=cell / 2;
  float foo=cell / 2 - 2;
  float maxValue=0;
  for (int y=0; y < rows; y++) {
    for (int x=0; x < cols; x++) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y,x);
      for (int i=0; i < numAngles; i++) {
        maxValue=Math.max(maxValue,c.histogram[i]);
      }
    }
  }
  Line2D.Float line=new Line2D.Float();
  for (int y=0; y < height; y+=cell) {
    float c_y=y + r;
    for (int x=0; x < width; x+=cell) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y / cell,x / cell);
      float c_x=x + r;
      for (int i=0; i < numAngles; i++) {
        int a=(int)(255.0f * c.histogram[i] / maxValue + 0.5f);
        g2.setColor(colors[a]);
        float x0=c_x - foo * cos[i];
        float x1=c_x + foo * cos[i];
        float y0=c_y - foo * sin[i];
        float y1=c_y + foo * sin[i];
        line.setLine(x0,y0,x1,y1);
        g2.draw(line);
      }
    }
  }
}
Program: 150803
Project: 150803
Buggy source:
public void render(Graphics2D g2){
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_PURE);
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setStroke(new BasicStroke(1));
  if (localMax) {
    local(g2);
  }
 else {
    global(g2);
  }
}

Fixed version (ground truth):
public void render(Graphics2D g2){
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_PURE);
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF);
  if (showGrid) {
    int cell=hog.getWidthCell();
    int rows=hog.getCellRows();
    int cols=hog.getCellCols();
    int width=cell * cols;
    int height=cell * rows;
    g2.setColor(new Color(150,150,0));
    g2.setStroke(new BasicStroke(1));
    for (int i=0; i < rows; i++) {
      g2.drawLine(0,i * cell,width,i * cell);
    }
    for (int i=0; i < cols; i++) {
      g2.drawLine(i * cell,0,i * cell,height);
    }
  }
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setStroke(new BasicStroke(1));
  if (localMax) {
    local(g2);
  }
 else {
    global(g2);
  }
}
Program: 150804
Project: 150804
Buggy source:
private void local(Graphics2D g2){
  int cell=hog.getWidthCell();
  int rows=hog.getCellRows();
  int cols=hog.getCellCols();
  int width=cell * cols;
  int height=cell * rows;
  int numAngles=hog.getOrientationBins();
  float r=cell / 2;
  Line2D.Float line=new Line2D.Float();
  for (int y=0; y < height; y+=cell) {
    float c_y=y + r;
    for (int x=0; x < width; x+=cell) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y / cell,x / cell);
      float c_x=x + r;
      float maxValue=0;
      for (int i=0; i < c.histogram.length; i++) {
        maxValue=Math.max(maxValue,c.histogram[i]);
      }
      for (int i=0; i < numAngles; i++) {
        int a=(int)(255.0f * c.histogram[i] / maxValue + 0.5f);
        g2.setColor(colors[a]);
        float x0=c_x - r * cos[i] + 0.5f;
        float x1=c_x + r * cos[i] + 0.5f;
        float y0=c_y - r * sin[i] + 0.5f;
        float y1=c_y + r * sin[i] + 0.5f;
        line.setLine(x0,y0,x1,y1);
        g2.draw(line);
      }
    }
  }
}

Fixed version (ground truth):
private void local(Graphics2D g2){
  int cell=hog.getWidthCell();
  int rows=hog.getCellRows();
  int cols=hog.getCellCols();
  int width=cell * cols;
  int height=cell * rows;
  int numAngles=hog.getOrientationBins();
  float r=cell / 2 - 1;
  Line2D.Float line=new Line2D.Float();
  for (int y=0; y < height; y+=cell) {
    float c_y=y + r;
    for (int x=0; x < width; x+=cell) {
      DescribeDenseHogAlg.Cell c=hog.getCell(y / cell,x / cell);
      float c_x=x + r;
      float maxValue=0;
      for (int i=0; i < c.histogram.length; i++) {
        maxValue=Math.max(maxValue,c.histogram[i]);
      }
      for (int i=0; i < numAngles; i++) {
        int a=(int)(255.0f * c.histogram[i] / maxValue + 0.5f);
        g2.setColor(colors[a]);
        float x0=c_x - r * cos[i];
        float x1=c_x + r * cos[i];
        float y0=c_y - r * sin[i];
        float y1=c_y + r * sin[i];
        line.setLine(x0,y0,x1,y1);
        g2.draw(line);
      }
    }
  }
}
Program: 150805
Project: 150805
Buggy source:
public VisualizeImageHogApp(ConfigDenseHoG config,List<String> exampleInputs,ImageType<T> imageType){
  super(exampleInputs,imageType);
  hog=FactoryDescribeImageDenseAlg.hog(config,imageType);
  visualizers=new VisualizeHogCells(hog,true);
  visualizers.setLocalMax(false);
  add(imagePanel,BorderLayout.CENTER);
}

Fixed version (ground truth):
public VisualizeImageHogApp(ConfigDenseHoG config,List<String> exampleInputs,ImageType<T> imageType){
  super(exampleInputs,imageType);
  hog=FactoryDescribeImageDenseAlg.hog(config,imageType);
  visualizers=new VisualizeHogCells(hog,true);
  visualizers.setLocalMax(false);
  add(imagePanel,BorderLayout.CENTER);
  imagePanel.addMouseListener(new MouseListener(){
    @Override public void mouseClicked(    MouseEvent e){
    }
    @Override public void mousePressed(    MouseEvent e){
      int row=e.getY() / hog.getWidthCell();
      int col=e.getX() / hog.getWidthCell();
      if (row >= 0 && col >= 0 && row < hog.getCellRows() && col < hog.getCellCols()) {
        DescribeDenseHogAlg.Cell c=hog.getCell(row,col);
        System.out.print("String_Node_Str" + row + "String_Node_Str"+ col+ "String_Node_Str");
        for (int i=0; i < c.histogram.length; i++) {
          System.out.print("String_Node_Str" + c.histogram[i]);
        }
        System.out.println();
      }
    }
    @Override public void mouseReleased(    MouseEvent e){
    }
    @Override public void mouseEntered(    MouseEvent e){
    }
    @Override public void mouseExited(    MouseEvent e){
    }
  }
);
}
Program: 150806
Project: 150806
Buggy source:
/** 
 * Compute histograms for all the cells inside the image using precomputed derivative.
 */
void computeCellHistograms(){
  int width=cellCols * widthCell;
  int height=cellRows * widthCell;
  float angleBinSize=GrlConstants.F_PI / orientationBins;
  int indexCell=0;
  for (int i=0; i < height; i+=widthCell) {
    for (int j=0; j < width; j+=widthCell, indexCell++) {
      Cell c=cells[indexCell];
      c.reset();
      for (int k=0; k < widthCell; k++) {
        int indexPixel=(i + k) * derivX.width + j;
        for (int l=0; l < widthCell; l++, indexPixel++) {
          computeDerivative(indexPixel);
          float angle=UtilAngle.atanSafe(pixelDY,pixelDX) + GrlConstants.F_PId2;
          float magnitude=(float)Math.sqrt(pixelDX * pixelDX + pixelDY * pixelDY);
          float findex0=angle / angleBinSize;
          int index0=(int)findex0;
          int index1=(index0 + 1) % orientationBins;
          float weight1=findex0 - index0;
          c.histogram[index0 % orientationBins]=magnitude * (1.0f - weight1);
          c.histogram[index1]=magnitude * weight1;
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Compute histograms for all the cells inside the image using precomputed derivative.
 */
void computeCellHistograms(){
  int width=cellCols * widthCell;
  int height=cellRows * widthCell;
  float angleBinSize=GrlConstants.F_PI / orientationBins;
  int indexCell=0;
  for (int i=0; i < height; i+=widthCell) {
    for (int j=0; j < width; j+=widthCell, indexCell++) {
      Cell c=cells[indexCell];
      c.reset();
      for (int k=0; k < widthCell; k++) {
        int indexPixel=(i + k) * derivX.width + j;
        for (int l=0; l < widthCell; l++, indexPixel++) {
          computeDerivative(indexPixel);
          float angle=UtilAngle.atanSafe(pixelDY,pixelDX) + GrlConstants.F_PId2;
          float magnitude=(float)Math.sqrt(pixelDX * pixelDX + pixelDY * pixelDY);
          float findex0=angle / angleBinSize;
          int index0=(int)findex0;
          float weight1=findex0 - index0;
          index0%=orientationBins;
          int index1=(index0 + 1) % orientationBins;
          c.histogram[index0]+=magnitude * (1.0f - weight1);
          c.histogram[index1]+=magnitude * weight1;
        }
      }
    }
  }
}
Program: 150807
Project: 150807
Buggy source:
private static int maxAbsU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex];
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v > output)       output=v;
    }
  }
  return output;
}

Fixed version (ground truth):
private static int maxAbsU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex] & 0xFFFF;
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v > output)       output=v;
    }
  }
  return output;
}
Program: 150808
Project: 150808
Buggy source:
private static int maxU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex];
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v > output)       output=v;
    }
  }
  return output;
}

Fixed version (ground truth):
private static int maxU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex] & 0xFFFF;
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v > output)       output=v;
    }
  }
  return output;
}
Program: 150809
Project: 150809
Buggy source:
private static int minU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex];
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v < output)       output=v;
    }
  }
  return output;
}

Fixed version (ground truth):
private static int minU(short[] array,int startIndex,int rows,int columns,int stride){
  int output=array[startIndex] & 0xFFFF;
  for (int y=0; y < rows; y++) {
    int index=startIndex + y * stride;
    int end=index + columns;
    for (; index < end; index++) {
      int v=array[index] & 0xFFFF;
      if (v < output)       output=v;
    }
  }
  return output;
}
Program: 150810
Project: 150810
Buggy source:
private void testMax(Method m) throws InvocationTargetException, IllegalAccessException {
  Class paramTypes[]=m.getParameterTypes();
  ImageBase input=GeneralizedImageOps.createImage(paramTypes[0],width,height,numBands);
  if (input.getImageType().getDataType().isSigned()) {
    GImageMiscOps.fillUniform(input,rand,-20,-5);
    GeneralizedImageOps.setB(input,0,3,0,-2);
    Number o=(Number)m.invoke(null,input);
    assertEquals(-2,o.doubleValue(),1e-8);
  }
 else {
    GImageMiscOps.fillUniform(input,rand,0,20);
    GeneralizedImageOps.setB(input,0,3,0,100);
    Number o=(Number)m.invoke(null,input);
    assertEquals(100,o.doubleValue(),1e-8);
  }
}

Fixed version (ground truth):
private void testMax(Method m) throws InvocationTargetException, IllegalAccessException {
  Class paramTypes[]=m.getParameterTypes();
  ImageBase input=GeneralizedImageOps.createImage(paramTypes[0],width,height,numBands);
  if (input.getImageType().getDataType().isSigned()) {
    GImageMiscOps.fillUniform(input,rand,-20,-5);
    GeneralizedImageOps.setB(input,0,3,0,-2);
    Number o=(Number)m.invoke(null,input);
    assertEquals(-2,o.doubleValue(),1e-8);
  }
 else {
    GImageMiscOps.fillUniform(input,rand,0,200);
    double maxValue=input.getImageType().getDataType().getMaxValue();
    for (int y=0; y < height; y++) {
      for (int x=0; x < width; x++) {
        double before=GeneralizedImageOps.get(input,x,y,0);
        GeneralizedImageOps.setB(input,x,y,0,maxValue);
        Number o=(Number)m.invoke(null,input);
        assertEquals(maxValue,o.doubleValue(),1e-8);
        GeneralizedImageOps.setB(input,x,y,0,before);
      }
    }
  }
}
Program: 150811
Project: 150811
Buggy source:
private void testMin(Method m) throws InvocationTargetException, IllegalAccessException {
  Class paramTypes[]=m.getParameterTypes();
  ImageBase input=GeneralizedImageOps.createImage(paramTypes[0],width,height,numBands);
  if (input.getImageType().getDataType().isSigned()) {
    GImageMiscOps.fillUniform(input,rand,-20,-5);
    GeneralizedImageOps.setB(input,0,3,0,-30);
    Number o=(Number)m.invoke(null,input);
    assertEquals(-30,o.doubleValue(),1e-8);
  }
 else {
    GImageMiscOps.fillUniform(input,rand,5,20);
    GeneralizedImageOps.setB(input,0,3,0,2);
    Number o=(Number)m.invoke(null,input);
    assertEquals(2,o.doubleValue(),1e-8);
  }
}

Fixed version (ground truth):
private void testMin(Method m) throws InvocationTargetException, IllegalAccessException {
  Class paramTypes[]=m.getParameterTypes();
  ImageBase input=GeneralizedImageOps.createImage(paramTypes[0],width,height,numBands);
  if (input.getImageType().getDataType().isSigned()) {
    GImageMiscOps.fillUniform(input,rand,-20,-5);
    GeneralizedImageOps.setB(input,0,3,0,-30);
    Number o=(Number)m.invoke(null,input);
    assertEquals(-30,o.doubleValue(),1e-8);
  }
 else {
    double maxValue=input.getImageType().getDataType().getMaxValue();
    GImageMiscOps.fillUniform(input,rand,100,maxValue);
    for (int y=0; y < height; y++) {
      for (int x=0; x < width; x++) {
        double before=GeneralizedImageOps.get(input,x,y,0);
        GeneralizedImageOps.setB(input,x,y,0,5);
        Number o=(Number)m.invoke(null,input);
        assertEquals(5,o.doubleValue(),1e-8);
        GeneralizedImageOps.setB(input,x,y,0,before);
      }
    }
  }
}
Program: 150812
Project: 150812
Buggy source:
public static void main(String[] args){
  ConfigDenseSurfFast surfFast=new ConfigDenseSurfFast(new DenseSampling(8,8));
  ConfigDenseSurfStable surfStable=new ConfigDenseSurfStable(new DenseSampling(8,8));
  ConfigDenseSift sift=new ConfigDenseSift(new DenseSampling(6,6));
  ConfigDenseHoG hog=new ConfigDenseHoG();
  DescribeImageDense<ImageUInt8,TupleDesc_F64> desc=(DescribeImageDense)FactoryDescribeImageDense.surfFast(surfFast,ImageUInt8.class);
  ComputeClusters<double[]> clusterer=FactoryClustering.kMeans_F64(null,MAX_KNN_ITERATIONS,20,1e-6);
  clusterer.setVerbose(true);
  NearestNeighbor<HistogramScene> nn=FactoryNearestNeighbor.exhaustive();
  ExampleClassifySceneKnn example=new ExampleClassifySceneKnn(desc,clusterer,nn);
  File trainingDir=new File(UtilIO.pathExample("String_Node_Str"));
  File testingDir=new File(UtilIO.pathExample("String_Node_Str"));
  if (!trainingDir.exists() || !testingDir.exists()) {
    String path=UtilIO.pathExample("String_Node_Str");
    System.err.println("String_Node_Str" + path + "String_Node_Str");
    System.err.println("String_Node_Str");
    System.exit(1);
  }
  example.loadSets(trainingDir,null,testingDir);
  example.learnAndSave();
  example.loadAndCreateClassifier();
  Confusion confusion=example.evaluateTest();
  confusion.getMatrix().print();
  System.out.println("String_Node_Str" + confusion.computeAccuracy());
  ShowImages.showWindow(new ConfusionMatrixPanel(confusion.getMatrix(),400,true),"String_Node_Str",true);
}

Fixed version (ground truth):
public static void main(String[] args){
  ConfigDenseSurfFast surfFast=new ConfigDenseSurfFast(new DenseSampling(8,8));
  ConfigDenseSurfStable surfStable=new ConfigDenseSurfStable(new DenseSampling(8,8));
  ConfigDenseSift sift=new ConfigDenseSift(new DenseSampling(6,6));
  ConfigDenseHoG hog=new ConfigDenseHoG();
  DescribeImageDense<ImageUInt8,TupleDesc_F64> desc=(DescribeImageDense)FactoryDescribeImageDense.hog(hog,ImageType.single(ImageUInt8.class));
  ComputeClusters<double[]> clusterer=FactoryClustering.kMeans_F64(null,MAX_KNN_ITERATIONS,20,1e-6);
  clusterer.setVerbose(true);
  NearestNeighbor<HistogramScene> nn=FactoryNearestNeighbor.exhaustive();
  ExampleClassifySceneKnn example=new ExampleClassifySceneKnn(desc,clusterer,nn);
  File trainingDir=new File(UtilIO.pathExample("String_Node_Str"));
  File testingDir=new File(UtilIO.pathExample("String_Node_Str"));
  if (!trainingDir.exists() || !testingDir.exists()) {
    String path=UtilIO.pathExample("String_Node_Str");
    System.err.println("String_Node_Str" + path + "String_Node_Str");
    System.err.println("String_Node_Str");
    System.exit(1);
  }
  example.loadSets(trainingDir,null,testingDir);
  example.learnAndSave();
  example.loadAndCreateClassifier();
  Confusion confusion=example.evaluateTest();
  confusion.getMatrix().print();
  System.out.println("String_Node_Str" + confusion.computeAccuracy());
  ShowImages.showWindow(new ConfusionMatrixPanel(confusion.getMatrix(),400,true),"String_Node_Str",true);
}
Program: 150813
Project: 150813
Buggy source:
/** 
 * Captures calibration data live using a webcam and a GUI to assist the user
 */
public void handleWebcam(){
  Webcam webcam=openSelectedCamera();
  if (desiredWidth > 0 && desiredHeight > 0)   UtilWebcamCapture.adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  ComputeGeometryScore quality=new ComputeGeometryScore(zeroSkew,detector.getLayout());
  AssistedCalibrationGui gui=new AssistedCalibrationGui(webcam.getViewSize());
  JFrame frame=ShowImages.showWindow(gui,"String_Node_Str",true);
  ImageFloat32 gray=new ImageFloat32(webcam.getViewSize().width,webcam.getViewSize().height);
  AssistedCalibration assisted=new AssistedCalibration(detector,quality,gui);
  assisted.init(gray.width,gray.height);
  BufferedImage image;
  while ((image=webcam.getImage()) != null && !assisted.isFinished()) {
    ConvertBufferedImage.convertFrom(image,gray);
    try {
      assisted.process(gray,image);
    }
 catch (    RuntimeException e) {
      System.err.println("String_Node_Str");
      UtilImageIO.saveImage(image,"String_Node_Str");
      throw e;
    }
  }
  webcam.close();
  if (assisted.isFinished()) {
    frame.setVisible(false);
    inputDirectory=AssistedCalibration.IMAGE_DIRECTORY;
    outputFileName=new File(AssistedCalibration.OUTPUT_DIRECTORY,"String_Node_Str").getPath();
    handleDirectory();
  }
}

Fixed version (ground truth):
/** 
 * Captures calibration data live using a webcam and a GUI to assist the user
 */
public void handleWebcam(){
  final Webcam webcam=openSelectedCamera();
  if (desiredWidth > 0 && desiredHeight > 0)   UtilWebcamCapture.adjustResolution(webcam,desiredWidth,desiredHeight);
  webcam.open();
  Runtime.getRuntime().addShutdownHook(new Thread(){
    public void run(){
      if (webcam.isOpen()) {
        System.out.println("String_Node_Str");
        webcam.close();
      }
    }
  }
);
  ComputeGeometryScore quality=new ComputeGeometryScore(zeroSkew,detector.getLayout());
  AssistedCalibrationGui gui=new AssistedCalibrationGui(webcam.getViewSize());
  JFrame frame=ShowImages.showWindow(gui,"String_Node_Str",true);
  ImageFloat32 gray=new ImageFloat32(webcam.getViewSize().width,webcam.getViewSize().height);
  AssistedCalibration assisted=new AssistedCalibration(detector,quality,gui);
  assisted.init(gray.width,gray.height);
  BufferedImage image;
  while ((image=webcam.getImage()) != null && !assisted.isFinished()) {
    ConvertBufferedImage.convertFrom(image,gray);
    try {
      assisted.process(gray,image);
    }
 catch (    RuntimeException e) {
      System.err.println("String_Node_Str");
      UtilImageIO.saveImage(image,"String_Node_Str");
      throw e;
    }
  }
  webcam.close();
  if (assisted.isFinished()) {
    frame.setVisible(false);
    inputDirectory=AssistedCalibration.IMAGE_DIRECTORY;
    outputFileName=new File(AssistedCalibration.OUTPUT_DIRECTORY,"String_Node_Str").getPath();
    handleDirectory();
  }
}
Program: 150814
Project: 150814
Buggy source:
public void run(){
  gui.setObservations(calibrationAlg.getObservations());
  gui.setResults(calibrationAlg.getErrors());
  gui.setCalibration(calibrationAlg.getZhangParam());
  gui.setCorrection(intrinsic);
  gui.repaint();
}

Fixed version (ground truth):
public void run(){
  if (webcam.isOpen()) {
    System.out.println("String_Node_Str");
    webcam.close();
  }
}
Program: 150815
Project: 150815
Buggy source:
/** 
 * Converts the cluster into a grid data structure.  If its not a grid then nothing happens
 */
protected void processCluster(List<SquareNode> cluster){
  invalid=false;
  if (cluster.size() == 1) {
    SquareNode n=cluster.get(0);
    if (n.getNumberOfConnections() == 0) {
      SquareGrid grid=grids.grow();
      grid.columns=grid.rows=1;
      grid.nodes.clear();
      grid.nodes.add(n);
      return;
    }
  }
  for (int i=0; i < cluster.size(); i++) {
    cluster.get(i).graph=SquareNode.RESET_GRAPH;
  }
  SquareNode seed=findSeedNode(cluster);
  if (seed == null)   return;
  List<SquareNode> firstRow;
  if (seed.getNumberOfConnections() == 1) {
    firstRow=firstRow1(seed);
  }
 else   if (seed.getNumberOfConnections() == 2) {
    firstRow=firstRow2(seed);
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  if (invalid || firstRow == null)   return;
  List<List<SquareNode>> listRows=new ArrayList<List<SquareNode>>();
  listRows.add(firstRow);
  while (true) {
    List<SquareNode> previous=listRows.get(listRows.size() - 1);
    if (!addNextRow(previous.get(0),listRows)) {
      break;
    }
  }
  if (invalid || listRows.size() < 2)   return;
  SquareGrid grid=assembleGrid(listRows);
  if (grid == null || !checkEdgeCount(grid)) {
    grids.removeTail();
  }
}

Fixed version (ground truth):
/** 
 * Converts the cluster into a grid data structure.  If its not a grid then nothing happens
 */
protected void processCluster(List<SquareNode> cluster){
  invalid=false;
  if (cluster.size() == 1) {
    SquareNode n=cluster.get(0);
    if (n.getNumberOfConnections() == 0) {
      SquareGrid grid=grids.grow();
      grid.reset();
      grid.columns=grid.rows=1;
      grid.nodes.add(n);
      return;
    }
  }
  for (int i=0; i < cluster.size(); i++) {
    cluster.get(i).graph=SquareNode.RESET_GRAPH;
  }
  SquareNode seed=findSeedNode(cluster);
  if (seed == null)   return;
  List<SquareNode> firstRow;
  if (seed.getNumberOfConnections() == 1) {
    firstRow=firstRow1(seed);
  }
 else   if (seed.getNumberOfConnections() == 2) {
    firstRow=firstRow2(seed);
  }
 else {
    throw new RuntimeException("String_Node_Str");
  }
  if (invalid || firstRow == null)   return;
  List<List<SquareNode>> listRows=new ArrayList<List<SquareNode>>();
  listRows.add(firstRow);
  while (true) {
    List<SquareNode> previous=listRows.get(listRows.size() - 1);
    if (!addNextRow(previous.get(0),listRows)) {
      break;
    }
  }
  if (invalid || listRows.size() < 2)   return;
  SquareGrid grid=assembleGrid(listRows);
  if (grid == null || !checkEdgeCount(grid)) {
    grids.removeTail();
  }
}
Program: 150816
Project: 150816
Buggy source:
/** 
 * Converts the list of rows into a grid.  Since it is a chessboard pattern some of the grid elements will be null.
 */
private SquareGrid assembleGrid(List<List<SquareNode>> listRows){
  SquareGrid grid=grids.grow();
  List<SquareNode> row0=listRows.get(0);
  List<SquareNode> row1=listRows.get(1);
  int offset=row0.get(0).getNumberOfConnections() == 1 ? 0 : 1;
  grid.columns=row0.size() + row1.size();
  grid.rows=listRows.size();
  grid.nodes.clear();
  for (int i=0; i < grid.columns * grid.rows; i++) {
    grid.nodes.add(null);
  }
  for (int row=0; row < listRows.size(); row++) {
    List<SquareNode> list=listRows.get(row);
    int startCol=offset - row % 2 == 0 ? 0 : 1;
    int adjustedLength=grid.columns - startCol;
    if ((adjustedLength) - adjustedLength / 2 != list.size()) {
      return null;
    }
    int listIndex=0;
    for (int col=startCol; col < grid.columns; col+=2) {
      grid.set(row,col,list.get(listIndex++));
    }
  }
  return grid;
}

Fixed version (ground truth):
/** 
 * Converts the list of rows into a grid.  Since it is a chessboard pattern some of the grid elements will be null.
 */
private SquareGrid assembleGrid(List<List<SquareNode>> listRows){
  SquareGrid grid=grids.grow();
  grid.reset();
  List<SquareNode> row0=listRows.get(0);
  List<SquareNode> row1=listRows.get(1);
  int offset=row0.get(0).getNumberOfConnections() == 1 ? 0 : 1;
  grid.columns=row0.size() + row1.size();
  grid.rows=listRows.size();
  for (int i=0; i < grid.columns * grid.rows; i++) {
    grid.nodes.add(null);
  }
  for (int row=0; row < listRows.size(); row++) {
    List<SquareNode> list=listRows.get(row);
    int startCol=offset - row % 2 == 0 ? 0 : 1;
    int adjustedLength=grid.columns - startCol;
    if ((adjustedLength) - adjustedLength / 2 != list.size()) {
      return null;
    }
    int listIndex=0;
    for (int col=startCol; col < grid.columns; col+=2) {
      grid.set(row,col,list.get(listIndex++));
    }
  }
  return grid;
}
Program: 150817
Project: 150817
Buggy source:
/** 
 * Discards previous information
 */
public void reset(){
  corners=null;
  touch=null;
  graph=RESET_GRAPH;
  largestSide=0;
  for (int i=0; i < 4; i++) {
    if (edges[i] != null)     throw new RuntimeException("String_Node_Str");
    sideLengths[i]=0;
  }
}

Fixed version (ground truth):
/** 
 * Discards previous information
 */
public void reset(){
  corners=null;
  touch=null;
  center.set(-1,-1);
  largestSide=0;
  graph=RESET_GRAPH;
  for (int i=0; i < edges.length; i++) {
    if (edges[i] != null)     throw new RuntimeException("String_Node_Str");
    sideLengths[i]=0;
  }
}
Program: 150818
Project: 150818
Buggy source:
/** 
 * Reset and recycle data structures from the previous run
 */
protected void recycleData(){
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < 4; j++) {
      if (n.edges[j] != null) {
        detachEdge(n.edges[j]);
      }
    }
  }
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < 4; j++) {
      if (n.edges[j] != null)       throw new RuntimeException("String_Node_Str");
    }
  }
  nodes.reset();
  for (int i=0; i < clusters.size; i++) {
    clusters.get(i).clear();
  }
  clusters.reset();
}

Fixed version (ground truth):
/** 
 * Reset and recycle data structures from the previous run
 */
protected void recycleData(){
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < n.edges.length; j++) {
      if (n.edges[j] != null) {
        detachEdge(n.edges[j]);
      }
    }
  }
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < n.edges.length; j++) {
      if (n.edges[j] != null)       throw new RuntimeException("String_Node_Str");
    }
  }
  nodes.reset();
  for (int i=0; i < clusters.size; i++) {
    clusters.get(i).clear();
  }
  clusters.reset();
}
Program: 150819
Project: 150819
Buggy source:
/** 
 * Finds all neighbors and adds them to the graph.  Repeated until there are no more nodes to add to the graph
 */
void addToCluster(SquareNode seed,List<SquareNode> graph){
  open.clear();
  open.add(seed);
  while (!open.isEmpty()) {
    SquareNode n=open.remove(open.size() - 1);
    for (int i=0; i < 4; i++) {
      SquareEdge edge=n.edges[i];
      if (edge == null)       continue;
      SquareNode other;
      if (edge.a == n)       other=edge.b;
 else       if (edge.b == n)       other=edge.a;
 else       throw new RuntimeException("String_Node_Str");
      if (other.graph == SquareNode.RESET_GRAPH) {
        other.graph=n.graph;
        graph.add(other);
        open.add(other);
      }
 else       if (other.graph != n.graph) {
        throw new RuntimeException("String_Node_Str" + other.graph + "String_Node_Str"+ n.graph);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Finds all neighbors and adds them to the graph.  Repeated until there are no more nodes to add to the graph
 */
void addToCluster(SquareNode seed,List<SquareNode> graph){
  open.clear();
  open.add(seed);
  while (!open.isEmpty()) {
    SquareNode n=open.remove(open.size() - 1);
    for (int i=0; i < n.corners.size(); i++) {
      SquareEdge edge=n.edges[i];
      if (edge == null)       continue;
      SquareNode other;
      if (edge.a == n)       other=edge.b;
 else       if (edge.b == n)       other=edge.a;
 else       throw new RuntimeException("String_Node_Str");
      if (other.graph == SquareNode.RESET_GRAPH) {
        other.graph=n.graph;
        graph.add(other);
        open.add(other);
      }
 else       if (other.graph != n.graph) {
        throw new RuntimeException("String_Node_Str" + other.graph + "String_Node_Str"+ n.graph);
      }
    }
  }
}