nus-yam/ex-repair huggingface dataset:
Program: 140898
Project: 140898
Buggy source:
public Grid convolveToHalfSize(Grid grid){
  final int rows=grid.getRows();
  final int cols=grid.getCols();
  if (cols < 4 || rows < 4) {
    return null;
  }
  final int newCols=cols / 2 + cols % 2;
  final int newRows=rows / 2 + rows % 2;
  Grid convGrid=new Grid(newCols,newRows,grid.getCellSize() * 2);
  convGrid.setWest(grid.getWest());
  convGrid.setSouth(grid.getSouth());
  convGrid.setPrjFileContent(grid.getPrjFileContent());
  for (int c=0; c < cols; c+=2) {
    float g=this.convolveBorder(grid,c,0);
    convGrid.setValue(g,c / 2,0);
    g=this.convolveBorder(grid,c,rows - 1);
    convGrid.setValue(g,c / 2,rows / 2 - 1 + rows % 2);
  }
  for (int r=0; r < rows; r+=2) {
    float g=this.convolveBorder(grid,0,r);
    convGrid.setValue(g,0,r / 2);
    g=this.convolveBorder(grid,cols - 1,r);
    convGrid.setValue(g,cols / 2 - 1 + cols % 2,r / 2);
  }
  for (int r=2; r < rows - 2; r+=2) {
    for (int c=2; c < cols - 2; c+=2) {
      final float g=this.convolve(grid,c,r);
      convGrid.setValue(g,c / 2,r / 2);
    }
  }
  return convGrid;
}

Fixed version (ground truth):
public Grid convolveToHalfSize(Grid grid){
  final int cols=grid.getCols();
  final int rows=grid.getRows();
  int[] newDimension=nextSmallerSize(cols,rows);
  if (newDimension == null) {
    return null;
  }
  final int newCols=newDimension[0];
  final int newRows=newDimension[1];
  Grid convGrid=new Grid(newCols,newRows,grid.getCellSize() * 2);
  convGrid.setWest(grid.getWest());
  convGrid.setSouth(grid.getSouth());
  convGrid.setPrjFileContent(grid.getPrjFileContent());
  for (int c=0; c < cols; c+=2) {
    float g=this.convolveBorder(grid,c,0);
    convGrid.setValue(g,c / 2,0);
    g=this.convolveBorder(grid,c,rows - 1);
    convGrid.setValue(g,c / 2,rows / 2 - 1 + rows % 2);
  }
  for (int r=0; r < rows; r+=2) {
    float g=this.convolveBorder(grid,0,r);
    convGrid.setValue(g,0,r / 2);
    g=this.convolveBorder(grid,cols - 1,r);
    convGrid.setValue(g,cols / 2 - 1 + cols % 2,r / 2);
  }
  for (int r=2; r < rows - 2; r+=2) {
    for (int c=2; c < cols - 2; c+=2) {
      final float g=this.convolve(grid,c,r);
      convGrid.setValue(g,c / 2,r / 2);
    }
  }
  return convGrid;
}
Program: 140899
Project: 140899
Buggy source:
/** 
 * Returns the dimensions of all Gaussian pyramid levels that are created when the constructor of this class is called with the passed grid.
 * @param grid
 * @return two dimensional array: cols x rows of largest level, cols x rowsof second level, etc.
 */
public static int[][] getPyramidSizeForGrid(Grid grid){
  assert(grid != null);
  int nbrPyramidLevels=getPyramidLevelsForGrid(grid);
  int[][] dimensions=new int[nbrPyramidLevels][2];
  int cols=grid.getCols();
  int rows=grid.getRows();
  for (int i=0; i < nbrPyramidLevels; i++) {
    if (validDimension(cols,rows) == false) {
      break;
    }
    dimensions[i][0]=cols;
    dimensions[i][1]=rows;
    cols/=2;
    rows/=2;
  }
  return dimensions;
}

Fixed version (ground truth):
/** 
 * Returns the dimensions of all Gaussian pyramid levels that are created when the constructor of this class is called with the passed grid.
 * @param grid
 * @return two dimensional array: cols x rows of largest level, cols x rowsof second level, etc.
 */
public static int[][] getPyramidSizeForGrid(Grid grid){
  assert(grid != null);
  ArrayList<int[]> dimensions=new ArrayList<>();
  int[] dim={grid.getCols(),grid.getRows()};
  dimensions.add(dim);
  for (; ; ) {
    dim=Convolution5x5.nextSmallerSize(dim[0],dim[1]);
    if (dim == null) {
      break;
    }
    dimensions.add(dim);
  }
  return dimensions.toArray(new int[dimensions.size()][2]);
}
Program: 140900
Project: 140900
Buggy source:
/** 
 * Returns the number of levels in a Gaussian pyramid for a given grid.
 * @param grid
 * @return number of levels
 */
public static int getPyramidLevelsForGrid(Grid grid){
  assert(grid != null);
  int cols=grid.getCols();
  int rows=grid.getRows();
  int nbrPyramidLevels=0;
  for (; ; ) {
    if (validDimension(cols,rows) == false) {
      break;
    }
    ++nbrPyramidLevels;
    cols/=2;
    rows/=2;
  }
  return nbrPyramidLevels;
}

Fixed version (ground truth):
/** 
 * Returns the number of levels in a Gaussian pyramid for a given grid.
 * @param grid
 * @return number of levels
 */
public static int getPyramidLevelsForGrid(Grid grid){
  return getPyramidSizeForGrid(grid).length;
}
Program: 140901
Project: 140901
Buggy source:
public GaussianPyramid(Grid grid){
  ArrayList<Grid> grids=new ArrayList<>();
  grids.add(grid);
  Convolution5x5 conv=new Convolution5x5();
  for (; ; ) {
    if (grid == null) {
      break;
    }
    int cols=grid.getCols() / 2;
    int rows=grid.getRows() / 2;
    if (validDimension(cols,rows) == false) {
      break;
    }
    grid=conv.convolveToHalfSize(grid);
    grids.add(grid);
  }
  pyramid=grids.toArray(new Grid[grids.size()]);
}

Fixed version (ground truth):
public GaussianPyramid(Grid grid){
  ArrayList<Grid> grids=new ArrayList<>();
  grids.add(grid);
  Convolution5x5 conv=new Convolution5x5();
  for (; ; ) {
    grid=conv.convolveToHalfSize(grid);
    if (grid == null) {
      break;
    }
 else {
      grids.add(grid);
    }
  }
  pyramid=grids.toArray(new Grid[grids.size()]);
}
Program: 140903
Project: 140903
Buggy source:
protected boolean isValid(){
  return cols > 0 && rows > 0 && cellSize > 0 && !Double.isNaN(west) && !Double.isNaN(south);
}

Fixed version (ground truth):
/** 
 * Returns whether valid values have been found in the header.
 * @return true if the header has been successfully read and if it containsvalid values.
 */
