nus-yam/ex-repair huggingface dataset:
Program: 150820
Project: 150820
Buggy source:
/** 
 * Goes through each node and uses a nearest-neighbor search to find the closest nodes in its local neighborhood. It then checks those to see if it should connect
 */
void connectNodes(){
  setupSearch();
  int indexCornerList=0;
  for (int indexNode=0; indexNode < nodes.size(); indexNode++) {
    SquareNode n=nodes.get(indexNode);
    for (int indexLocal=0; indexLocal < n.corners.size(); indexLocal++) {
      if (n.touch.get(indexLocal))       continue;
      double[] point=searchPoints.get(indexCornerList++);
      searchResults.reset();
      search.findNearest(point,maxCornerDistance * maxCornerDistance,maxNeighbors + 1,searchResults);
      for (int indexResults=0; indexResults < searchResults.size(); indexResults++) {
        NnData<SquareNode> neighborData=searchResults.get(indexResults);
        SquareNode neighborNode=neighborData.data;
        if (neighborNode == n)         continue;
        int neighborCornerIndex=getCornerIndex(neighborNode,neighborData.point[0],neighborData.point[1]);
        if (candidateIsMuchCloser(n,neighborNode,neighborData.distance))         considerConnect(n,indexLocal,neighborNode,neighborCornerIndex,neighborData.distance);
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Goes through each node and uses a nearest-neighbor search to find the closest nodes in its local neighborhood. It then checks those to see if it should connect
 */
void connectNodes(){
  setupSearch();
  int indexCornerList=0;
  for (int indexNode=0; indexNode < nodes.size(); indexNode++) {
    SquareNode n=nodes.get(indexNode);
    for (int indexLocal=0; indexLocal < n.corners.size(); indexLocal++) {
      if (n.touch.size > 0 && n.touch.get(indexLocal))       continue;
      double[] point=searchPoints.get(indexCornerList++);
      searchResults.reset();
      search.findNearest(point,maxCornerDistance * maxCornerDistance,maxNeighbors + 1,searchResults);
      for (int indexResults=0; indexResults < searchResults.size(); indexResults++) {
        NnData<SquareNode> neighborData=searchResults.get(indexResults);
        SquareNode neighborNode=neighborData.data;
        if (neighborNode == n)         continue;
        int neighborCornerIndex=getCornerIndex(neighborNode,neighborData.point[0],neighborData.point[1]);
        if (candidateIsMuchCloser(n,neighborNode,neighborData.distance))         considerConnect(n,indexLocal,neighborNode,neighborCornerIndex,neighborData.distance);
      }
    }
  }
}
Program: 150821
Project: 150821
Buggy source:
/** 
 * Sets up data structures for nearest-neighbor search used in   {@link #connectNodes()}
 */
private void setupSearch(){
  searchPoints.reset();
  searchSquareList.clear();
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < n.corners.size(); j++) {
      if (n.touch.get(j))       continue;
      Point2D_F64 c=n.corners.get(j);
      double[] point=searchPoints.grow();
      point[0]=c.x;
      point[1]=c.y;
      searchSquareList.add(n);
    }
  }
  search.setPoints(searchPoints.toList(),searchSquareList);
}

Fixed version (ground truth):
/** 
 * Sets up data structures for nearest-neighbor search used in   {@link #connectNodes()}
 */
private void setupSearch(){
  searchPoints.reset();
  searchSquareList.clear();
  for (int i=0; i < nodes.size(); i++) {
    SquareNode n=nodes.get(i);
    for (int j=0; j < n.corners.size(); j++) {
      if (n.touch.size > 0 && n.touch.get(j))       continue;
      Point2D_F64 c=n.corners.get(j);
      double[] point=searchPoints.grow();
      point[0]=c.x;
      point[1]=c.y;
      searchSquareList.add(n);
    }
  }
  search.setPoints(searchPoints.toList(),searchSquareList);
}
Program: 150822
Project: 150822
Buggy source:
private void findPercentiles(){
  int count=0;
  lowerIndex=0;
  for (lowerIndex=0; lowerIndex < histogram.length; lowerIndex++) {
    count+=histogram[lowerIndex];
    if (count >= lowerCount) {
      break;
    }
  }
  for (upperIndex=lowerIndex; upperIndex < histogram.length; upperIndex++) {
    count+=histogram[upperIndex];
    if (count >= upperCount) {
      break;
    }
  }
}

Fixed version (ground truth):
private void findPercentiles(){
  int count=0;
  lowerIndex=0;
  for (lowerIndex=0; lowerIndex < histogram.length && count < lowerCount; lowerIndex++) {
    count+=histogram[lowerIndex];
  }
  for (upperIndex=lowerIndex; upperIndex < histogram.length && count < upperCount; upperIndex++) {
    count+=histogram[upperIndex];
  }
}
Program: 150823
Project: 150823
Buggy source:
/** 
 * If not touching the border then the number of corners must be 4.  If touching the border there must be at least 3 corners not touching the border.  7 corners at most.  If there were 8 then all sides of a square would be touching the border.    No more than 3 corners since that's the most number of non-border corners a square can have.
 */
@Override public boolean filterPixelPolygon(List<Point2D_I32> externalUndist,List<Point2D_I32> externalDist,GrowQueue_I32 splits,boolean touchesBorder){
  if (touchesBorder) {
    if (splits.size() > 7)     return false;
    int totalRegular=0;
    for (int i=0; i < splits.size(); i++) {
      Point2D_I32 p=externalDist.get(i);
      if (!(p.x == 0 || p.y == 0 || p.x == width - 1 || p.y == height - 1))       totalRegular++;
    }
    return totalRegular <= 3;
  }
 else {
    return splits.size() == 4;
  }
}

Fixed version (ground truth):
/** 
 * If not touching the border then the number of corners must be 4.  If touching the border there must be at least 3 corners not touching the border.  7 corners at most.  If there were 8 then all sides of a square would be touching the border.    No more than 3 corners since that's the most number of non-border corners a square can have.
 */
@Override public boolean filterPixelPolygon(List<Point2D_I32> externalUndist,List<Point2D_I32> externalDist,GrowQueue_I32 splits,boolean touchesBorder){
  if (touchesBorder) {
    if (splits.size() > 7 || splits.size() <= 3)     return false;
    int totalRegular=0;
    for (int i=0; i < splits.size(); i++) {
      Point2D_I32 p=externalDist.get(splits.get(i));
      if (!(p.x == 0 || p.y == 0 || p.x == width - 1 || p.y == height - 1))       totalRegular++;
    }
    return totalRegular <= 3;
  }
 else {
    return splits.size() == 4;
  }
}
Program: 150824
Project: 150824
Buggy source:
private void renderGraph(Graphics2D g2,double scale){
  java.util.List<java.util.List<SquareNode>> graphs=getClusters();
  BasicStroke strokeWide=new BasicStroke(3);
  BasicStroke strokeNarrow=new BasicStroke(2);
  Line2D.Double l=new Line2D.Double();
  g2.setStroke(new BasicStroke(3));
  for (int i=0; i < graphs.size(); i++) {
    java.util.List<SquareNode> graph=graphs.get(i);
    int key=graphs.size() == 1 ? 0 : 255 * i / (graphs.size() - 1);
    int rgb=key << 8 | (255 - key);
    g2.setColor(new Color(rgb));
    java.util.List<SquareEdge> edges=new ArrayList<SquareEdge>();
    for (    SquareNode n : graph) {
      for (int j=0; j < 4; j++) {
        if (n.edges[j] != null && !edges.contains(n.edges[j])) {
          edges.add(n.edges[j]);
        }
      }
    }
    for (    SquareEdge e : edges) {
      Point2D_F64 a=e.a.center;
      Point2D_F64 b=e.b.center;
      l.setLine(a.x * scale,a.y * scale,b.x * scale,b.y * scale);
      g2.setColor(Color.CYAN);
      g2.setStroke(strokeWide);
      g2.draw(l);
      g2.setColor(new Color(rgb));
      g2.setStroke(strokeNarrow);
      g2.draw(l);
    }
  }
}

Fixed version (ground truth):
private void renderGraph(Graphics2D g2,double scale){
  java.util.List<java.util.List<SquareNode>> graphs=getClusters();
  BasicStroke strokeWide=new BasicStroke(3);
  BasicStroke strokeNarrow=new BasicStroke(2);
  Line2D.Double l=new Line2D.Double();
  g2.setStroke(new BasicStroke(3));
  for (int i=0; i < graphs.size(); i++) {
    java.util.List<SquareNode> graph=graphs.get(i);
    int key=graphs.size() == 1 ? 0 : 255 * i / (graphs.size() - 1);
    int rgb=key << 8 | (255 - key);
    g2.setColor(new Color(rgb));
    java.util.List<SquareEdge> edges=new ArrayList<SquareEdge>();
    for (    SquareNode n : graph) {
      for (int j=0; j < n.edges.length; j++) {
        if (n.edges[j] != null && !edges.contains(n.edges[j])) {
          edges.add(n.edges[j]);
        }
      }
    }
    for (    SquareEdge e : edges) {
      Point2D_F64 a=e.a.center;
      Point2D_F64 b=e.b.center;
      l.setLine(a.x * scale,a.y * scale,b.x * scale,b.y * scale);
      g2.setColor(Color.CYAN);
      g2.setStroke(strokeWide);
      g2.draw(l);
      g2.setColor(new Color(rgb));
      g2.setStroke(strokeNarrow);
      g2.draw(l);
    }
  }
}
Program: 150825
Project: 150825
Buggy source:
private void drawCornersInside(Graphics2D g2,double scale,Polygon2D_F64 poly){
  double x0=poly.get(0).x * scale;
  double y0=poly.get(0).y * scale;
  double x1=poly.get(1).x * scale;
  double y1=poly.get(1).y * scale;
  double x2=poly.get(2).x * scale;
  double y2=poly.get(2).y * scale;
  double x3=poly.get(3).x * scale;
  double y3=poly.get(3).y * scale;
  double dx02=x2 - x0;
  double dy02=y2 - y0;
  double dx13=x3 - x1;
  double dy13=y3 - y1;
  double fraction=0.2;
  x0+=dx02 * fraction;
  y0+=dy02 * fraction;
  x2-=dx02 * fraction;
  y2-=dy02 * fraction;
  x1+=dx13 * fraction;
  y1+=dy13 * fraction;
  x3-=dx13 * fraction;
  y3-=dy13 * fraction;
  VisualizeFeatures.drawPoint(g2,x0,y0,3,Color.RED,false);
  VisualizeFeatures.drawPoint(g2,x1,y1,3,new Color(190,0,0),false);
  VisualizeFeatures.drawPoint(g2,x2,y2,3,Color.GREEN,false);
  VisualizeFeatures.drawPoint(g2,x3,y3,3,new Color(0,190,0),false);
}

Fixed version (ground truth):
private void drawCornersInside(Graphics2D g2,double scale,Polygon2D_F64 poly){
  Color colors[]=new Color[]{Color.RED,new Color(190,0,0),Color.GREEN,new Color(0,190,0)};
  Point2D_F64 center=new Point2D_F64();
  UtilPolygons2D_F64.vertexAverage(poly,center);
  for (int i=0; i < poly.size(); i++) {
    Point2D_F64 p=poly.get(i);
    Color c=i < 4 ? colors[i] : Color.BLUE;
    double dx=p.x - center.x;
    double dy=p.y - center.y;
    double x=(center.x + dx * 0.75) * scale;
    double y=(center.y + dy * 0.75) * scale;
    VisualizeFeatures.drawPoint(g2,x,y,3,c,false);
  }
}
Program: 150826
Project: 150826
Buggy source:
@Override protected boolean process(ImageFloat32 image){
  if (controlPanel.isManual()) {
    config.thresholding.type=ThresholdType.FIXED;
    config.thresholding.fixedThreshold=controlPanel.getThresholdLevel();
  }
 else {
    config.thresholding.type=ThresholdType.LOCAL_SQUARE;
  }
  alg=FactoryCalibrationTarget.detectorChessboard(config).getAlgorithm();
  return alg.process(image);
}

Fixed version (ground truth):
@Override protected boolean process(ImageFloat32 image){
  if (controlPanel.isManual()) {
    config.thresholding.type=ThresholdType.FIXED;
    config.thresholding.fixedThreshold=controlPanel.getThresholdLevel();
  }
 else {
    config.thresholding.type=ThresholdType.LOCAL_SQUARE_BORDER;
  }
  alg=FactoryCalibrationTarget.detectorChessboard(config).getAlgorithm();
  return alg.process(image);
}
Program: 150827
Project: 150827
Buggy source:
public static void main(String args[]) throws FileNotFoundException {
  List<String> examples=new ArrayList<String>();
  examples.add("String_Node_Str");
  for (int i=1; i <= 11; i++) {
    examples.add(UtilIO.pathExample(String.format("String_Node_Str",i)));
  }
  DetectCalibrationChessboardApp app=new DetectCalibrationChessboardApp(examples);
  app.configure(7,5,false);
  app.openFile(new File(examples.get(0)));
  app.waitUntilDoneProcessing();
  ShowImages.showWindow(app,"String_Node_Str",true);
}

Fixed version (ground truth):
public static void main(String args[]) throws FileNotFoundException {
  List<String> examples=new ArrayList<String>();
  for (int i=1; i <= 11; i++) {
    examples.add(UtilIO.pathExample(String.format("String_Node_Str",i)));
  }
  DetectCalibrationChessboardApp app=new DetectCalibrationChessboardApp(examples);
  app.configure(7,5,false);
  app.openFile(new File(examples.get(0)));
  app.waitUntilDoneProcessing();
  ShowImages.showWindow(app,"String_Node_Str",true);
}
Program: 150828
Project: 150828
Buggy source:
public static ConfigThreshold local(ThresholdType type,int radius){
  if (!type.isAdaptive())   throw new IllegalArgumentException("String_Node_Str");
  if (type.isGlobal())   throw new IllegalArgumentException("String_Node_Str");
  ConfigThreshold config=new ConfigThreshold();
  config.type=type;
  config.radius=radius;
  return config;
}

Fixed version (ground truth):
public static ConfigThreshold local(ThresholdType type,int radius){
  if (!type.isAdaptive())   throw new IllegalArgumentException("String_Node_Str");
  if (type.isGlobal())   throw new IllegalArgumentException("String_Node_Str");
  if (type == ThresholdType.LOCAL_SQUARE_BORDER) {
    return new ConfigThresholdSquareBorder(radius,10,true);
  }
 else {
    ConfigThreshold config=new ConfigThreshold();
    config.type=type;
    config.radius=radius;
    return config;
  }
}
Program: 150829
Project: 150829
Buggy source:
public DemonstrationBase(List<String> exampleInputs,ImageType<T> imageType){
  super(new BorderLayout());
  createMenuBar(exampleInputs);
  this.input=imageType.createImage(1,1);
  this.imageType=imageType;
}

Fixed version (ground truth):
public DemonstrationBase(List<String> exampleInputs,ImageType<T> imageType){
  super(new BorderLayout());
  createMenuBar(exampleInputs);
  this.input=imageType.createImage(1,1);
  this.imageType=imageType;
  this.boofCopy1=imageType.createImage(1,1);
}
Program: 150830
Project: 150830
Buggy source:
protected void processImageThread(final BufferedImage buffered,final T input){
synchronized (processLock) {
    if (buffered != null)     imageCopy1=checkCopyBuffered(buffered,imageCopy1);
    if (processRunning) {
      processRequested=true;
    }
 else {
      processRequested=true;
      processRunning=true;
      new Thread(){
        @Override public void run(){
          while (true) {
synchronized (processLock) {
              if (!processRequested) {
                break;
              }
              processRequested=false;
              if (buffered != null)               imageCopy0=checkCopyBuffered(imageCopy1,imageCopy0);
            }
synchronized (waitingLock) {
              waitingToOpenImage=false;
            }
            if (buffered != null)             processImage(imageCopy0,input);
 else             processImage(null,null);
          }
synchronized (processLock) {
            processRunning=false;
          }
        }
      }
.start();
    }
  }
}

Fixed version (ground truth):
protected void processImageThread(final BufferedImage buffered,final T input){
synchronized (processLock) {
    if (processRunning) {
      if (buffered != null) {
        imageCopy1=checkCopyBuffered(buffered,imageCopy1);
        boofCopy1.setTo(input);
      }
 else       imageCopy1=null;
      processRequested=true;
      return;
    }
 else {
      processRunning=true;
      processRequested=false;
      if (buffered != null)       imageCopy0=checkCopyBuffered(buffered,imageCopy0);
 else       imageCopy0=null;
    }
  }
  new Thread(){
    @Override public void run(){
      try {
        while (true) {
synchronized (waitingLock) {
            waitingToOpenImage=false;
          }
          if (imageCopy0 != null)           processImage(imageCopy0,input);
 else           processImage(null,null);
synchronized (processLock) {
            if (!processRequested) {
              processRunning=false;
              break;
            }
            processRequested=false;
            if (imageCopy1 != null) {
              imageCopy0=checkCopyBuffered(imageCopy1,imageCopy0);
              input.setTo(boofCopy1);
            }
 else             imageCopy0=null;
          }
        }
      }
 catch (      RuntimeException e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
        System.out.println("String_Node_Str");
        if (imageCopy0 != null)         UtilImageIO.saveImage(imageCopy0,"String_Node_Str");
synchronized (processLock) {
          processRunning=false;
        }
      }
    }
  }
.start();
}
Program: 150831
Project: 150831
Buggy source:
/** 
 * Returns additional information on the polygon
 */
public Info getPolygonInfo(int which){
  return foundInfo.get(which);
}

Fixed version (ground truth):
/** 
 * Returns additional information on the polygon
 */
public FastQueue<Info> getPolygonInfo(){
  return foundInfo;
}
Program: 150832
Project: 150832
Buggy source:
/** 
 * If not touching the border then the number of corners must be 4.  If touching the border there must be at least 3 corners not touching the border.  7 corners at most.  If there were 8 then all sides of a square would be touching the border.    No more than 3 corners since that's the most number of non-border corners a square can have.
 */
@Override public boolean filterPixelPolygon(List<Point2D_I32> externalUndist,List<Point2D_I32> externalDist,GrowQueue_I32 splits,boolean touchesBorder){
  if (touchesBorder) {
    if (splits.size() > 7 || splits.size() < 3)     return false;
    int totalRegular=0;
    for (int i=0; i < splits.size(); i++) {
      Point2D_I32 p=externalDist.get(splits.get(i));
      if (!(p.x == 0 || p.y == 0 || p.x == width - 1 || p.y == height - 1))       totalRegular++;
    }
    return totalRegular <= 4;
  }
 else {
    return splits.size() == 4;
  }
}

Fixed version (ground truth):
/** 
 * If not touching the border then the number of corners must be 4.  If touching the border there must be at least 3 corners not touching the border.  7 corners at most.  If there were 8 then all sides of a square would be touching the border.    No more than 3 corners since that's the most number of non-border corners a square can have.
 */
@Override public boolean filterPixelPolygon(List<Point2D_I32> externalUndist,List<Point2D_I32> externalDist,GrowQueue_I32 splits,boolean touchesBorder){
  if (touchesBorder) {
    if (splits.size() > 7 || splits.size() < 3)     return false;
    int totalRegular=0;
    for (int i=0; i < splits.size(); i++) {
      Point2D_I32 p=externalDist.get(splits.get(i));
      if (!(p.x == 0 || p.y == 0 || p.x == width - 1 || p.y == height - 1))       totalRegular++;
    }
    return totalRegular > 0 && totalRegular <= 4;
  }
 else {
    return splits.size() == 4;
  }
}
Program: 150833
Project: 150833
Buggy source:
/** 
 * Detects chessboard in the binary image.  Square corners must be disconnected. Returns true if a chessboard was found, false otherwise.
 * @param input Original input image.
 * @param binary Binary image of chessboard
 * @return True if successful.
 */
public boolean process(T input,ImageUInt8 binary){
  boundPolygon.vertexes.reset();
  detectorSquare.process(input,binary);
  FastQueue<Polygon2D_F64> found=detectorSquare.getFoundPolygons();
  clusters=s2c.process(found.toList());
  c2g.process(clusters);
  List<SquareGrid> grids=c2g.getGrids().toList();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid grid=grids.get(i);
    if (grid.rows == numCols && grid.columns == numRows) {
      tools.transpose(grid);
    }
    if (grid.rows == numRows && grid.columns == numCols) {
      if (grid.get(0,0) == null) {
        if (grid.get(0,-1) != null) {
          tools.flipColumns(grid);
        }
 else         if (grid.get(-1,0) != null) {
          tools.flipRows(grid);
        }
 else {
          continue;
        }
      }
      if (!ensureCCW(grid))       continue;
      putIntoCanonical(grid);
      return computeCalibrationPoints(grid);
    }
  }
  return false;
}

Fixed version (ground truth):
/** 
 * Detects chessboard in the binary image.  Square corners must be disconnected. Returns true if a chessboard was found, false otherwise.
 * @param input Original input image.
 * @param binary Binary image of chessboard
 * @return True if successful.
 */
public boolean process(T input,ImageUInt8 binary){
  boundPolygon.vertexes.reset();
  detectorSquare.process(input,binary);
  FastQueue<Polygon2D_F64> found=detectorSquare.getFoundPolygons();
  FastQueue<BinaryPolygonDetector.Info> foundInfo=detectorSquare.getPolygonInfo();
  clusters=s2c.process(found.toList(),foundInfo.toList());
  c2g.process(clusters);
  List<SquareGrid> grids=c2g.getGrids().toList();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid grid=grids.get(i);
    if (grid.rows == numCols && grid.columns == numRows) {
      tools.transpose(grid);
    }
    if (grid.rows == numRows && grid.columns == numCols) {
      if (grid.get(0,0) == null) {
        if (grid.get(0,-1) != null) {
          tools.flipColumns(grid);
        }
 else         if (grid.get(-1,0) != null) {
          tools.flipRows(grid);
        }
 else {
          continue;
        }
      }
      if (!ensureCCW(grid))       continue;
      putIntoCanonical(grid);
      return computeCalibrationPoints(grid);
    }
  }
  return false;
}
Program: 150834
Project: 150834
Buggy source:
/** 
 * Processes the unordered set of squares and creates a graph out of them using prior knowledge and geometric constraints.
 * @param squares Set of squares
 * @return List of graphs.  All data structures are recycled on the next call to process().
 */
