Program: 24762
Project: 24762
Buggy source:
/** 
 * Iterate all the spans from the text query that match the sectionType query also.
 */
public Spans getSpans(final IndexReader reader,final Searcher searcher) throws IOException {
  ArrayList newClauses=new ArrayList(clauses.length);
  for (int i=0; i < clauses.length; i++) {
    if (!(clauses[i] instanceof SpanTermQuery))     throw new RuntimeException("String_Node_Str");
    boolean isFirst=(i == 0);
    boolean isLast=(i == clauses.length - 1);
    if (!isFirst && !isLast) {
      newClauses.add(clauses[i]);
      continue;
    }
    SpanTermQuery oldClause=(SpanTermQuery)clauses[i];
    String oldTerm=oldClause.getTerm().text();
    String field=oldClause.getTerm().field();
    SpanQuery detachedStartQuery=new SpanTermQuery(new Term(field,"String_Node_Str" + Constants.FIELD_START_MARKER));
    SpanQuery detachedEndQuery=new SpanTermQuery(new Term(field,"String_Node_Str" + Constants.FIELD_END_MARKER));
    ArrayList orClauses=new ArrayList();
    for (int startAtt=0; startAtt < 3; ++startAtt) {
      if ((startAtt == 0 && isFirst) || (startAtt != 0 && !isFirst))       continue;
      for (int endAtt=0; endAtt < 3; ++endAtt) {
        if ((endAtt == 0 && isLast) || (endAtt != 0 && !isLast))         continue;
        ArrayList phraseClauses=new ArrayList();
        if (startAtt == 1)         phraseClauses.add(detachedStartQuery);
        String newTerm=oldTerm;
        if (startAtt == 2)         newTerm=Constants.FIELD_START_MARKER + newTerm;
        if (endAtt == 2)         newTerm=newTerm + Constants.FIELD_END_MARKER;
        SpanQuery newClause=new SpanTermQuery(new Term(field,newTerm));
        newClause.setBoost(oldClause.getBoost());
        phraseClauses.add(newClause);
        if (endAtt == 1)         phraseClauses.add(detachedEndQuery);
        int nTerms=phraseClauses.size();
        if (nTerms == 1)         orClauses.add(phraseClauses.get(0));
 else {
          orClauses.add(new SpanNearQuery((SpanQuery[])phraseClauses.toArray(new SpanQuery[nTerms]),0,true));
        }
      }
    }
    if (orClauses.size() == 1) {
      newClauses.add(orClauses.get(0));
      continue;
    }
    SpanOrQuery orQuery=new SpanOrQuery((SpanQuery[])orClauses.toArray(new SpanQuery[orClauses.size()]));
    newClauses.add(orQuery);
  }
  SpanQuery q=new SpanNearQuery((SpanQuery[])newClauses.toArray(new SpanQuery[newClauses.size()]),0,true);
  q.setSpanRecording(getSpanRecording());
  return q.getSpans(reader,searcher);
}

Fixed version (ground truth):
/** 
 * Iterate all the spans from the text query that match the sectionType query also.
 */
public Spans getSpans(final IndexReader reader,final Searcher searcher) throws IOException {
  ArrayList newClauses=new ArrayList(clauses.length);
  for (int i=0; i < clauses.length; i++) {
    if (!(clauses[i] instanceof SpanTermQuery))     throw new RuntimeException("String_Node_Str");
    boolean isFirst=(i == 0);
    boolean isLast=(i == clauses.length - 1);
    if (!isFirst && !isLast) {
      newClauses.add(clauses[i]);
      continue;
    }
    SpanTermQuery oldClause=(SpanTermQuery)clauses[i];
    String oldTerm=oldClause.getTerm().text();
    String field=oldClause.getTerm().field();
    int length=oldClause.getTermLength();
    SpanQuery detachedStartQuery=new SpanTermQuery(new Term(field,"String_Node_Str" + Constants.FIELD_START_MARKER));
    SpanQuery detachedEndQuery=new SpanTermQuery(new Term(field,"String_Node_Str" + Constants.FIELD_END_MARKER));
    ArrayList orClauses=new ArrayList();
    for (int startAtt=0; startAtt < 3; ++startAtt) {
      if ((startAtt == 0 && isFirst) || (startAtt != 0 && !isFirst))       continue;
      for (int endAtt=0; endAtt < 3; ++endAtt) {
        if ((endAtt == 0 && isLast) || (endAtt != 0 && !isLast))         continue;
        ArrayList phraseClauses=new ArrayList();
        if (startAtt == 1)         phraseClauses.add(detachedStartQuery);
        String newTerm=oldTerm;
        if (startAtt == 2)         newTerm=Constants.FIELD_START_MARKER + newTerm;
        if (endAtt == 2)         newTerm=newTerm + Constants.FIELD_END_MARKER;
        SpanQuery newClause=new SpanTermQuery(new Term(field,newTerm),length);
        newClause.setBoost(oldClause.getBoost());
        phraseClauses.add(newClause);
        if (endAtt == 1)         phraseClauses.add(detachedEndQuery);
        int nTerms=phraseClauses.size();
        if (nTerms == 1)         orClauses.add(phraseClauses.get(0));
 else {
          orClauses.add(new SpanNearQuery((SpanQuery[])phraseClauses.toArray(new SpanQuery[nTerms]),0,true));
        }
      }
    }
    if (orClauses.size() == 1) {
      newClauses.add(orClauses.get(0));
      continue;
    }
    SpanOrQuery orQuery=new SpanOrQuery((SpanQuery[])orClauses.toArray(new SpanQuery[orClauses.size()]));
    newClauses.add(orQuery);
  }
  SpanQuery q=new SpanNearQuery((SpanQuery[])newClauses.toArray(new SpanQuery[newClauses.size()]),0,true);
  q.setSpanRecording(getSpanRecording());
  return q.getSpans(reader,searcher);
}