Program: 149546
Project: 149546
Buggy source:
/** 
 * Search for any neighbours within a set height of the specified peak that is within the search region bounds.
 * @param regionBounds the region bounds
 * @param n the candidate index
 * @return The number of neighbours
 */
private int findNeighbours(Rectangle regionBounds,int n){
  int xmin=regionBounds.x;
  int xmax=xmin + regionBounds.width - 1;
  int ymin=regionBounds.y;
  int ymax=ymin + regionBounds.height - 1;
  final Candidate spot=candidates[n];
  final float heightThreshold;
  if (relativeIntensity) {
    heightThreshold=(float)(spot.intensity * config.getNeighbourHeightThreshold());
  }
 else {
    if (spot.intensity < background)     heightThreshold=spot.intensity;
 else     heightThreshold=(float)((spot.intensity - background) * config.getNeighbourHeightThreshold() + background);
  }
  neighbourCount=0;
  final CandidateList neighbours=findNeighbours(spot);
  final Candidate[] candidates=neighbours.list;
  for (int i=0; i < neighbours.size; i++) {
    final int id=candidates[i].index;
    if (isFit(id))     continue;
    if (canIgnore(candidates[i].x,candidates[i].y,xmin,xmax,ymin,ymax,candidates[i].intensity,heightThreshold))     continue;
    neighbourIndices[neighbourCount++]=id;
  }
  int c=0;
  for (int i=0; i < this.candidates.length; i++) {
    if (i == n || isFit(i))     continue;
    if (canIgnore(this.candidates[i].x,this.candidates[i].y,xmin,xmax,ymin,ymax,this.candidates[i].intensity,heightThreshold))     continue;
    if (neighbourIndices[c++] != i)     throw new RuntimeException("String_Node_Str");
  }
  fittedNeighbourCount=0;
  if (!sliceResults.isEmpty()) {
    final double x0min=regionBounds.x;
    final double y0min=regionBounds.y;
    final double x0max=regionBounds.x + regionBounds.width;
    final double y0max=regionBounds.y + regionBounds.height;
    final PeakResult[] peakNeighbours=findPeakNeighbours(spot);
    for (int i=0; i < peakNeighbours.length; i++) {
      final PeakResult result=peakNeighbours[i];
      final double xw=2 * result.getXSD();
      final double yw=2 * result.getYSD();
      if (intersects(x0min,y0min,x0max,y0max,result.getXPosition() - xw,result.getYPosition() - yw,result.getXPosition() + xw,result.getYPosition() + yw))       continue;
      fittedNeighbourIndices[fittedNeighbourCount++]=i;
    }
  }
  return neighbourCount + fittedNeighbourCount;
}

Fixed version (ground truth):
/** 
 * Search for any neighbours within a set height of the specified peak that is within the search region bounds.
 * @param regionBounds the region bounds
 * @param n the candidate index
 * @return The number of neighbours
 */
private int findNeighbours(Rectangle regionBounds,int n){
  int xmin=regionBounds.x;
  int xmax=xmin + regionBounds.width - 1;
  int ymin=regionBounds.y;
  int ymax=ymin + regionBounds.height - 1;
  final Candidate spot=candidates[n];
  final float heightThreshold;
  if (relativeIntensity) {
    heightThreshold=(float)(spot.intensity * config.getNeighbourHeightThreshold());
  }
 else {
    if (spot.intensity < background)     heightThreshold=spot.intensity;
 else     heightThreshold=(float)((spot.intensity - background) * config.getNeighbourHeightThreshold() + background);
  }
  neighbourCount=0;
  final CandidateList neighbours=findNeighbours(spot);
  final Candidate[] candidates=neighbours.list;
  for (int i=0; i < neighbours.size; i++) {
    final int id=candidates[i].index;
    if (isFit(id))     continue;
    if (canIgnore(candidates[i].x,candidates[i].y,xmin,xmax,ymin,ymax,candidates[i].intensity,heightThreshold))     continue;
    neighbourIndices[neighbourCount++]=id;
  }
  fittedNeighbourCount=0;
  if (!sliceResults.isEmpty()) {
    final double x0min=regionBounds.x;
    final double y0min=regionBounds.y;
    final double x0max=regionBounds.x + regionBounds.width;
    final double y0max=regionBounds.y + regionBounds.height;
    final PeakResult[] peakNeighbours=findPeakNeighbours(spot);
    for (int i=0; i < peakNeighbours.length; i++) {
      final PeakResult result=peakNeighbours[i];
      final double xw=2 * result.getXSD();
      final double yw=2 * result.getYSD();
      if (intersects(x0min,y0min,x0max,y0max,result.getXPosition() - xw,result.getYPosition() - yw,result.getXPosition() + xw,result.getYPosition() + yw))       continue;
      fittedNeighbourIndices[fittedNeighbourCount++]=i;
    }
  }
  return neighbourCount + fittedNeighbourCount;
}