Program: 38655
Project: 38655
Buggy source:
@Override public JsRecords execute(IDb db) throws IOException {
  Set<Long> validSubScopeIds=InternalScopeGetter.getValidSubScopeIds(db,table,executionScopeId,subScopeIds,ignoreInvalidSubScopes);
  if (validSubScopeIds.isEmpty()) {
    return JsRecords.empty(executionScopeId);
  }
  Records records=db.createQuery().from(table.table).where(table.typeColumn.notEqualTo(ValueType.SCOPE.value)).where(table.scopeColumn.in(validSubScopeIds)).select(table.scopeColumn,table.typeColumn,table.keyColumn,table.valueColumn).orderBy(table.scopeColumn).orderBy(table.idColumn).fetch();
  if (records.isEmpty()) {
    List<JsRecord> emptyRecords=Lists.newLinkedList();
    for (    long subScopeId : validSubScopeIds) {
      emptyRecords.add(JsRecord.empty(subScopeId));
    }
    return new JsRecords(executionScopeId,emptyRecords);
  }
  List<JsRecord> jsRecords=Lists.newLinkedList();
  Long previousScopeId=records.get(0).get(table.scopeColumn);
  InternalRecordCreator recordCreator=new InternalRecordCreator(table,selectedKeys);
  Iterator<Record> iterator=records.iterator();
  while (iterator.hasNext()) {
    Record record=iterator.next();
    Long currentScopeId=record.get(table.scopeColumn);
    if (!Objects.equals(previousScopeId,currentScopeId)) {
      if (recordCreator.hasNewRecord()) {
        jsRecords.add(recordCreator.createNewRecord(currentScopeId));
      }
      previousScopeId=currentScopeId;
    }
    recordCreator.appendRecord(record);
    if (!iterator.hasNext() && recordCreator.hasNewRecord()) {
      jsRecords.add(recordCreator.createNewRecord(currentScopeId));
    }
  }
  return new JsRecords(executionScopeId,jsRecords);
}

Fixed version (ground truth):
@Override public JsRecords execute(IDb db) throws IOException {
  Set<Long> validSubScopeIds=InternalScopeGetter.getValidSubScopeIds(db,table,executionScopeId,subScopeIds,ignoreInvalidSubScopes);
  if (validSubScopeIds.isEmpty()) {
    return JsRecords.empty(executionScopeId);
  }
  Records records=db.createQuery().from(table.table).where(table.typeColumn.notEqualTo(ValueType.SCOPE.value)).where(table.scopeColumn.in(validSubScopeIds)).select(table.scopeColumn,table.typeColumn,table.keyColumn,table.valueColumn).orderBy(table.scopeColumn).orderBy(table.idColumn).fetch();
  if (records.isEmpty()) {
    List<JsRecord> emptyRecords=Lists.newLinkedList();
    for (    long subScopeId : validSubScopeIds) {
      emptyRecords.add(JsRecord.empty(subScopeId));
    }
    return new JsRecords(executionScopeId,emptyRecords);
  }
  List<JsRecord> jsRecords=Lists.newLinkedList();
  Long previousScopeId=records.get(0).get(table.scopeColumn);
  InternalRecordCreator recordCreator=new InternalRecordCreator(table,selectedKeys);
  Iterator<Record> iterator=records.iterator();
  while (iterator.hasNext()) {
    Record record=iterator.next();
    Long currentScopeId=record.get(table.scopeColumn);
    if (!Objects.equals(previousScopeId,currentScopeId)) {
      if (recordCreator.hasNewRecord()) {
        jsRecords.add(recordCreator.createNewRecord(previousScopeId));
      }
      previousScopeId=currentScopeId;
    }
    recordCreator.appendRecord(record);
    if (!iterator.hasNext() && recordCreator.hasNewRecord()) {
      jsRecords.add(recordCreator.createNewRecord(currentScopeId));
    }
  }
  return new JsRecords(executionScopeId,jsRecords);
}