public List<List<SquareNode>> process(List<Polygon2D_F64> squares){
  recycleData();
  computeNodeInfo(squares);
  connectNodes();
  findClusters();
  return clusters.toList();
}

Fixed version (ground truth):
/** 
 * Processes the unordered set of squares and creates a graph out of them using prior knowledge and geometric constraints.
 * @param squares Set of squares
 * @return List of graphs.  All data structures are recycled on the next call to process().
 */
public List<List<SquareNode>> process(List<Polygon2D_F64> squares,List<BinaryPolygonDetector.Info> info){
  recycleData();
  computeNodeInfo(squares,info);
  connectNodes();
  findClusters();
  return clusters.toList();
}
Program: 150835
Project: 150835
Buggy source:
void computeNodeInfo(List<Polygon2D_F64> squares){
  for (int i=0; i < squares.size(); i++) {
    SquareNode n=nodes.grow();
    n.reset();
    n.corners=squares.get(i);
    UtilPoint2D_F64.mean(n.corners.vertexes.data,0,n.corners.size(),n.center);
    for (int j=0; j < n.corners.size(); j++) {
      int k=(j + 1) % n.corners.size();
      double l=n.corners.get(j).distance(n.corners.get(k));
      n.largestSide=Math.max(n.largestSide,l);
    }
  }
}