protected boolean isValid(){
  return cols > 0 && rows > 0 && cellSize > 0 && !Double.isNaN(west) && !Double.isNaN(south);
}
Program: 140904
Project: 140904
Buggy source:
String readHeader(BufferedReader reader,boolean stopOnFirstUnknownLine) throws IOException {
  cols=rows=0;
  west=south=cellSize=Double.NaN;
  noDataValue=Float.NaN;
  String line;
  while ((line=reader.readLine()) != null) {
    StringTokenizer tokenizer=new StringTokenizer(line,"String_Node_Str");
    String str=tokenizer.nextToken().trim().toLowerCase();
    if (str.equals("String_Node_Str")) {
      cols=Integer.parseInt(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      rows=Integer.parseInt(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str") || str.equals("String_Node_Str")) {
      west=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str") || str.equals("String_Node_Str")) {
      south=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      cellSize=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.startsWith("String_Node_Str")) {
      noDataValue=Float.parseFloat(tokenizer.nextToken());
    }
 else {
      if (stopOnFirstUnknownLine) {
        return line;
      }
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * Reads header line-by-line until the first grid line or an unknown header line is encountered.
 * @param reader read from this
 * @return The first grid line or the unknown header line.
 * @throws IOException
 */
String readHeader(BufferedReader reader) throws IOException {
  cols=rows=0;
  west=south=cellSize=Double.NaN;
  noDataValue=Float.NaN;
  boolean xCornerCoordinates=false, yCornerCoordinates=false;
  String line;
  while ((line=reader.readLine()) != null) {
    StringTokenizer tokenizer=new StringTokenizer(line,"String_Node_Str");
    String str=tokenizer.nextToken().trim().toLowerCase();
    if (str.equals("String_Node_Str")) {
      cols=Integer.parseInt(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      rows=Integer.parseInt(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      west=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      west=Double.parseDouble(tokenizer.nextToken());
      xCornerCoordinates=true;
    }
 else     if (str.equals("String_Node_Str")) {
      south=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.equals("String_Node_Str")) {
      south=Double.parseDouble(tokenizer.nextToken());
      yCornerCoordinates=true;
    }
 else     if (str.equals("String_Node_Str")) {
      cellSize=Double.parseDouble(tokenizer.nextToken());
    }
 else     if (str.startsWith("String_Node_Str")) {
      noDataValue=Float.parseFloat(tokenizer.nextToken());
    }
 else {
      if (xCornerCoordinates) {
        west+=cellSize / 2;
      }
      if (yCornerCoordinates) {
        south+=cellSize / 2;
      }
      return line;
    }
  }
  cols=rows=0;
  west=south=cellSize=Double.NaN;
  return null;
}
Program: 140906
Project: 140906
Buggy source:
@Override protected void operateCell(Grid src,Grid dst,int col,int row){
  int nCols=src.getCols();
  int nRows=src.getRows();
  if (maskGrid.getValue(col,row) == maskValue) {
    float total=0;
    int counter=0;
    for (int i=0; i < 9; i++) {
      int c=col + DX[i];
      int r=row + DY[i];
      if (c >= 0 && c < nCols && r >= 0 && r < nRows) {
        float v=src.getValue(c,r);
        if (!Float.isNaN(v)) {
          ++counter;
          total+=v;
        }
      }
    }
    dst.setValue(total / counter,col,row);
  }
}

Fixed version (ground truth):
@Override protected void operateCell(Grid src,Grid dst,int col,int row){
  int nCols=src.getCols();
  int nRows=src.getRows();
  if (maskGrid.getValue(col,row) == maskValue) {
    float total=0;
    int counter=0;
    for (int i=0; i < 9; i++) {
      int c=col + DX[i];
      int r=row + DY[i];
      if (c >= 0 && c < nCols && r >= 0 && r < nRows) {
        float v=src.getValue(c,r);
        if (!Float.isNaN(v)) {
          ++counter;
          total+=v;
        }
      }
    }
    dst.setValue(counter == 0 ? Float.NaN : total / counter,col,row);
  }
}
Program: 140908
Project: 140908
Buggy source:
@Override protected float valueForPoint(LineString line,int pointID,boolean rightSide){
  double illuminationAngle=illuminationDirection(line,pointID);
  double illuminationX=Math.cos(illuminationAngle);
  double illuminationY=Math.sin(illuminationAngle);
  if (pointID == line.getNumPoints() - 1) {
    pointID--;
  }
  Point p1=line.getPointN(pointID);
  Point p2=line.getPointN(pointID + 1);
  double dx=p2.getX() - p1.getX();
  double dy=p2.getY() - p1.getY();
  double length=Math.sqrt(dx * dx + dy * dy);
  double dirX=dx / length;
  double dirY=dy / length;
  if (Double.isNaN(dirX) || Double.isNaN(dirY)) {
    return Float.NaN;
  }
  double temp=dx;
  if (rightSide) {
    dx=-dy;
    dy=temp;
  }
 else {
    dx=dy;
    dy=-temp;
  }
  double cosAngle=(dx * illuminationX) + (dy * illuminationY);
  double aspectShade=(cosAngle + 1) / 2;
  int gray=(int)Math.round(255 * aspectShade);
  Number ridgeLineFlag=line.getAttribute("String_Node_Str");
  if (ridgeLineFlag != null) {
    gray=255 - gray;
  }
  return gray;
}

Fixed version (ground truth):
@Override protected float valueForPoint(LineString line,int pointID,boolean rightSide){
  double illuminationAngle=illuminationDirection(line,pointID);
  double illuminationX=Math.cos(illuminationAngle);
  double illuminationY=Math.sin(illuminationAngle);
  if (pointID == line.getNumPoints() - 1) {
    pointID--;
  }
  Point p1=line.getPointN(pointID);
  Point p2=line.getPointN(pointID + 1);
  double dx=p2.getX() - p1.getX();
  double dy=p2.getY() - p1.getY();
  double length=Math.sqrt(dx * dx + dy * dy);
  double dirX=dx / length;
  double dirY=dy / length;
  if (Double.isNaN(dirX) || Double.isNaN(dirY)) {
    return Float.NaN;
  }
  double temp=dirX;
  if (rightSide) {
    dirX=-dirY;
    dirY=temp;
  }
 else {
    dirX=dirY;
    dirY=-temp;
  }
  double cosAngle=(dirX * illuminationX) + (dirY * illuminationY);
  double aspectShade=(cosAngle + 1) / 2;
  int gray=(int)Math.round(255 * aspectShade);
  Number ridgeLineFlag=line.getAttribute("String_Node_Str");
  if (ridgeLineFlag != null) {
    gray=255 - gray;
  }
  return gray;
}
Program: 140909
Project: 140909
Buggy source:
/** 
 * Write an image to a file using the fileFormat at filePath. Also writes a world file and a projection file. This is called by doInBackground, so derived classes must not access the Event Dispatching Thread.
 * @param image image to write
 * @param grid a world file will be written such that the image covers thearea of this grid.
 * @throws Exception typically an IOException when the file cannot bewritten.
 */
protected void writeImage(BufferedImage image,Grid grid) throws Exception {
  File file=null;
  try {
    setIndeterminate(true);
    String fileName=FileUtils.getFileName(filePath);
    setMessage("String_Node_Str" + fileName + "String_Node_Str");
    file=new File(filePath);
    ImageIO.write(image,fileFormat,file);
    String worldFilePath=WorldFileExporter.constructPath(filePath);
    double cellSize=grid.getCellSize();
    double west=grid.getWest() - cellSize / 2;
    double north=grid.getNorth() + cellSize / 2;
    WorldFileExporter.writeWorldFile(worldFilePath,cellSize,west,north);
    WKTProjectionFile.write(grid.getPrjFileContent(),filePath);
  }
 catch (  IOException exc) {
    if (file != null && file.exists()) {
      file.delete();
    }
    throw exc;
  }
}

Fixed version (ground truth):
/** 
 * Write an image to a file using the fileFormat at filePath. Also writes a world file and a projection file. This is called by doInBackground, so the method is final such that derived classes do not access the Event Dispatching Thread.
 * @param image image to write
 * @param grid a world file will be written such that the image covers thearea of this grid.
 * @throws Exception typically an IOException when the file cannot bewritten.
 */
final protected void writeImage(BufferedImage image,Grid grid) throws Exception {
  File file=null;
  try {
    setIndeterminate(true);
    String fileName=FileUtils.getFileName(filePath);
    setMessage("String_Node_Str" + fileName + "String_Node_Str");
    file=new File(filePath);
    ImageIO.write(image,fileFormat,file);
    String worldFilePath=WorldFileExporter.constructPath(filePath);
    double cellSize=grid.getCellSize();
    double west=grid.getWest() - cellSize / 2;
    double north=grid.getNorth() + cellSize / 2;
    WorldFileExporter.writeWorldFile(worldFilePath,cellSize,west,north);
    WKTProjectionFile.write(grid.getPrjFileContent(),filePath);
  }
 catch (  IOException exc) {
    if (file != null && file.exists()) {
      file.delete();
    }
    throw exc;
  }
}
Program: 140912
Project: 140912
Buggy source:
/** 
 * Bilinear interpolation. See http://www.geovista.psu.edu/sites/geocomp99/Gc99/082/gc_082.htm "What's the point? Interpolation and extrapolation with a regular grid DEM"
 * @param x horizontal coordinate
 * @param y vertical coordinate
 * @return interpolated value
 */
public final float getBilinearInterpol(double x,double y){
  float h1, h2, h3, h4;
  final int rows=grid.length;
  final int cols=grid[0].length;
  final double north=south + (rows - 1) * cellSize;
  final double dx=(x - west) / cellSize;
  final int col=(int)(dx);
  final int row=(int)((north - y) / cellSize);
  if (col < 0 || col > cols - 1 || row < 0 || row > rows - 1) {
    return Float.NaN;
  }
  if (col == cols - 1) {
    if (row == rows - 1) {
      return grid[rows - 1][cols - 1];
    }
    return verticalBilinearInterpol(y,row,col);
  }
  if (row == rows - 1) {
    float leftH=grid[row][col];
    float rightH=grid[row][col + 1];
    return (float)(dx * (rightH - leftH) + leftH);
  }
  final double relX=dx - col;
  final double relY=(y - south) / cellSize - rows + row + 2;
  h1=grid[row + 1][col];
  h2=grid[row + 1][col + 1];
  h3=grid[row][col];
  h4=grid[row][col + 1];
  return (float)(h1 + (h2 - h1) * relX + (h3 - h1) * relY + (h1 - h2 - h3 + h4) * relX * relY);
}

Fixed version (ground truth):
/** 
 * Bilinear interpolation. See http://www.geovista.psu.edu/sites/geocomp99/Gc99/082/gc_082.htm "What's the point? Interpolation and extrapolation with a regular grid DEM"
 * @param x horizontal coordinate
 * @param y vertical coordinate
 * @return interpolated value
 */
public final float getBilinearInterpol(double x,double y){
  float h1, h2, h3, h4;
  final int rows=grid.length;
  final int cols=grid[0].length;
  final double north=south + (rows - 1) * cellSize;
  final double dx=(x - west) / cellSize;
  final int col=(int)(dx);
  final int row=(int)((north - y) / cellSize);
  if (col < 0 || col > cols - 1 || row < 0 || row > rows - 1) {
    return Float.NaN;
  }
  if (col == cols - 1) {
    if (row == rows - 1) {
      return grid[rows - 1][cols - 1];
    }
    return verticalBilinearInterpol(y,row,col);
  }
  if (row == rows - 1) {
    float leftH=grid[row][col];
    float rightH=grid[row][col + 1];
    return (float)((dx - col) * (rightH - leftH) + leftH);
  }
  final double relX=dx - col;
  final double relY=(y - south) / cellSize - rows + row + 2;
  h1=grid[row + 1][col];
  h2=grid[row + 1][col + 1];
  h3=grid[row][col];
  h4=grid[row][col + 1];
  return (float)(h1 + (h2 - h1) * relX + (h3 - h1) * relY + (h1 - h2 - h3 + h4) * relX * relY);
}
Program: 140913
Project: 140913
Buggy source:
/** 
 * Creates a new instance of Grid.
 * @param cols The number of vertical columns in the new grid.
 * @param rows The number of horizontal rows in the new grid.
 * @param cellSize The size between two rows or columns.
 */
public Grid(int cols,int rows,double cellSize){
  this(cols,rows);
  if (cols < 3 || rows < 3) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (cellSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.cellSize=cellSize;
}

Fixed version (ground truth):
/** 
 * Creates a new instance of Grid.
 * @param cols The number of vertical columns in the new grid.
 * @param rows The number of horizontal rows in the new grid.
 * @param cellSize The size between two rows or columns.
 */
public Grid(int cols,int rows,double cellSize){
  this(cols,rows);
  if (cellSize <= 0) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.cellSize=cellSize;
}
Program: 140914
Project: 140914
Buggy source:
private float verticalBilinearInterpol(double y,int topRow,int col){
  float topH=grid[topRow][col];
  float bottomH=grid[topRow + 1][col];
  double w=(getNorth() - y) / cellSize;
  return (float)(w * (topH - bottomH) + bottomH);
}

Fixed version (ground truth):
private float verticalBilinearInterpol(double y,int topRow,int col){
  float topH=grid[topRow][col];
  float bottomH=grid[topRow + 1][col];
  double w=(getNorth() - y) % cellSize;
  return (float)(w * (topH - bottomH) + bottomH);
}
Program: 140915
Project: 140915
Buggy source:
private double illuminationAzimuth(double dx,double dy){
  final double illuminationAzimuth=Math.toRadians(model.getAzimuth());
  double illuminationAngle=illuminationAzimuth;
  final double maxDeviation=Math.toRadians(30);
  double aspect=Math.atan2(dx,-dy);
  if (aspect < 0) {
    aspect+=Math.PI;
  }
  double angleDiff=illuminationAngle - aspect;
  if (angleDiff <= 0) {
    angleDiff+=Math.PI;
  }
  double angleAdjustment;
  if (angleDiff >= Math.PI / 2) {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff + 2 * maxDeviation;
  }
 else {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff;
  }
  return illuminationAngle + angleAdjustment;
}

Fixed version (ground truth):
/** 
 * Computes an adjusted illumination angle for a given line orientation.
 * @param dx
 * @param dy
 * @return
 */
private double illuminationAzimuth(double dx,double dy){
  final double illuminationAzimuth=Math.toRadians(model.getAzimuth());
  double illuminationAngle=Math.PI / 2 - illuminationAzimuth;
  illuminationAngle=GeometryUtils.trimAngle(illuminationAngle);
  double aspect=Math.atan2(dx,-dy);
  if (aspect < 0) {
    aspect+=Math.PI;
  }
  double angleDiff=illuminationAngle - aspect;
  if (angleDiff <= 0) {
    angleDiff+=Math.PI;
  }
  double maxDeviation=Math.toRadians(30);
  double angleAdjustment;
  if (angleDiff >= Math.PI / 2) {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff + 2 * maxDeviation;
  }
 else {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff;
  }
  double adjustedAngle=illuminationAngle + angleAdjustment;
  return Math.PI / 2 - adjustedAngle;
}
Program: 140916
Project: 140916
Buggy source:
public LightDirectionInterpolationOperator(Model model,GeometryCollection lines){
  this.model=model;
  genDirectionPoints(lines);
}

Fixed version (ground truth):
public LightDirectionInterpolationOperator(Model model,GeometryCollection lines){
  this.model=model;
  model.lightDirectionPoints=new GeometryCollection();
  for (int i=0; i < lines.getNumGeometries(); ++i) {
    LineString line=(LineString)lines.getGeometryN(i);
    for (int pointNum=0; pointNum < line.getNumPoints() - 1; ++pointNum) {
      Point p0=line.getPointN(pointNum);
      Point p1=line.getPointN(pointNum + 1);
      double dx=p1.getX() - p0.getX();
      double dy=p1.getY() - p0.getY();
      double length=Math.sqrt(dx * dx + dy * dy);
      double dirX=dx / length;
      double dirY=dy / length;
      if (Double.isNaN(dirX) || Double.isNaN(dirY)) {
        continue;
      }
      double lineOrientation=Math.atan2(dy,dx);
      System.out.println(Math.toDegrees(lineOrientation));
      double lightDir=illuminationAzimuth(dirX,dirY);
      double x=p0.getX() + dx / 2;
      double y=p0.getY() + dy / 2;
      DirectionPoint dirPoint=new DirectionPoint(x,y,lightDir);
      model.lightDirectionPoints.addGeometry(dirPoint);
    }
  }
}
Program: 140917
Project: 140917
Buggy source:
@Override public void paint(Graphics2D g2d,double west,double north,double scale){
  double x=getX();
  double y=getY();
  double dx=Math.sin(azimuthRad) * LINE_LENGTH_PX / 2 / scale;
  double dy=Math.cos(azimuthRad) * LINE_LENGTH_PX / 2 / scale;
  double x0=x - dx;
  double y0=y - dy;
  double x1=x + dx;
  double y1=y + dy;
  GeneralPath.Double path=new GeneralPath.Double();
  path.moveTo(scale * (x0 - west),scale * (north - y0));
  path.lineTo(scale * (x1 - west),scale * (north - y1));
  g2d.draw(path);
  double a0x=-ARROW_WIDTH_PX / 2 / scale;
  double a0y=(LINE_LENGTH_PX - ARROW_LENGTH_PX) / 2 / scale;
  double a1x=0;
  double a1y=LINE_LENGTH_PX / 2 / scale;
  double a2x=ARROW_WIDTH_PX / 2 / scale;
  double a2y=(LINE_LENGTH_PX - ARROW_LENGTH_PX) / 2 / scale;
  double cos=Math.cos(-azimuthRad);
  double sin=Math.sin(-azimuthRad);
  double b0x=cos * a0x - sin * a0y;
  double b0y=sin * a0x + cos * a0y;
  double b1x=cos * a1x - sin * a1y;
  double b1y=sin * a1x + cos * a1y;
  double b2x=cos * a2x - sin * a2y;
  double b2y=sin * a2x + cos * a2y;
  path=new GeneralPath.Double();
  path.moveTo(scale * (x + b0x - west),scale * (north - (b0y + y)));
  path.lineTo(scale * (x + b1x - west),scale * (north - (b1y + y)));
  path.lineTo(scale * (x + b2x - west),scale * (north - (b2y + y)));
  g2d.draw(path);
}

Fixed version (ground truth):
@Override public void paint(Graphics2D g2d,double west,double north,double scale){
  double x=getX();
  double y=getY();
  double dx=Math.sin(azimuthRad) * LINE_LENGTH_PX / 2 / scale;
  double dy=Math.cos(azimuthRad) * LINE_LENGTH_PX / 2 / scale;
  double x0=x - dx;
  double y0=y - dy;
  double x1=x + dx;
  double y1=y + dy;
  GeneralPath.Double path=new GeneralPath.Double();
  path.moveTo(scale * (x0 - west),scale * (north - y0));
  path.lineTo(scale * (x1 - west),scale * (north - y1));
  g2d.draw(path);
  double a0x=-ARROW_WIDTH_PX / 2 / scale;
  double a0y=(LINE_LENGTH_PX - ARROW_LENGTH_PX) / 2 / scale;
  double a1x=0;
  double a1y=LINE_LENGTH_PX / 2 / scale;
  double a2x=ARROW_WIDTH_PX / 2 / scale;
  double a2y=(LINE_LENGTH_PX - ARROW_LENGTH_PX) / 2 / scale;
  double cos=Math.cos(Math.PI - azimuthRad);
  double sin=Math.sin(Math.PI - azimuthRad);
  double b0x=cos * a0x - sin * a0y;
  double b0y=sin * a0x + cos * a0y;
  double b1x=cos * a1x - sin * a1y;
  double b1y=sin * a1x + cos * a1y;
  double b2x=cos * a2x - sin * a2y;
  double b2y=sin * a2x + cos * a2y;
  path=new GeneralPath.Double();
  path.moveTo(scale * (x + b0x - west),scale * (north - (b0y + y)));
  path.lineTo(scale * (x + b1x - west),scale * (north - (b1y + y)));
  path.lineTo(scale * (x + b2x - west),scale * (north - (b2y + y)));
  g2d.draw(path);
}
Program: 140919
Project: 140919
Buggy source:
private void renderGeometryCollection(GeometryCollection features,Color color,float lineWidth){
  if (features != null) {
    Graphics2D g2d=(Graphics2D)displayImage.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(color);
    double scale=displayImage.getWidth() / (model.getGrid().getEast() - model.getGrid().getWest());
    System.out.println("String_Node_Str" + scale);
    g2d.setStroke(new BasicStroke(lineWidth * (displayImage.getWidth() / model.getGrid().getCols())));
    double west=model.getGrid().getWest();
    double north=model.getGrid().getNorth();
    features.paint(g2d,west,north,scale);
  }
}

Fixed version (ground truth):
private void renderGeometryCollection(GeometryCollection features,Color color,float lineWidth){
  if (features != null) {
    Graphics2D g2d=(Graphics2D)displayImage.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(color);
    double scale=displayImage.getWidth() / (model.getGrid().getEast() - model.getGrid().getWest());
    float strokeWidth=lineWidth * (displayImage.getWidth() / model.getGrid().getCols());
    g2d.setStroke(new BasicStroke(strokeWidth,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER));
    double west=model.getGrid().getWest();
    double north=model.getGrid().getNorth();
    features.paint(g2d,west,north,scale);
  }
}
Program: 140920
Project: 140920
Buggy source:
public void dev(BufferedImage img){
  FlowDirectionOperator mblDop=new FlowDirectionOperator();
  Grid dir=mblDop.operate(model.getFilteredGrid());
  MaximumBranchLengthOperator mblOp=new MaximumBranchLengthOperator();
  Grid mbl=mblOp.operate(dir);
  BinaryThresholdOperator thresholder=new BinaryThresholdOperator(100);
  Grid thresholded=thresholder.operate(mbl);
  SkeletonizerOperator mblSkel=new SkeletonizerOperator();
  Grid skeleton=thresholded;
  do {
    mblSkel.operate(skeleton,null);
  }
 while (!mblSkel.isDone());
  Grid resultGrid=skeleton;
  new GridToImageOperator(resultGrid,img).operate(resultGrid);
}

Fixed version (ground truth):
public void dev(BufferedImage img){
  FlowDirectionOperator mblDop=new FlowDirectionOperator();
  Grid dir=mblDop.operate(model.getFilteredGrid());
  MaximumBranchLengthsOperator mblOp=new MaximumBranchLengthsOperator();
  Grid mbl=mblOp.operate(dir);
  BinaryThresholdOperator thresholder=new BinaryThresholdOperator(100);
  Grid thresholded=thresholder.operate(mbl);
  SkeletonizerOperator mblSkel=new SkeletonizerOperator();
  Grid skeleton=thresholded;
  skeleton=mblSkel.operate(skeleton);
  Grid resultGrid=skeleton;
  new GridToImageOperator(resultGrid,img).operate(resultGrid);
}
Program: 140921
Project: 140921
Buggy source:
/** 
 * Multi-threaded operation. Requires a direction grid created with FlowDirectionOperator.
 * @param dir the direction grid
 * @param dst a grid to store maximum branch lengths
 */
@Override protected void operate(Grid dir,Grid dst,int startRow,int endRow){
  final int nCols=dir.getCols();
  final int nRows=dir.getRows();
  int adjI, adjJ;
  int[] allowedDirs={2,5,7,8};
  HashMap<Integer,Float> travelled=new HashMap<>(nRows + nCols);
  for (int row=startRow; row < endRow; ++row) {
    if (reportProgress(startRow,endRow,row) == false) {
      return;
    }
    for (int col=0; col < nCols; ++col) {
      float maxBranchLength=0;
      for (      int n : allowedDirs) {
        adjI=this.dY[n] + row;
        adjJ=this.dX[n] + col;
        if (adjI >= 0 && adjJ >= 0 && adjI < nRows && adjJ < nCols) {
          float l=branchLength(travelled,dir,col,row,adjJ,adjI);
          travelled.clear();
          if (l > maxBranchLength) {
            maxBranchLength=l;
          }
        }
      }
      dst.setValue(maxBranchLength,col,row);
    }
  }
}

Fixed version (ground truth):
/** 
 * Multi-threaded operation. Requires a direction grid created with FlowDirectionOperator.
 * @param dir the direction grid
 * @param dst a grid to store maximum branch lengths
 */
@Override protected void operate(Grid dir,Grid dst,int startRow,int endRow){
  final int nCols=dir.getCols();
  final int nRows=dir.getRows();
  int adjI, adjJ;
  int[] allowedDirs={0,1,2,3,5,6,7,8};
  HashMap<Integer,Float> travelled=new HashMap<>(nRows + nCols);
  for (int row=startRow; row < endRow; ++row) {
    if (reportProgress(startRow,endRow,row) == false) {
      return;
    }
    for (int col=0; col < nCols; ++col) {
      float maxBranchLength=0;
      for (      int n : allowedDirs) {
        adjI=this.dY[n] + row;
        adjJ=this.dX[n] + col;
        if (adjI >= 0 && adjJ >= 0 && adjI < nRows && adjJ < nCols) {
          float l=branchLength(travelled,dir,col,row,adjJ,adjI);
          travelled.clear();
          if (l > maxBranchLength) {
            maxBranchLength=l;
          }
        }
      }
      dst.setValue(maxBranchLength,col,row);
    }
  }
}
Program: 140922
Project: 140922
Buggy source:
private void updateMaxBranchLengthGrid(ProgressIndicator progressIndicator){
  if (localLightDirection) {
    boolean initialIgnoreProgress=progressIndicator.isIgnoreProgress();
    try {
      FlowDirectionOperator flowDirectionOp=new FlowDirectionOperator();
      flowDirectionOp.setProgressIndicator(progressIndicator);
      progressIndicator.setIgnoreProgress(true);
      progressIndicator.setMessage("String_Node_Str");
      Grid flowDirections=flowDirectionOp.operate(generalizedGrid);
      if (generalizedGrid.sameGeometry(maxBranchLenghtsGrid) == false) {
        maxBranchLenghtsGrid=Grid.shallowCopy(generalizedGrid);
      }
      MaximumBranchLengthOperator mbl=new MaximumBranchLengthOperator();
      mbl.setProgressIndicator(progressIndicator);
      progressIndicator.setIgnoreProgress(false);
      progressIndicator.setMessage("String_Node_Str");
      mbl.operate(flowDirections,maxBranchLenghtsGrid);
    }
  finally {
      progressIndicator.setIgnoreProgress(initialIgnoreProgress);
    }
  }
}

Fixed version (ground truth):
private void updateMaxBranchLengthGrid(ProgressIndicator progressIndicator){
  if (localLightDirection) {
    boolean initialIgnoreProgress=progressIndicator.isIgnoreProgress();
    try {
      FlowDirectionOperator flowDirectionOp=new FlowDirectionOperator();
      flowDirectionOp.setProgressIndicator(progressIndicator);
      progressIndicator.setIgnoreProgress(true);
      progressIndicator.setMessage("String_Node_Str");
      Grid flowDirections=flowDirectionOp.operate(generalizedGrid);
      if (generalizedGrid.sameGeometry(maxBranchLenghtsGrid) == false) {
        maxBranchLenghtsGrid=Grid.shallowCopy(generalizedGrid);
      }
      MaximumBranchLengthsOperator mbl=new MaximumBranchLengthsOperator();
      mbl.setProgressIndicator(progressIndicator);
      progressIndicator.setIgnoreProgress(false);
      progressIndicator.setMessage("String_Node_Str");
      mbl.operate(flowDirections,maxBranchLenghtsGrid);
    }
  finally {
      progressIndicator.setIgnoreProgress(initialIgnoreProgress);
    }
  }
}
Program: 140923
Project: 140923
Buggy source:
public void dev(BufferedImage img){
  FlowDirectionOperator mblDop=new FlowDirectionOperator();
  Grid dir=mblDop.operate(model.getFilteredGrid());
  MaximumBranchLengthsOperator mblOp=new MaximumBranchLengthsOperator();
  Grid mbl=mblOp.operate(dir);
  BinaryThresholdOperator thresholder=new BinaryThresholdOperator(100);
  Grid thresholded=thresholder.operate(mbl);
  SkeletonizerOperator mblSkel=new SkeletonizerOperator();
  Grid skeleton=thresholded;
  skeleton=mblSkel.operate(skeleton);
  Grid resultGrid=skeleton;
  new GridToImageOperator(resultGrid,img).operate(resultGrid);
}

Fixed version (ground truth):
public void dev(BufferedImage img){
  FlowDirectionOperator mblDop=new FlowDirectionOperator();
  Grid dir=mblDop.operate(model.getFilteredGrid());
  MaximumBranchLengthOperator mblOp=new MaximumBranchLengthOperator();
  Grid mbl=mblOp.operate(dir);
  BinaryThresholdOperator thresholder=new BinaryThresholdOperator(100);
  Grid thresholded=thresholder.operate(mbl);
  SkeletonizerOperator mblSkel=new SkeletonizerOperator();
  Grid skeleton=thresholded;
  do {
    mblSkel.operate(skeleton,null);
  }
 while (!mblSkel.isDone());
  Grid resultGrid=skeleton;
  new GridToImageOperator(resultGrid,img).operate(resultGrid);
}
Program: 140924
Project: 140924
Buggy source:
/** 
 * Multi-threaded operation. Requires a direction grid created with FlowDirectionOperator.
 * @param dir the direction grid
 * @param dst a grid to store maximum branch lengths
 */
@Override protected void operate(Grid dir,Grid dst,int startRow,int endRow){
  final int nCols=dir.getCols();
  final int nRows=dir.getRows();
  int adjI, adjJ;
  int[] allowedDirs={0,1,2,3,5,6,7,8};
  HashMap<Integer,Float> travelled=new HashMap<>(nRows + nCols);
  for (int row=startRow; row < endRow; ++row) {
    if (reportProgress(startRow,endRow,row) == false) {
      return;
    }
    for (int col=0; col < nCols; ++col) {
      float maxBranchLength=0;
      for (      int n : allowedDirs) {
        adjI=this.dY[n] + row;
        adjJ=this.dX[n] + col;
        if (adjI >= 0 && adjJ >= 0 && adjI < nRows && adjJ < nCols) {
          float l=branchLength(travelled,dir,col,row,adjJ,adjI);
          travelled.clear();
          if (l > maxBranchLength) {
            maxBranchLength=l;
          }
        }
      }
      dst.setValue(maxBranchLength,col,row);
    }
  }
}

Fixed version (ground truth):
/** 
 * Multi-threaded operation. Requires a direction grid created with FlowDirectionOperator.
 * @param dir the direction grid
 * @param dst a grid to store maximum branch lengths
 */
@Override protected void operate(Grid dir,Grid dst,int startRow,int endRow){
  final int nCols=dir.getCols();
  final int nRows=dir.getRows();
  int adjI, adjJ;
  int[] allowedDirs={2,5,7,8};
  HashMap<Integer,Float> travelled=new HashMap<>(nRows + nCols);
  for (int row=startRow; row < endRow; ++row) {
    if (reportProgress(startRow,endRow,row) == false) {
      return;
    }
    for (int col=0; col < nCols; ++col) {
      float maxBranchLength=0;
      for (      int n : allowedDirs) {
        adjI=this.dY[n] + row;
        adjJ=this.dX[n] + col;
        if (adjI >= 0 && adjJ >= 0 && adjI < nRows && adjJ < nCols) {
          float l=branchLength(travelled,dir,col,row,adjJ,adjI);
          travelled.clear();
          if (l > maxBranchLength) {
            maxBranchLength=l;
          }
        }
      }
      dst.setValue(maxBranchLength,col,row);
    }
  }
}
Program: 140925
Project: 140925
Buggy source:
protected void nextIteration(Grid grid){
  lastIterationChangedGrid=false;
  rotateG3=false;
  super.operate(grid,null);
  rotateG3=true;
  super.operate(grid,null);
}

Fixed version (ground truth):
protected void nextIteration(Grid grid){
  final int nCols=grid.getCols();
  final int nRows=grid.getRows();
  grid.setRowValue(0f,0);
  grid.setRowValue(0f,nRows - 1);
  grid.setColValue(0f,0);
  grid.setColValue(0f,nCols - 1);
  lastIterationChangedGrid=false;
  rotateG3=false;
  skippedRows.clear();
  super.operate(grid,null);
  for (  Integer row : skippedRows) {
    lastIterationChangedGrid|=operateRow(grid,row);
  }
  rotateG3=true;
  skippedRows.clear();
  super.operate(grid,null);
  for (  Integer row : skippedRows) {
    lastIterationChangedGrid|=operateRow(grid,row);
  }
}
Program: 140926
Project: 140926
Buggy source:
private double illuminationAzimuth(double dx,double dy){
  final double illuminationAngle=Math.toRadians(model.getAzimuth());
  final double maxDeviation=Math.toRadians(30);
  double aspect=Math.atan2(dx,-dy);
  if (aspect < 0) {
    aspect+=Math.PI;
  }
  double angleDiff=illuminationAngle - aspect;
  if (angleDiff <= 0) {
    angleDiff+=Math.PI;
  }
  double angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff;
  if (angleDiff >= Math.PI / 2) {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff + 2 * maxDeviation;
  }
  return illuminationAngle + angleAdjustment;
}

Fixed version (ground truth):
private double illuminationAzimuth(double dx,double dy){
  final double illuminationAzimuth=Math.toRadians(model.getAzimuth());
  final double maxDeviation=Math.toRadians(30);
  double aspect=Math.atan2(dx,-dy);
  if (aspect < 0) {
    aspect+=Math.PI;
  }
  double angleDiff=illuminationAzimuth - aspect;
  if (angleDiff <= 0) {
    angleDiff+=Math.PI;
  }
  double angleAdjustment;
  if (angleDiff >= Math.PI / 2) {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff + 2 * maxDeviation;
  }
 else {
    angleAdjustment=-maxDeviation / (Math.PI / 2) * angleDiff;
  }
  return illuminationAzimuth - angleAdjustment;
}
Program: 140927
Project: 140927
Buggy source:
public DirectionPoint(double x,double y,double azimuthDeg){
  this.x=x;
  this.y=y;
  this.azimuthDeg=azimuthDeg;
  this.dirX=Math.sin(Math.toRadians(azimuthDeg));
  this.dirY=Math.cos(Math.toRadians(azimuthDeg));
}

Fixed version (ground truth):
public DirectionPoint(double x,double y,double azimuthRad){
  this.x=x;
  this.y=y;
  this.azimuthRad=azimuthRad;
  this.dirX=Math.sin(azimuthRad);
  this.dirY=Math.cos(azimuthRad);
}
Program: 140928
Project: 140928
Buggy source:
@Override protected void operateCell(Grid ignore,Grid dst,int col,int row){
  double x=dst.getWest() + col * dst.getCellSize();
  double y=dst.getNorth() - row * dst.getCellSize();
  double sumWeight=0;
  double totalX=0;
  double totalY=0;
  for (  DirectionPoint point : referencePoints) {
    double dx=point.x - x;
    double dy=point.y - y;
    double distance=Math.sqrt(dx * dx + dy * dy);
    double weight=1d / distance;
    sumWeight+=weight;
    totalX+=weight * point.dirX;
    totalY+=weight * point.dirY;
  }
  totalX/=sumWeight;
  totalY/=sumWeight;
  double dir=Math.toDegrees(Math.atan2(totalY,totalX));
  double azimuth=90 - dir;
  dst.setValue(azimuth,col,row);
}

Fixed version (ground truth):
@Override protected void operateCell(Grid ignore,Grid dst,int col,int row){
  double x=dst.getWest() + col * dst.getCellSize();
  double y=dst.getNorth() - row * dst.getCellSize();
  double sumWeight=0;
  double totalX=0;
  double totalY=0;
  for (  DirectionPoint point : referencePoints) {
    double dx=point.x - x;
    double dy=point.y - y;
    double distance=Math.sqrt(dx * dx + dy * dy);
    if (distance < 0.0000001) {
      totalX=point.dirX;
      totalY=point.dirY;
      sumWeight=1;
      break;
    }
    double weight=1d / (distance * distance);
    sumWeight+=weight;
    totalX+=weight * point.dirX;
    totalY+=weight * point.dirY;
  }
  totalX/=sumWeight;
  totalY/=sumWeight;
  double dir=Math.toDegrees(Math.atan2(totalY,totalX));
  double azimuth=90 - dir;
  dst.setValue(azimuth,col,row);
}
Program: 140929
Project: 140929
Buggy source:
public void genDirectionPoints(GeometryCollection lines){
  for (int lineNumber=0; lineNumber < lines.getNumGeometries(); ++lineNumber) {
    Geometry line=lines.getGeometryN(lineNumber);
    LineString line2=(LineString)line;
    for (int pointNum=0; pointNum < line2.getNumPoints() - 1; ++pointNum) {
      Point point=line2.getPointN(pointNum);
      lineDirection(line2,pointNum,dirXY);
      double lightDir=illuminationAzimuth(dirXY[0],dirXY[1]);
      DirectionPoint dirPoint=new DirectionPoint(point.getX(),point.getY(),lightDir);
      referencePoints.add(dirPoint);
    }
  }
}

Fixed version (ground truth):
private void genDirectionPoints(GeometryCollection lines){
  DouglasPeucker dp=new DouglasPeucker(50);
  lines=dp.simplify(lines);
  for (int i=0; i < lines.getNumGeometries(); ++i) {
    LineString line=(LineString)lines.getGeometryN(i);
    for (int pointNum=0; pointNum < line.getNumPoints() - 1; ++pointNum) {
      Point p0=line.getPointN(pointNum);
      Point p1=line.getPointN(pointNum + 1);
      double dx=p0.getX() - p1.getX();
      double dy=p0.getY() - p1.getY();
      double length=Math.sqrt(dx * dx + dy * dy);
      double dirX=dx / length;
      double dirY=dy / length;
      double lightDir=illuminationAzimuth(dirX,dirY);
      if (Double.isNaN(lightDir)) {
        continue;
      }
      DirectionPoint dirPoint=new DirectionPoint(p0.getX(),p0.getY(),lightDir);
      referencePoints.add(dirPoint);
    }
  }
}
Program: 140930
Project: 140930
Buggy source:
/** 
 * Constructor for the JFrame. Initializes components and sets up the default color gradient.
 * @param model model object
 */
public MainWindow(Model model){
  this.model=model;
  initRecentDocumentsMenu();
  initComponents();
  MenuKeysDispatcher.setupDialogActions(menuBar);
  GUIUtil.zoomMenuCommands(zoomInAction,zoomOutAction,getRootPane());
  progressPanel=new ProgressPanel();
  progressPanel.setOpaque(false);
  setGlassPane(progressPanel);
  progressPanel.setVisible(false);
  showDebugMenuWhenAssertionsAreEnabled();
  navigableImagePanel.setInfoString("String_Node_Str");
  Color focusColor=new Color(190,230,255);
  Border border=javax.swing.BorderFactory.createLineBorder(focusColor,4);
  new FileDrop(null,navigableImagePanel,border,new FileDrop.Listener(){
    @Override public void filesDropped(    java.io.File[] files){
      for (      File file : files) {
        try {
          openGrid(file.getCanonicalPath());
        }
 catch (        IOException ex) {
          ErrorDialog.showErrorDialog(OPEN_ERROR_MESSAGE,"String_Node_Str",ex,navigableImagePanel.getParent());
        }
      }
    }
  }
);
}

Fixed version (ground truth):
/** 
 * Constructor for the JFrame. Initializes components and sets up the default color gradient.
 * @param model model object
 */
public MainWindow(Model model){
  this.model=model;
  initRecentDocumentsMenu();
  initComponents();
  MenuKeysDispatcher.setupDialogActions(menuBar);
  GUIUtil.zoomMenuCommands(zoomInAction,zoomOutAction,getRootPane());
  progressPanel=new ProgressPanel();
  progressPanel.setOpaque(false);
  setGlassPane(progressPanel);
  progressPanel.setVisible(false);
  showDebugMenuWhenAssertionsAreEnabled();
  navigableImagePanel.setInfoString("String_Node_Str");
  Color focusColor=new Color(190,230,255);
  Border border=javax.swing.BorderFactory.createLineBorder(focusColor,4);
  new FileDrop(null,navigableImagePanel,border,new FileDrop.Listener(){
    @Override public void filesDropped(    java.io.File[] files){
      try {
        int maxNbrFilesToScan=Math.min(files.length,100);
        for (int i=0; i < maxNbrFilesToScan; i++) {
          String filePath=files[i].getCanonicalPath();
          if (EsriASCIIGridReader.canRead(filePath)) {
            openGrid(filePath);
          }
        }
      }
 catch (      IOException ex) {
        ErrorDialog.showErrorDialog(OPEN_ERROR_MESSAGE,"String_Node_Str",ex,navigableImagePanel.getParent());
      }
    }
  }
);
}
Program: 140931
Project: 140931
Buggy source:
@Override public void filesDropped(java.io.File[] files){
  for (  File file : files) {
    try {
      openGrid(file.getCanonicalPath());
    }
 catch (    IOException ex) {
      ErrorDialog.showErrorDialog(OPEN_ERROR_MESSAGE,"String_Node_Str",ex,navigableImagePanel.getParent());
    }
  }
}

Fixed version (ground truth):
@Override public void filesDropped(java.io.File[] files){
  try {
    int maxNbrFilesToScan=Math.min(files.length,100);
    for (int i=0; i < maxNbrFilesToScan; i++) {
      String filePath=files[i].getCanonicalPath();
      if (EsriASCIIGridReader.canRead(filePath)) {
        openGrid(filePath);
      }
    }
  }
 catch (  IOException ex) {
    ErrorDialog.showErrorDialog(OPEN_ERROR_MESSAGE,"String_Node_Str",ex,navigableImagePanel.getParent());
  }
}
Program: 140932
Project: 140932
Buggy source:
@Override public void done(){
  if (isCancelled()) {
    SwingUtilities.invokeLater(new Runnable(){
      @Override public void run(){
        closeGUI();
      }
    }
);
    return;
  }
 else {
    closeGUI();
  }
  try {
    Grid grid=get();
    model.setGrid(grid);
  }
 catch (  InterruptedException|CancellationException e) {
  }
catch (  Throwable e) {
    closeGUI();
    String msg="String_Node_Str";
    if (e instanceof OutOfMemoryError) {
      msg+="String_Node_Str";
    }
 else {
      msg+="String_Node_Str";
    }
    msg+="String_Node_Str";
    ErrorDialog.showErrorDialog(msg,"String_Node_Str",e,frame);
  }
}

Fixed version (ground truth):
@Override public void done(){
  if (isCancelled()) {
    SwingUtilities.invokeLater(new Runnable(){
      @Override public void run(){
        closeGUI();
      }
    }
);
    return;
  }
 else {
    closeGUI();
  }
  try {
    Grid grid=get();
    model.setGrid(grid);
    successfullyImportedGrid=true;
  }
 catch (  InterruptedException|CancellationException e) {
  }
catch (  Throwable e) {
    closeGUI();
    String msg="String_Node_Str";
    if (e instanceof OutOfMemoryError) {
      msg+="String_Node_Str";
    }
 else {
      msg+="String_Node_Str";
    }
    msg+="String_Node_Str";
    ErrorDialog.showErrorDialog(msg,"String_Node_Str",e,frame);
  }
}
Program: 140934
Project: 140934
Buggy source:
@Override public void run(){
  try {
    final int nCols=grid.getCols();
    final int nRows=grid.getRows();
    final int nbrValues=nRows * nCols;
    do {
      String str=queue.take();
      if (EOF.equals(str)) {
        if (counter != nbrValues) {
          throw new IOException("String_Node_Str");
        }
        break;
      }
      StringTokenizer tokenizer=new StringTokenizer(str,"String_Node_Str");
      while (tokenizer.hasMoreTokens() && !Thread.currentThread().isInterrupted() && producerConsumerException == null) {
        int col=counter % nCols;
        int row=counter / nCols;
        ++counter;
        if (counter > nbrValues) {
          throw new IOException("String_Node_Str");
        }
        String token=tokenizer.nextToken();
        try {
          float v=Float.parseFloat(token);
          grid.setValue(v == noDataValue ? Float.NaN : v,col,row);
        }
 catch (        NumberFormatException exc) {
          throw new IllegalArgumentException("String_Node_Str" + token + "String_Node_Str",exc);
        }
      }
      if (progressIndicator != null) {
        int row=counter / nCols;
        int perc=(int)((row + 1d) / nRows * 100);
        if (!progressIndicator.progress(perc)) {
          counter=nbrValues;
          break;
        }
      }
    }
 while (counter < nbrValues && !Thread.currentThread().isInterrupted() && producerConsumerException == null);
  }
 catch (  Throwable ex) {
    producerConsumerException=ex;
  }
}

Fixed version (ground truth):
@Override public void run(){
  try {
    final int nCols=grid.getCols();
    final int nRows=grid.getRows();
    final int nbrValues=nRows * nCols;
    do {
      String str=queue.take();
      if (EOF.equals(str)) {
        if (counter != nbrValues) {
          throw new IOException("String_Node_Str");
        }
        break;
      }
      StringTokenizer tokenizer=new StringTokenizer(str,"String_Node_Str");
      while (tokenizer.hasMoreTokens() && !Thread.currentThread().isInterrupted() && producerConsumerException == null) {
        int col=counter % nCols;
        int row=counter / nCols;
        ++counter;
        if (counter > nbrValues) {
          throw new IOException("String_Node_Str");
        }
        String token=tokenizer.nextToken();
        try {
          float v=Float.parseFloat(token);
          grid.setValue(v == noDataValue ? Float.NaN : v,col,row);
        }
 catch (        NumberFormatException exc) {
          throw new IllegalArgumentException("String_Node_Str" + token + "String_Node_Str",exc);
        }
      }
      if (progressIndicator != null) {
        int row=counter / nCols;
        int perc=(int)(100d * row / nRows);
        if (!progressIndicator.progress(perc)) {
          counter=nbrValues;
          break;
        }
      }
    }
 while (counter < nbrValues && !Thread.currentThread().isInterrupted() && producerConsumerException == null);
  }
 catch (  Throwable ex) {
    producerConsumerException=ex;
  }
}
Program: 140936
Project: 140936
Buggy source:
@Override protected void operateCell(Grid src,Grid dst,int col,int row){
  dst.setValue(Math.random(),col,row);
}

Fixed version (ground truth):
@Override protected void operateCell(Grid src,Grid dst,int col,int row){
  float val=(float)(src.getValue(col,row) + Math.random() * 500);
  dst.setValue(val,col,row);
}