Program: 8998
Project: 8998
Buggy source:
@Override public Iterator<ResultRowImpl> getRows(){
  prepare();
  if (explain) {
    String plan=getPlan();
    columns=new ColumnImpl[]{new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str")};
    ResultRowImpl r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString(plan)},null);
    return Arrays.asList(r).iterator();
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",statement);
    LOG.debug("String_Node_Str",getPlan());
  }
  RowIterator rowIt=new RowIterator(context.getBaseState());
  Comparator<ResultRowImpl> orderBy;
  boolean sortUsingIndex=false;
  if (selectors.size() == 1) {
    IndexPlan plan=selectors.get(0).getExecutionPlan().getIndexPlan();
    if (plan != null) {
      List<OrderEntry> list=plan.getSortOrder();
      if (list != null && list.size() == orderings.length) {
        sortUsingIndex=true;
        for (int i=0; i < list.size(); i++) {
          OrderEntry e=list.get(i);
          OrderingImpl o=orderings[i];
          DynamicOperandImpl op=o.getOperand();
          if (!(op instanceof PropertyValueImpl)) {
            sortUsingIndex=false;
            break;
          }
          String pn=((PropertyValueImpl)op).getPropertyName();
          if (!pn.equals(e.getPropertyName())) {
            sortUsingIndex=false;
            break;
          }
          if (o.isDescending() != (e.getOrder() == Order.DESCENDING)) {
            sortUsingIndex=false;
            break;
          }
        }
      }
    }
  }
  if (sortUsingIndex) {
    orderBy=null;
  }
 else {
    orderBy=ResultRowImpl.getComparator(orderings);
  }
  Iterator<ResultRowImpl> it=FilterIterators.newCombinedFilter(rowIt,distinct,limit,offset,orderBy);
  if (measure) {
    while (it.hasNext()) {
      it.next();
    }
    columns=new ColumnImpl[]{new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str"),new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str")};
    ArrayList<ResultRowImpl> list=new ArrayList<ResultRowImpl>();
    ResultRowImpl r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString("String_Node_Str"),PropertyValues.newLong(rowIt.getReadCount())},null);
    list.add(r);
    for (    SelectorImpl selector : selectors) {
      r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString(selector.getSelectorName()),PropertyValues.newLong(selector.getScanCount())},null);
      list.add(r);
    }
    it=list.iterator();
  }
  return it;
}

Fixed version (ground truth):
@Override public Iterator<ResultRowImpl> getRows(){
  prepare();
  if (explain) {
    String plan=getPlan();
    columns=new ColumnImpl[]{new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str")};
    ResultRowImpl r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString(plan)},null);
    return Arrays.asList(r).iterator();
  }
  if (LOG.isDebugEnabled()) {
    LOG.debug("String_Node_Str",statement);
    LOG.debug("String_Node_Str",getPlan());
  }
  RowIterator rowIt=new RowIterator(context.getBaseState());
  Comparator<ResultRowImpl> orderBy;
  boolean sortUsingIndex=false;
  if (orderings != null && selectors.size() == 1) {
    IndexPlan plan=selectors.get(0).getExecutionPlan().getIndexPlan();
    if (plan != null) {
      List<OrderEntry> list=plan.getSortOrder();
      if (list != null && list.size() == orderings.length) {
        sortUsingIndex=true;
        for (int i=0; i < list.size(); i++) {
          OrderEntry e=list.get(i);
          OrderingImpl o=orderings[i];
          DynamicOperandImpl op=o.getOperand();
          if (!(op instanceof PropertyValueImpl)) {
            sortUsingIndex=false;
            break;
          }
          String pn=((PropertyValueImpl)op).getPropertyName();
          if (!pn.equals(e.getPropertyName())) {
            sortUsingIndex=false;
            break;
          }
          if (o.isDescending() != (e.getOrder() == Order.DESCENDING)) {
            sortUsingIndex=false;
            break;
          }
        }
      }
    }
  }
  if (sortUsingIndex) {
    orderBy=null;
  }
 else {
    orderBy=ResultRowImpl.getComparator(orderings);
  }
  Iterator<ResultRowImpl> it=FilterIterators.newCombinedFilter(rowIt,distinct,limit,offset,orderBy);
  if (measure) {
    while (it.hasNext()) {
      it.next();
    }
    columns=new ColumnImpl[]{new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str"),new ColumnImpl("String_Node_Str","String_Node_Str","String_Node_Str")};
    ArrayList<ResultRowImpl> list=new ArrayList<ResultRowImpl>();
    ResultRowImpl r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString("String_Node_Str"),PropertyValues.newLong(rowIt.getReadCount())},null);
    list.add(r);
    for (    SelectorImpl selector : selectors) {
      r=new ResultRowImpl(this,Tree.EMPTY_ARRAY,new PropertyValue[]{PropertyValues.newString(selector.getSelectorName()),PropertyValues.newLong(selector.getScanCount())},null);
      list.add(r);
    }
    it=list.iterator();
  }
  return it;
}