Fixed version (ground truth):
void computeNodeInfo(List<Polygon2D_F64> squares,List<BinaryPolygonDetector.Info> squaresInfo){
  for (int i=0; i < squares.size(); i++) {
    SquareNode n=nodes.grow();
    n.reset();
    Polygon2D_F64 polygon=squares.get(i);
    BinaryPolygonDetector.Info info=squaresInfo.get(i);
    UtilPoint2D_F64.mean(polygon.vertexes.data,0,polygon.size(),n.center);
    for (int j=0, k=polygon.size() - 1; j < polygon.size(); k=j, j++) {
      double l=polygon.get(j).distance(polygon.get(k));
      n.largestSide=Math.max(n.largestSide,l);
    }
    if (n.corners == null)     n.corners=new Polygon2D_F64();
 else     n.corners.vertexes.reset();
    for (int j=0; j < polygon.size(); j++) {
      if (!info.borderCorners.get(j)) {
        n.corners.vertexes.grow().set(polygon.get(j));
      }
    }
    if (n.corners.size() == 0) {
      nodes.removeTail();
    }
 else     if (n.corners.size() > 4)     throw new RuntimeException("String_Node_Str" + n.corners.size());
  }
}
Program: 150837
Project: 150837
Buggy source:
/** 
 * Tests the corner distance threshold.  two nodes should be barely within tolerance of each other with the 3rd barely not in tolerance
 */
