Program: 101608
Project: 101608
Buggy source:
public int locate(){
  alphabet();
  scoreTextLength=Math.max(text.length(),Bitap.MINLENGTH);
  scoreTextLength=Math.min(scoreTextLength,Bitap.MAXLENGTH);
  double scoreThreshold=Bitap.THRESHOLD;
  int bestLoc=text.indexOf(pattern,loc);
  if (bestLoc != -1) {
    scoreThreshold=Math.min(bitapScore(0,bestLoc),scoreThreshold);
  }
  bestLoc=text.lastIndexOf(pattern,loc + pattern.length());
  if (bestLoc != -1) {
    scoreThreshold=Math.min(bitapScore(0,bestLoc),scoreThreshold);
  }
  int matchmask=(int)Math.pow(2,pattern.length() - 1);
  bestLoc=-1;
  int binMin;
  int binMid;
  int binMax=Math.max(loc + loc,text.length());
  int[] lastrd=new int[0];
  for (int d=0; d < pattern.length(); d++) {
    int[] rd=new int[text.length()];
    binMin=loc;
    binMid=binMax;
    while (binMin < binMid) {
      if (bitapScore(d,binMid) < scoreThreshold) {
        binMin=binMid;
      }
 else {
        binMax=binMid;
      }
      binMid=(binMax - binMin) / 2 + binMin;
    }
    binMax=binMid;
    int start=Math.max(0,loc - (binMid - loc) - 1);
    int finish=Math.min(text.length() - 1,pattern.length() + binMid);
    if (text.charAt(finish) == pattern.charAt(pattern.length() - 1)) {
      rd[finish]=(int)Math.pow(2,d + 1) - 1;
    }
 else {
      rd[finish]=(int)Math.pow(2,d) - 1;
    }
    for (int j=finish - 1; j >= start; j--) {
      Character curChar=new Character(text.charAt(j));
      int mask=alphabet.containsKey(curChar) ? ((Integer)alphabet.get(curChar)).intValue() : 0;
      if (d == 0) {
        rd[j]=((rd[j + 1] << 1) | 1) & mask;
      }
 else {
        rd[j]=((rd[j + 1] << 1) | 1) & mask | ((lastrd[j + 1] << 1) | 1) | ((lastrd[j] << 1) | 1) | lastrd[j + 1];
      }
      if ((rd[j] & matchmask) != 0) {
        double score=bitapScore(d,j);
        if (score <= scoreThreshold) {
          scoreThreshold=score;
          bestLoc=j;
          if (j > loc) {
            start=Math.max(0,loc - (j - loc));
          }
 else {
            break;
          }
        }
      }
    }
    if (bitapScore(d + 1,loc) > scoreThreshold) {
      break;
    }
    lastrd=rd;
  }
  return bestLoc;
}

Fixed version (ground truth):
public int locate(){
  alphabet();
  scoreTextLength=Math.max(text.length(),Bitap.minLength);
  scoreTextLength=Math.min(scoreTextLength,Bitap.maxLength);
  double scoreThreshold=Bitap.threshold;
  int bestLoc=text.indexOf(pattern,loc);
  if (bestLoc != -1) {
    scoreThreshold=Math.min(bitapScore(0,bestLoc),scoreThreshold);
  }
  bestLoc=text.lastIndexOf(pattern,loc + pattern.length());
  if (bestLoc != -1) {
    scoreThreshold=Math.min(bitapScore(0,bestLoc),scoreThreshold);
  }
  int matchmask=(int)Math.pow(2,pattern.length() - 1);
  bestLoc=-1;
  int binMin;
  int binMid;
  int binMax=Math.max(loc + loc,text.length());
  int[] lastrd=new int[0];
  for (int d=0; d < pattern.length(); d++) {
    int[] rd=new int[text.length()];
    binMin=loc;
    binMid=binMax;
    while (binMin < binMid) {
      if (bitapScore(d,binMid) < scoreThreshold) {
        binMin=binMid;
      }
 else {
        binMax=binMid;
      }
      binMid=(binMax - binMin) / 2 + binMin;
    }
    binMax=binMid;
    int start=Math.max(0,loc - (binMid - loc) - 1);
    int finish=Math.min(text.length() - 1,pattern.length() + binMid);
    if (text.charAt(finish) == pattern.charAt(pattern.length() - 1)) {
      rd[finish]=(int)Math.pow(2,d + 1) - 1;
    }
 else {
      rd[finish]=(int)Math.pow(2,d) - 1;
    }
    for (int j=finish - 1; j >= start; j--) {
      Character curChar=new Character(text.charAt(j));
      int mask=alphabet.containsKey(curChar) ? ((Integer)alphabet.get(curChar)).intValue() : 0;
      if (d == 0) {
        rd[j]=((rd[j + 1] << 1) | 1) & mask;
      }
 else {
        rd[j]=((rd[j + 1] << 1) | 1) & mask | ((lastrd[j + 1] << 1) | 1) | ((lastrd[j] << 1) | 1) | lastrd[j + 1];
      }
      if ((rd[j] & matchmask) != 0) {
        double score=bitapScore(d,j);
        if (score <= scoreThreshold) {
          scoreThreshold=score;
          bestLoc=j;
          if (j > loc) {
            start=Math.max(0,loc - (j - loc));
          }
 else {
            break;
          }
        }
      }
    }
    if (bitapScore(d + 1,loc) > scoreThreshold) {
      break;
    }
    lastrd=rd;
  }
  return bestLoc;
}