Program: 39078
Project: 39078
Buggy source:
/** 
 * Searches for closest matches.
 * @param compare Kanji to compare
 * @param algo Match algorithm to use
 * @param progress Progress reporter (null if not needed)
 * @return Top matches above search threshold
 * @throws IllegalArgumentException If match algorithm not set
 */
public synchronized KanjiMatch[] getTopMatches(KanjiInfo compare,KanjiInfo.MatchAlgorithm algo,Progress progress) throws IllegalArgumentException {
  TreeSet<KanjiMatch> matches=new TreeSet<KanjiMatch>();
switch (algo) {
case STRICT:
{
      List<KanjiInfo> list=kanji.get(compare.getStrokeCount());
      if (list != null) {
        int max=list.size();
        if (progress != null) {
          progress.progress(0,max);
        }
        int i=0;
        for (        KanjiInfo other : list) {
          float score=compare.getMatchScore(other,algo);
          if (score > 0) {
            KanjiMatch match=new KanjiMatch(other,score);
            matches.add(match);
          }
          if (progress != null) {
            progress.progress(++i,max);
          }
        }
      }
    }
  break;
case FUZZY:
case FUZZY_1OUT:
case FUZZY_2OUT:
{
  List<KanjiInfo> list=new LinkedList<KanjiInfo>();
  if (compare.getStrokeCount() > 0) {
    int range=(algo == MatchAlgorithm.FUZZY_2OUT) ? 2 : (algo == MatchAlgorithm.FUZZY_1OUT) ? 1 : 0;
    int count=compare.getStrokeCount() - range;
    for (int i=0; i < 2; i++) {
      if (count > 0) {
        List<KanjiInfo> countList=kanji.get(count);
        if (countList != null) {
          list.addAll(countList);
        }
      }
      count+=2 * range;
      if (range == 0) {
        break;
      }
    }
  }
  int max=list.size();
  if (progress != null) {
    progress.progress(0,max);
  }
  int i=0;
  for (  KanjiInfo other : list) {
    float score=compare.getMatchScore(other,algo);
    KanjiMatch match=new KanjiMatch(other,score);
    matches.add(match);
    if (progress != null) {
      progress.progress(++i,max);
    }
  }
}
break;
default :
throw new IllegalArgumentException("String_Node_Str");
}
LinkedList<KanjiMatch> results=new LinkedList<KanjiMatch>();
float maxScore=-1;
for (KanjiMatch match : matches) {
if (maxScore == -1) {
maxScore=match.getScore();
}
 else {
if (match.getScore() < maxScore * 0.75f) {
break;
}
}
results.add(match);
}
return results.toArray(new KanjiMatch[results.size()]);
}

Fixed version (ground truth):
/** 
 * Searches for closest matches.
 * @param compare Kanji to compare
 * @param algo Match algorithm to use
 * @param progress Progress reporter (null if not needed)
 * @return Top matches above search threshold
 * @throws IllegalArgumentException If match algorithm not set
 */
public KanjiMatch[] getTopMatches(KanjiInfo compare,KanjiInfo.MatchAlgorithm algo,Progress progress) throws IllegalArgumentException {
  TreeSet<KanjiMatch> matches=new TreeSet<KanjiMatch>();
switch (algo) {
case STRICT:
{
      List<KanjiInfo> list;
synchronized (this) {
        list=new LinkedList<KanjiInfo>(kanji.get(compare.getStrokeCount()));
      }
      if (list != null) {
        int max=list.size();
        if (progress != null) {
          progress.progress(0,max);
        }
        int i=0;
        for (        KanjiInfo other : list) {
          float score=compare.getMatchScore(other,algo);
          if (score > 0) {
            KanjiMatch match=new KanjiMatch(other,score);
            matches.add(match);
          }
          if (progress != null) {
            progress.progress(++i,max);
          }
        }
      }
    }
  break;
case FUZZY:
case FUZZY_1OUT:
case FUZZY_2OUT:
{
  List<KanjiInfo> list=new LinkedList<KanjiInfo>();
  if (compare.getStrokeCount() > 0) {
synchronized (this) {
      int range=(algo == MatchAlgorithm.FUZZY_2OUT) ? 2 : (algo == MatchAlgorithm.FUZZY_1OUT) ? 1 : 0;
      int count=compare.getStrokeCount() - range;
      for (int i=0; i < 2; i++) {
        if (count > 0) {
          List<KanjiInfo> countList=kanji.get(count);
          if (countList != null) {
            list.addAll(countList);
          }
        }
        count+=2 * range;
        if (range == 0) {
          break;
        }
      }
    }
  }
  int max=list.size();
  if (progress != null) {
    progress.progress(0,max);
  }
  int i=0;
  for (  KanjiInfo other : list) {
    float score=compare.getMatchScore(other,algo);
    KanjiMatch match=new KanjiMatch(other,score);
    matches.add(match);
    if (progress != null) {
      progress.progress(++i,max);
    }
  }
}
break;
default :
throw new IllegalArgumentException("String_Node_Str");
}
LinkedList<KanjiMatch> results=new LinkedList<KanjiMatch>();
float maxScore=-1;
for (KanjiMatch match : matches) {
if (maxScore == -1) {
maxScore=match.getScore();
}
 else {
if (match.getScore() < maxScore * 0.75f) {
break;
}
}
results.add(match);
}
return results.toArray(new KanjiMatch[results.size()]);
}