@Test public void process_connect_threshold(){
  SquaresIntoCrossClusters alg=new SquaresIntoCrossClusters(0.2,-1);
  List<Polygon2D_F64> squares=new ArrayList<Polygon2D_F64>();
  squares.add(createSquare(5,6));
  squares.add(createSquare(6.20001,7));
  squares.add(createSquare(6.1999999,5));
  List<List<SquareNode>> clusters=alg.process(squares);
  assertEquals(2,clusters.size());
}

Fixed version (ground truth):
/** 
 * Tests the corner distance threshold.  two nodes should be barely within tolerance of each other with the 3rd barely not in tolerance
 */
@Test public void process_connect_threshold(){
  SquaresIntoCrossClusters alg=new SquaresIntoCrossClusters(0.2,-1);
  List<Polygon2D_F64> squares=new ArrayList<Polygon2D_F64>();
  squares.add(createSquare(5,6));
  squares.add(createSquare(6.20001,7));
  squares.add(createSquare(6.1999999,5));
  List<BinaryPolygonDetector.Info> squareInfo=createInfo(squares);
  List<List<SquareNode>> clusters=alg.process(squares,squareInfo);
  assertEquals(2,clusters.size());
}
Program: 150838
Project: 150838
Buggy source:
/** 
 * Create a simple perfect cluster.  Do a crude test based on number of edge histogram
 */
