Program: 28403
Project: 28403
Buggy source:
/** 
 * Compute n-gram distance.
 * @param s0
 * @param s1
 * @return
 */
public final double distance(final String s0,final String s1){
  final char special='\n';
  final int sl=s0.length();
  final int tl=s1.length();
  if (sl == 0 || tl == 0) {
    if (sl == tl) {
      return 0;
    }
 else {
      return 1;
    }
  }
  int cost=0;
  if (sl < n || tl < n) {
    for (int i=0, ni=Math.min(sl,tl); i < ni; i++) {
      if (s0.charAt(i) == s1.charAt(i)) {
        cost++;
      }
    }
    return (float)cost / Math.max(sl,tl);
  }
  char[] sa=new char[sl + n - 1];
  float[] p;
  float[] d;
  float[] d2;
  for (int i=0; i < sa.length; i++) {
    if (i < n - 1) {
      sa[i]=special;
    }
 else {
      sa[i]=s0.charAt(i - n + 1);
    }
  }
  p=new float[sl + 1];
  d=new float[sl + 1];
  int i;
  int j;
  char[] t_j=new char[n];
  for (i=0; i <= sl; i++) {
    p[i]=i;
  }
  for (j=1; j <= tl; j++) {
    if (j < n) {
      for (int ti=0; ti < n - j; ti++) {
        t_j[ti]=special;
      }
      for (int ti=n - j; ti < n; ti++) {
        t_j[ti]=s1.charAt(ti - (n - j));
      }
    }
 else {
      t_j=s1.substring(j - n,j).toCharArray();
    }
    d[0]=j;
    for (i=1; i <= sl; i++) {
      cost=0;
      int tn=n;
      for (int ni=0; ni < n; ni++) {
        if (sa[i - 1 + ni] != t_j[ni]) {
          cost++;
        }
 else         if (sa[i - 1 + ni] == special) {
          tn--;
        }
      }
      float ec=(float)cost / tn;
      d[i]=Math.min(Math.min(d[i - 1] + 1,p[i] + 1),p[i - 1] + ec);
    }
    d2=p;
    p=d;
    d=d2;
  }
  return p[sl] / Math.max(tl,sl);
}

Fixed version (ground truth):
/** 
 * Compute n-gram distance.
 * @param s0
 * @param s1
 * @return
 */
public final double distance(final String s0,final String s1){
  final char special='\n';
  final int sl=s0.length();
  final int tl=s1.length();
  if (s0.equals(s1)) {
    return 0;
  }
  if (sl == 0 || tl == 0) {
    if (sl == tl) {
      return 0;
    }
 else {
      return 1;
    }
  }
  int cost=0;
  if (sl < n || tl < n) {
    for (int i=0, ni=Math.min(sl,tl); i < ni; i++) {
      if (s0.charAt(i) == s1.charAt(i)) {
        cost++;
      }
    }
    return (float)cost / Math.max(sl,tl);
  }
  char[] sa=new char[sl + n - 1];
  float[] p;
  float[] d;
  float[] d2;
  for (int i=0; i < sa.length; i++) {
    if (i < n - 1) {
      sa[i]=special;
    }
 else {
      sa[i]=s0.charAt(i - n + 1);
    }
  }
  p=new float[sl + 1];
  d=new float[sl + 1];
  int i;
  int j;
  char[] t_j=new char[n];
  for (i=0; i <= sl; i++) {
    p[i]=i;
  }
  for (j=1; j <= tl; j++) {
    if (j < n) {
      for (int ti=0; ti < n - j; ti++) {
        t_j[ti]=special;
      }
      for (int ti=n - j; ti < n; ti++) {
        t_j[ti]=s1.charAt(ti - (n - j));
      }
    }
 else {
      t_j=s1.substring(j - n,j).toCharArray();
    }
    d[0]=j;
    for (i=1; i <= sl; i++) {
      cost=0;
      int tn=n;
      for (int ni=0; ni < n; ni++) {
        if (sa[i - 1 + ni] != t_j[ni]) {
          cost++;
        }
 else         if (sa[i - 1 + ni] == special) {
          tn--;
        }
      }
      float ec=(float)cost / tn;
      d[i]=Math.min(Math.min(d[i - 1] + 1,p[i] + 1),p[i - 1] + ec);
    }
    d2=p;
    p=d;
    d=d2;
  }
  return p[sl] / Math.max(tl,sl);
}