Program: 24713
Project: 24713
Buggy source:
/** 
 * Make a list of all the terms present in the given query, grouped by field set.
 * @param query          The query to traverse
 * @param desiredFields  The set of fields to limit to. If null, allfields are considered.
 * @return  An ordered map consisting of entries of a key and avalue. The key is an ordered set of field names. The value is an ordered set of words.
 */
private LinkedHashMap gatherKeywords(Query query,final Set desiredFields){
  final LinkedHashMap termMap=new LinkedHashMap();
  XtfQueryTraverser trav=new XtfQueryTraverser(){
    private void add(    Term t){
      final String field=t.field();
      final String word=t.text();
      if (desiredFields != null && !desiredFields.contains(field))       return;
      if (!termMap.containsKey(word))       termMap.put(word,new LinkedHashSet());
      ((LinkedHashSet)termMap.get(word)).add(field);
    }
    public void traverseQuery(    Query q){
      if (q.getBoost() > 0.001f)       super.traverseQuery(q);
    }
    protected void traverse(    TermQuery q){
      add(q.getTerm());
    }
    protected void traverse(    SpanTermQuery q){
      add(q.getTerm());
    }
    protected void traverse(    BooleanQuery bq){
      BooleanClause[] clauses=bq.getClauses();
      for (int i=0; i < clauses.length; i++) {
        if (clauses[i].getOccur() != BooleanClause.Occur.MUST_NOT)         traverseQuery(clauses[i].getQuery());
      }
    }
    protected void traverse(    SpanChunkedNotQuery nq){
      traverseQuery(nq.getInclude());
    }
    protected void traverse(    SpanNotQuery nq){
      traverseQuery(nq.getInclude());
    }
    protected void traverse(    SpanNotNearQuery nq){
      traverseQuery(nq.getInclude());
    }
  }
;
  trav.traverseQuery(query);
  LinkedHashMap fieldsMap=new LinkedHashMap();
  for (Iterator ti=termMap.keySet().iterator(); ti.hasNext(); ) {
    String word=(String)ti.next();
    LinkedHashSet fieldsSet=(LinkedHashSet)termMap.get(word);
    if (!fieldsMap.containsKey(fieldsSet))     fieldsMap.put(fieldsSet,new LinkedHashSet());
    ((LinkedHashSet)fieldsMap.get(fieldsSet)).add(word);
  }
  return fieldsMap;
}

Fixed version (ground truth):
/** 
 * Make a list of all the terms present in the given query, grouped by field set.
 * @param query          The query to traverse
 * @param desiredFields  The set of fields to limit to. If null, allfields are considered.
 * @return  An ordered map consisting of entries of a key and avalue. The key is an ordered set of field names. The value is an ordered set of words.
 */
private LinkedHashMap gatherKeywords(Query query,final Set desiredFields){
  final LinkedHashMap termMap=new LinkedHashMap();
  XtfQueryTraverser trav=new XtfQueryTraverser(){
    private void add(    Term t){
      final String field=t.field();
      final String word=t.text();
      if (desiredFields != null && !desiredFields.contains(field))       return;
      if (!termMap.containsKey(word))       termMap.put(word,new LinkedHashSet());
      ((LinkedHashSet)termMap.get(word)).add(field);
    }
    public void traverseQuery(    Query q){
      if (q.getBoost() > 0.001f)       super.traverseQuery(q);
    }
    protected void traverse(    TermQuery q){
      add(q.getTerm());
    }
    protected void traverse(    SpanTermQuery q){
      add(q.getTerm());
    }
    protected void traverse(    SpanExactQuery q){
    }
    protected void traverse(    BooleanQuery bq){
      BooleanClause[] clauses=bq.getClauses();
      for (int i=0; i < clauses.length; i++) {
        if (clauses[i].getOccur() != BooleanClause.Occur.MUST_NOT)         traverseQuery(clauses[i].getQuery());
      }
    }
    protected void traverse(    SpanChunkedNotQuery nq){
      traverseQuery(nq.getInclude());
    }
    protected void traverse(    SpanNotQuery nq){
      traverseQuery(nq.getInclude());
    }
    protected void traverse(    SpanNotNearQuery nq){
      traverseQuery(nq.getInclude());
    }
  }
;
  trav.traverseQuery(query);
  LinkedHashMap fieldsMap=new LinkedHashMap();
  for (Iterator ti=termMap.keySet().iterator(); ti.hasNext(); ) {
    String word=(String)ti.next();
    LinkedHashSet fieldsSet=(LinkedHashSet)termMap.get(word);
    if (!fieldsMap.containsKey(fieldsSet))     fieldsMap.put(fieldsSet,new LinkedHashSet());
    ((LinkedHashSet)fieldsMap.get(fieldsSet)).add(word);
  }
  return fieldsMap;
}