@Test public void process_simple(){
  SquaresIntoCrossClusters alg=new SquaresIntoCrossClusters(0.05,-1);
  List<Polygon2D_F64> squares=new ArrayList<Polygon2D_F64>();
  squares.add(createSquare(7,8));
  squares.add(createSquare(9,8));
  squares.add(createSquare(8,9));
  squares.add(createSquare(7,10));
  squares.add(createSquare(9,10));
  List<List<SquareNode>> clusters=alg.process(squares);
  assertEquals(1,clusters.size());
  List<SquareNode> cluster=clusters.get(0);
  int connections[]=new int[5];
  for (  SquareNode n : cluster) {
    connections[n.getNumberOfConnections()]++;
  }
  assertEquals(0,connections[0]);
  assertEquals(4,connections[1]);
  assertEquals(0,connections[2]);
  assertEquals(0,connections[3]);
  assertEquals(1,connections[4]);
}

Fixed version (ground truth):
/** 
 * Create a simple perfect cluster.  Do a crude test based on number of edge histogram
 */
@Test public void process_simple(){
  SquaresIntoCrossClusters alg=new SquaresIntoCrossClusters(0.05,-1);
  List<Polygon2D_F64> squares=new ArrayList<Polygon2D_F64>();
  squares.add(createSquare(7,8));
  squares.add(createSquare(9,8));
  squares.add(createSquare(8,9));
  squares.add(createSquare(7,10));
  squares.add(createSquare(9,10));
  List<BinaryPolygonDetector.Info> squareInfo=createInfo(squares);
  List<List<SquareNode>> clusters=alg.process(squares,squareInfo);
  assertEquals(1,clusters.size());
  List<SquareNode> cluster=clusters.get(0);
  int connections[]=new int[5];
  for (  SquareNode n : cluster) {
    connections[n.getNumberOfConnections()]++;
  }
  assertEquals(0,connections[0]);
  assertEquals(4,connections[1]);
  assertEquals(0,connections[2]);
  assertEquals(0,connections[3]);
  assertEquals(1,connections[4]);
}
Program: 150839
Project: 150839
Buggy source:
/** 
 * Specifies the image's intrinsic parameters and target size
 * @param width Width of the input image
 * @param height Height of the input image
 */
