Program: 92588
Project: 92588
Buggy source:
/** 
 * Returns the approximate k-nearest neighbors. A posteriori multiple probe model has to be trained already.
 * @param q the query object.
 * @param k	the number of nearest neighbors to search for.
 * @param recall the expected recall rate.
 * @param T the maximum number of probes.
 */
public Neighbor<double[],E>[] knn(double[] q,int k,double recall,int T){
  if (recall > 1 || recall < 0) {
    throw new IllegalArgumentException("String_Node_Str" + recall);
  }
  if (k < 1) {
    throw new IllegalArgumentException("String_Node_Str" + k);
  }
  double alpha=1 - Math.pow(1 - recall,1.0 / hash.size());
  int hit=0;
  IntArrayList candidates=new IntArrayList();
  for (int i=0; i < hash.size(); i++) {
    IntArrayList buckets=model.get(i).getProbeSequence(q,alpha,T);
    for (int j=0; j < buckets.size(); j++) {
      int bucket=buckets.get(j);
      ArrayList<HashEntry> bin=hash.get(i).table[bucket % H];
      if (bin != null) {
        for (        HashEntry e : bin) {
          if (e.bucket == bucket) {
            if (q == e.key && identicalExcluded) {
              continue;
            }
            candidates.add(e.index);
          }
        }
      }
    }
  }
  int[] cand=candidates.toArray();
  Arrays.sort(cand);
  Neighbor<double[],E> neighbor=new Neighbor<double[],E>(null,null,0,Double.MAX_VALUE);
  @SuppressWarnings("String_Node_Str") Neighbor<double[],E>[] neighbors=(Neighbor<double[],E>[])java.lang.reflect.Array.newInstance(neighbor.getClass(),k);
  HeapSelect<Neighbor<double[],E>> heap=new HeapSelect<Neighbor<double[],E>>(neighbors);
  for (int i=0; i < k; i++) {
    heap.add(neighbor);
  }
  int prev=-1;
  for (  int index : cand) {
    if (index == prev) {
      continue;
    }
 else {
      prev=index;
    }
    double[] key=keys.get(index);
    double dist=Math.distance(q,key);
    if (dist < heap.peek().distance) {
      heap.add(new Neighbor<double[],E>(key,data.get(index),index,dist));
      hit++;
    }
  }
  heap.sort();
  if (hit < k) {
    @SuppressWarnings("String_Node_Str") Neighbor<double[],E>[] n2=(Neighbor<double[],E>[])java.lang.reflect.Array.newInstance(neighbor.getClass(),hit);
    for (int i=0; i < hit; i++) {
      n2[i]=neighbors[i + 1];
    }
    neighbors=n2;
  }
  return neighbors;
}

Fixed version (ground truth):
/** 
 * Returns the approximate k-nearest neighbors. A posteriori multiple probe model has to be trained already.
 * @param q the query object.
 * @param k	the number of nearest neighbors to search for.
 * @param recall the expected recall rate.
 * @param T the maximum number of probes.
 */
public Neighbor<double[],E>[] knn(double[] q,int k,double recall,int T){
  if (recall > 1 || recall < 0) {
    throw new IllegalArgumentException("String_Node_Str" + recall);
  }
  if (k < 1) {
    throw new IllegalArgumentException("String_Node_Str" + k);
  }
  double alpha=1 - Math.pow(1 - recall,1.0 / hash.size());
  int hit=0;
  IntArrayList candidates=new IntArrayList();
  for (int i=0; i < hash.size(); i++) {
    IntArrayList buckets=model.get(i).getProbeSequence(q,alpha,T);
    for (int j=0; j < buckets.size(); j++) {
      int bucket=buckets.get(j);
      ArrayList<HashEntry> bin=hash.get(i).table[bucket % H];
      if (bin != null) {
        for (        HashEntry e : bin) {
          if (e.bucket == bucket) {
            if (q == e.key && identicalExcluded) {
              continue;
            }
            candidates.add(e.index);
          }
        }
      }
    }
  }
  int[] cand=candidates.toArray();
  Arrays.sort(cand);
  Neighbor<double[],E> neighbor=new Neighbor<double[],E>(null,null,0,Double.MAX_VALUE);
  @SuppressWarnings("String_Node_Str") Neighbor<double[],E>[] neighbors=(Neighbor<double[],E>[])java.lang.reflect.Array.newInstance(neighbor.getClass(),k);
  HeapSelect<Neighbor<double[],E>> heap=new HeapSelect<Neighbor<double[],E>>(neighbors);
  for (int i=0; i < k; i++) {
    heap.add(neighbor);
  }
  int prev=-1;
  for (  int index : cand) {
    if (index == prev) {
      continue;
    }
 else {
      prev=index;
    }
    double[] key=keys.get(index);
    double dist=Math.distance(q,key);
    if (dist < heap.peek().distance) {
      heap.add(new Neighbor<double[],E>(key,data.get(index),index,dist));
      hit++;
    }
  }
  heap.sort();
  if (hit < k) {
    @SuppressWarnings("String_Node_Str") Neighbor<double[],E>[] n2=(Neighbor<double[],E>[])java.lang.reflect.Array.newInstance(neighbor.getClass(),hit);
    int start=k - hit;
    for (int i=0; i < hit; i++) {
      n2[i]=neighbors[i + start];
    }
    neighbors=n2;
  }
  return neighbors;
}