Program: 31255
Project: 31255
Buggy source:
private RecordSource compileAnalytic(RecordSource rs,QueryModel model) throws ParserException {
  final int n=analyticColumns.size();
  grouppedAnalytic.clear();
  analyticComparators.clear();
  final RecordMetadata metadata=rs.getMetadata();
  ObjList<AnalyticFunction> naturalOrderFunctions=null;
  for (int i=0; i < n; i++) {
    AnalyticColumn col=analyticColumns.getQuick(i);
    ObjList<VirtualColumn> partitionBy=null;
    int psz=col.getPartitionBy().size();
    if (psz > 0) {
      partitionBy=new ObjList<>(psz);
      for (int j=0; j < psz; j++) {
        partitionBy.add(virtualColumnBuilder.createVirtualColumn(model,col.getPartitionBy().getQuick(j),metadata));
      }
    }
    if (col.getAst().paramCount > 1) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    if (col.getAst().paramCount < 1) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    VirtualColumn valueColumn=virtualColumnBuilder.createVirtualColumn(model,col.getAst().rhs,metadata);
    valueColumn.setName(col.getAlias());
    AnalyticFunction f=AnalyticFunctionFactories.newInstance(configuration,col.getAst().token,valueColumn,partitionBy,rs.supportsRowIdAccess(),orderedAnalytic);
    if (f == null) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    if (col.getOrderBy().size() > 0) {
      IntList order=toOrderIndices(metadata,col.getOrderBy(),col.getOrderByDirection());
      ObjList<AnalyticFunction> funcs=grouppedAnalytic.get(order);
      if (funcs == null) {
        grouppedAnalytic.put(order,funcs=new ObjList<>());
      }
      funcs.add(f);
    }
 else {
      if (naturalOrderFunctions == null) {
        naturalOrderFunctions=new ObjList<>();
      }
      naturalOrderFunctions.add(f);
    }
  }
  ObjList<ObjList<AnalyticFunction>> funcs=new ObjList<>(grouppedAnalytic.size());
  for (  ObjObjHashMap.Entry<IntList,ObjList<AnalyticFunction>> e : grouppedAnalytic) {
    analyticComparators.add(cc.compile(metadata,e.key));
    funcs.add(e.value);
  }
  if (naturalOrderFunctions != null) {
    analyticComparators.add(null);
    funcs.add(naturalOrderFunctions);
  }
  return new AnalyticRecordSource(configuration.getDbAnalyticWindowPage(),configuration.getDbSortKeyPage(),rs,analyticComparators,funcs);
}

Fixed version (ground truth):
private RecordSource compileAnalytic(RecordSource rs,QueryModel model) throws ParserException {
  final int n=analyticColumns.size();
  grouppedAnalytic.clear();
  analyticComparators.clear();
  final RecordMetadata metadata=rs.getMetadata();
  ObjList<AnalyticFunction> naturalOrderFunctions=null;
  for (int i=0; i < n; i++) {
    AnalyticColumn col=analyticColumns.getQuick(i);
    ObjList<VirtualColumn> partitionBy=null;
    int psz=col.getPartitionBy().size();
    if (psz > 0) {
      partitionBy=new ObjList<>(psz);
      for (int j=0; j < psz; j++) {
        partitionBy.add(virtualColumnBuilder.createVirtualColumn(model,col.getPartitionBy().getQuick(j),metadata));
      }
    }
    if (col.getAst().paramCount > 1) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    if (col.getAst().paramCount < 1) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    VirtualColumn valueColumn=virtualColumnBuilder.createVirtualColumn(model,col.getAst().rhs,metadata);
    valueColumn.setName(col.getAlias());
    AnalyticFunction f=AnalyticFunctionFactories.newInstance(configuration,col.getAst().token,valueColumn,partitionBy,rs.supportsRowIdAccess(),col.getOrderBy().size() > 0);
    if (f == null) {
      throw QueryError.$(col.getAst().position,"String_Node_Str");
    }
    if (col.getOrderBy().size() > 0) {
      IntList order=toOrderIndices(metadata,col.getOrderBy(),col.getOrderByDirection());
      ObjList<AnalyticFunction> funcs=grouppedAnalytic.get(order);
      if (funcs == null) {
        grouppedAnalytic.put(order,funcs=new ObjList<>());
      }
      funcs.add(f);
    }
 else {
      if (naturalOrderFunctions == null) {
        naturalOrderFunctions=new ObjList<>();
      }
      naturalOrderFunctions.add(f);
    }
  }
  ObjList<ObjList<AnalyticFunction>> funcs=new ObjList<>(grouppedAnalytic.size());
  for (  ObjObjHashMap.Entry<IntList,ObjList<AnalyticFunction>> e : grouppedAnalytic) {
    analyticComparators.add(cc.compile(metadata,e.key));
    funcs.add(e.value);
  }
  if (naturalOrderFunctions != null) {
    analyticComparators.add(null);
    funcs.add(naturalOrderFunctions);
  }
  return new AnalyticRecordSource(configuration.getDbAnalyticWindowPage(),configuration.getDbSortKeyPage(),rs,analyticComparators,funcs);
}