private void configure(int width,int height){
  labeled.reshape(width,height);
  this.minimumContour=(int)(width * minContourFraction);
  this.minimumArea=Math.pow(this.minimumContour / 4.0,2);
}

Fixed version (ground truth):
/** 
 * Specifies the image's intrinsic parameters and target size
 * @param width Width of the input image
 * @param height Height of the input image
 */
private void configure(int width,int height){
  labeled.reshape(width,height);
  this.minimumContour=(int)(width * minContourFraction);
  this.minimumArea=Math.pow(this.minimumContour / 4.0,2);
  if (helper != null)   helper.setImageShape(width,height);
}
Program: 150840
Project: 150840
Buggy source:
@Override public double getCanonicalWidth(){
  throw new RuntimeException("String_Node_Str");
}

Fixed version (ground truth):
@Override public double getCanonicalWidth(){
  return alg.getDefinition().radius * 2 + 1;
}
Program: 150841
Project: 150841
Buggy source:
public void process(float c_x,float c_y,float orientation,float radius,TupleDesc_B feature){
  float scale=radius / definition.radius;
  boolean isInside=BoofMiscOps.checkInside(blur,c_x,c_y,definition.radius * scale);
  float c=(float)Math.cos(orientation);
  float s=(float)Math.sin(orientation);
  Arrays.fill(feature.data,0);
  if (isInside) {
    for (int i=0; i < definition.samplePoints.length; i++) {
      Point2D_I32 a=definition.samplePoints[i];
      float x0=c_x + (c * a.x - s * a.y) * scale;
      float y0=c_y + (s * a.x + c * a.y) * scale;
      values[i]=interp.get_fast(x0,y0);
    }
  }
 else {
    for (int i=0; i < definition.samplePoints.length; i++) {
      Point2D_I32 a=definition.samplePoints[i];
      float x0=c_x + (c * a.x - s * a.y) * scale;
      float y0=c_y + (s * a.x + c * a.y) * scale;
      if (BoofMiscOps.checkInside(blur,x0,y0)) {
        values[i]=interp.get(x0,y0);
      }
    }
  }
  for (int i=0; i < definition.compare.length; i++) {
    Point2D_I32 comp=definition.compare[i];
    if (values[comp.x] < values[comp.y]) {
      feature.data[i / 32]|=1 << (i % 32);
    }
  }
}

Fixed version (ground truth):
public void process(float c_x,float c_y,float orientation,float radius,TupleDesc_B feature){
  float scale=(float)(radius / BoofDefaults.BRIEF_SCALE_TO_RADIUS);
  boolean isInside=BoofMiscOps.checkInside(blur,c_x,c_y,definition.radius * scale);
  float c=(float)Math.cos(orientation);
  float s=(float)Math.sin(orientation);
  Arrays.fill(feature.data,0);
  if (isInside) {
    for (int i=0; i < definition.samplePoints.length; i++) {
      Point2D_I32 a=definition.samplePoints[i];
      float x0=c_x + (c * a.x - s * a.y) * scale;
      float y0=c_y + (s * a.x + c * a.y) * scale;
      values[i]=interp.get_fast(x0,y0);
    }
  }
 else {
    for (int i=0; i < definition.samplePoints.length; i++) {
      Point2D_I32 a=definition.samplePoints[i];
      float x0=c_x + (c * a.x - s * a.y) * scale;
      float y0=c_y + (s * a.x + c * a.y) * scale;
      if (BoofMiscOps.checkInside(blur,x0,y0)) {
        values[i]=interp.get(x0,y0);
      }
    }
  }
  for (int i=0; i < definition.compare.length; i++) {
    Point2D_I32 comp=definition.compare[i];
    if (values[comp.x] < values[comp.y]) {
      feature.data[i / 32]|=1 << (i % 32);
    }
  }
}
Program: 150842
Project: 150842
Buggy source:
/** 
 * Creates a Fast Hessian blob detector used by SURF.
 * @param config Configuration for detector. Pass in null for default options.
 * @param < II > Integral Image
 * @return The feature detector
 */
public static <II extends ImageSingleBand>FastHessianFeatureDetector<II> fastHessian(ConfigFastHessian config){
  if (config == null)   config=new ConfigFastHessian();
  config.checkValidity();
  NonMaxSuppression extractor=FactoryFeatureExtractor.nonmax(new ConfigExtract(config.extractRadius,config.detectThreshold,5,true));
  return new FastHessianFeatureDetector<II>(extractor,config.maxFeaturesPerScale,config.initialSampleSize,config.initialSize,config.numberScalesPerOctave,config.numberOfOctaves,config.scaleStepSize);
}

Fixed version (ground truth):
/** 
 * Creates a Fast Hessian blob detector used by SURF.
 * @param config Configuration for detector. Pass in null for default options.
 * @param < II > Integral Image
 * @return The feature detector
 */
public static <II extends ImageSingleBand>FastHessianFeatureDetector<II> fastHessian(ConfigFastHessian config){
  if (config == null)   config=new ConfigFastHessian();
  config.checkValidity();
  NonMaxSuppression extractor=FactoryFeatureExtractor.nonmax(new ConfigExtract(config.extractRadius,config.detectThreshold,0,true));
  return new FastHessianFeatureDetector<II>(extractor,config.maxFeaturesPerScale,config.initialSampleSize,config.initialSize,config.numberScalesPerOctave,config.numberOfOctaves,config.scaleStepSize);
}
Program: 150843
Project: 150843
Buggy source:
/** 
 * <p> Computes the value of a block inside an integral image and treats pixels outside of the image as zero.  The block is defined as follows: x0 < x &le; x1 and y0 < y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static <T extends ImageSingleBand>double block_zero(T integral,int x0,int y0,int x1,int y1){
  if (integral instanceof ImageFloat32) {
    return IntegralImageOps.block_zero((ImageFloat32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageFloat64) {
    return IntegralImageOps.block_zero((ImageFloat64)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt32) {
    return IntegralImageOps.block_zero((ImageSInt32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt64) {
    return IntegralImageOps.block_zero((ImageSInt64)integral,x0,y0,x1,y1);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * <p> Computes the value of a block inside an integral image and treats pixels outside of the image as zero.  The block is defined as follows: x0 &lt; x &le; x1 and y0 &lt; y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static <T extends ImageSingleBand>double block_zero(T integral,int x0,int y0,int x1,int y1){
  if (integral instanceof ImageFloat32) {
    return IntegralImageOps.block_zero((ImageFloat32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageFloat64) {
    return IntegralImageOps.block_zero((ImageFloat64)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt32) {
    return IntegralImageOps.block_zero((ImageSInt32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt64) {
    return IntegralImageOps.block_zero((ImageSInt64)integral,x0,y0,x1,y1);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}
Program: 150844
Project: 150844
Buggy source:
/** 
 * <p> Computes the value of a block inside an integral image without bounds checking.  The block is defined as follows: x0 < x &le; x1 and y0 < y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static <T extends ImageSingleBand>double block_unsafe(T integral,int x0,int y0,int x1,int y1){
  if (integral instanceof ImageFloat32) {
    return IntegralImageOps.block_unsafe((ImageFloat32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageFloat64) {
    return IntegralImageOps.block_unsafe((ImageFloat64)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt32) {
    return IntegralImageOps.block_unsafe((ImageSInt32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt64) {
    return IntegralImageOps.block_unsafe((ImageSInt64)integral,x0,y0,x1,y1);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * <p> Computes the value of a block inside an integral image without bounds checking.  The block is defined as follows: x0 &lt; x &le; x1 and y0 &lt; y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static <T extends ImageSingleBand>double block_unsafe(T integral,int x0,int y0,int x1,int y1){
  if (integral instanceof ImageFloat32) {
    return IntegralImageOps.block_unsafe((ImageFloat32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageFloat64) {
    return IntegralImageOps.block_unsafe((ImageFloat64)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt32) {
    return IntegralImageOps.block_unsafe((ImageSInt32)integral,x0,y0,x1,y1);
  }
 else   if (integral instanceof ImageSInt64) {
    return IntegralImageOps.block_unsafe((ImageSInt64)integral,x0,y0,x1,y1);
  }
 else {
    throw new IllegalArgumentException("String_Node_Str");
  }
}
Program: 150845
Project: 150845
Buggy source:
/** 
 * <p> Computes the value of a block inside an integral image and treats pixels outside of the image as zero.  The block is defined as follows: x0 < x &le; x1 and y0 < y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static long block_zero(ImageSInt64 integral,int x0,int y0,int x1,int y1){
  return ImplIntegralImageOps.block_zero(integral,x0,y0,x1,y1);
}

Fixed version (ground truth):
/** 
 * <p> Computes the value of a block inside an integral image and treats pixels outside of the image as zero.  The block is defined as follows: x0 &lt; x &le; x1 and y0 &lt; y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static long block_zero(ImageSInt64 integral,int x0,int y0,int x1,int y1){
  return ImplIntegralImageOps.block_zero(integral,x0,y0,x1,y1);
}
Program: 150846
Project: 150846
Buggy source:
/** 
 * <p> Computes the value of a block inside an integral image without bounds checking.  The block is defined as follows: x0 < x &le; x1 and y0 < y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static long block_unsafe(ImageSInt64 integral,int x0,int y0,int x1,int y1){
  return ImplIntegralImageOps.block_unsafe(integral,x0,y0,x1,y1);
}

Fixed version (ground truth):
/** 
 * <p> Computes the value of a block inside an integral image without bounds checking.  The block is defined as follows: x0 &lt; x &le; x1 and y0 &lt; y &le; y1. </p>
 * @param integral Integral image.
 * @param x0 Lower bound of the block.  Exclusive.
 * @param y0 Lower bound of the block.  Exclusive.
 * @param x1 Upper bound of the block.  Inclusive.
 * @param y1 Upper bound of the block.  Inclusive.
 * @return Value inside the block.
 */
public static long block_unsafe(ImageSInt64 integral,int x0,int y0,int x1,int y1){
  return ImplIntegralImageOps.block_unsafe(integral,x0,y0,x1,y1);
}
Program: 150848
Project: 150848
Buggy source:
private void renderOrder(Graphics2D g2,double scale){
  java.util.List<SquareGrid> grids=getGrids();
  g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL,RenderingHints.VALUE_STROKE_PURE);
  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
  g2.setStroke(new BasicStroke(3));
  Line2D.Double l=new Line2D.Double();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid g=grids.get(i);
    SquareNode p0=null;
    for (int j=0; j < g.nodes.size(); j++) {
      SquareNode p1=g.nodes.get(j);
      if (p1 == null)       continue;
      if (p0 != null) {
        double fraction=j / ((double)g.nodes.size() - 1);
        fraction=fraction * 0.8 + 0.1;
        int red=(int)(0xFF * fraction) + (int)(0x10 * (1 - fraction));
        int green=(int)(0x00 * fraction) + (int)(0x00 * (1 - fraction));
        int blue=(int)(0x10 * fraction) + (int)(0xff * (1 - fraction));
        int lineRGB=red << 16 | green << 8 | blue;
        l.setLine(scale * p0.center.x,scale * p0.center.y,scale * p1.center.x,scale * p1.center.y);
        g2.setColor(new Color(lineRGB));
        g2.draw(l);
      }
      p0=p1;
    }
  }
}

Fixed version (ground truth):
private void renderOrder(Graphics2D g2,double scale){
  java.util.List<SquareGrid> grids=getGrids();
  g2.setStroke(new BasicStroke(3));
  Line2D.Double l=new Line2D.Double();
  for (int i=0; i < grids.size(); i++) {
    SquareGrid g=grids.get(i);
    SquareNode p0=null;
    for (int j=0; j < g.nodes.size(); j++) {
      SquareNode p1=g.nodes.get(j);
      if (p1 == null)       continue;
      if (p0 != null) {
        double fraction=j / ((double)g.nodes.size() - 1);
        fraction=fraction * 0.8 + 0.1;
        int red=(int)(0xFF * fraction) + (int)(0x10 * (1 - fraction));
        int green=(int)(0x00 * fraction) + (int)(0x00 * (1 - fraction));
        int blue=(int)(0x10 * fraction) + (int)(0xff * (1 - fraction));
        int lineRGB=red << 16 | green << 8 | blue;
        l.setLine(scale * p0.center.x,scale * p0.center.y,scale * p1.center.x,scale * p1.center.y);
        g2.setColor(new Color(lineRGB));
        g2.draw(l);
      }
      p0=p1;
    }
  }
}
Program: 150849
Project: 150849
Buggy source:
private void renderGraph(Graphics2D g2,double scale){
  java.util.List<java.util.List<SquareNode>> graphs=getClusters();
  g2.setStroke(new BasicStroke(3));
  for (int i=0; i < graphs.size(); i++) {
    java.util.List<SquareNode> graph=graphs.get(i);
    int key=graphs.size() == 1 ? 0 : 255 * i / (graphs.size() - 1);
    int rgb=key << 8 | (255 - key);
    g2.setColor(new Color(rgb));
    java.util.List<SquareEdge> edges=new ArrayList<SquareEdge>();
    for (    SquareNode n : graph) {
      for (int j=0; j < 4; j++) {
        if (n.edges[j] != null && !edges.contains(n.edges[j])) {
          edges.add(n.edges[j]);
        }
      }
    }
    for (    SquareEdge e : edges) {
      Point2D_F64 a=e.a.center;
      Point2D_F64 b=e.b.center;
      g2.drawLine((int)(a.x * scale + 0.5),(int)(a.y * scale + 0.5),(int)(b.x * scale + 0.5),(int)(b.y * scale + 0.5));
    }
  }
}

Fixed version (ground truth):
private void renderGraph(Graphics2D g2,double scale){
  java.util.List<java.util.List<SquareNode>> graphs=getClusters();
  BasicStroke strokeWide=new BasicStroke(3);
  BasicStroke strokeNarrow=new BasicStroke(2);
  Line2D.Double l=new Line2D.Double();
  g2.setStroke(new BasicStroke(3));
  for (int i=0; i < graphs.size(); i++) {
    java.util.List<SquareNode> graph=graphs.get(i);
    int key=graphs.size() == 1 ? 0 : 255 * i / (graphs.size() - 1);
    int rgb=key << 8 | (255 - key);
    g2.setColor(new Color(rgb));
    java.util.List<SquareEdge> edges=new ArrayList<SquareEdge>();
    for (    SquareNode n : graph) {
      for (int j=0; j < 4; j++) {
        if (n.edges[j] != null && !edges.contains(n.edges[j])) {
          edges.add(n.edges[j]);
        }
      }
    }
    for (    SquareEdge e : edges) {
      Point2D_F64 a=e.a.center;
      Point2D_F64 b=e.b.center;
      l.setLine(a.x * scale,a.y * scale,b.x * scale,b.y * scale);
      g2.setColor(Color.CYAN);
      g2.setStroke(strokeWide);
      g2.draw(l);
      g2.setColor(new Color(rgb));
      g2.setStroke(strokeNarrow);
      g2.draw(l);
    }
  }
}
Program: 150850
Project: 150850
Buggy source:
/** 
 * Converts the cluster into a grid data structure.  If its not a grid then nothing happens
 */
protected void processCluster(List<SquareNode> cluster){
  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");
  }
  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;
    }
  }
  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.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();
  }
}
Program: 150851
Project: 150851
Buggy source:
/** 
 * Converts all the found clusters into grids, if they are valid.
 * @param clusters List of clusters
 */
public void process(List<List<SquareNode>> clusters){
  grids.reset();
  for (int i=0; i < clusters.size(); i++) {
    processCluster(clusters.get(i));
  }
}

Fixed version (ground truth):
/** 
 * Converts all the found clusters into grids, if they are valid.
 * @param clusters List of clusters
 */
public void process(List<List<SquareNode>> clusters){
  grids.reset();
  for (int i=0; i < clusters.size(); i++) {
    if (checkPreconditions(clusters.get(i)))     processCluster(clusters.get(i));
  }
}
Program: 150852
Project: 150852
Buggy source:
/** 
 * Adds the first row to the list of rows when the seed element has two edges
 */
List<SquareNode> firstRow2(SquareNode seed){
  int indexLower=lowerEdgeIndex(seed);
  int indexUpper=addOffset(indexLower,1,4);
  List<SquareNode> listDown=new ArrayList<SquareNode>();
  List<SquareNode> list=new ArrayList<SquareNode>();
  addToRow(seed,indexUpper,1,true,listDown);
  flipAdd(listDown,list);
  list.add(seed);
  seed.graph=0;
  addToRow(seed,indexLower,-1,true,list);
  return list;
}

Fixed version (ground truth):
/** 
 * Adds the first row to the list of rows when the seed element has two edges
 */
List<SquareNode> firstRow2(SquareNode seed){
  int indexLower=lowerEdgeIndex(seed);
  int indexUpper=addOffset(indexLower,1,4);
  List<SquareNode> listDown=new ArrayList<SquareNode>();
  List<SquareNode> list=new ArrayList<SquareNode>();
  if (!addToRow(seed,indexUpper,1,true,listDown))   return null;
  flipAdd(listDown,list);
  list.add(seed);
  seed.graph=0;
  if (!addToRow(seed,indexLower,-1,true,list))   return null;
  return list;
}