Program: 31305
Project: 31305
Buggy source:
@SuppressFBWarnings("String_Node_Str") private RecordSource selectColumns0(final RecordSource recordSource,QueryModel model) throws ParserException {
  final ObjList<QueryColumn> columns=model.getColumns();
  final CharSequenceIntHashMap columnNameHistogram=model.getColumnNameHistogram();
  final RecordMetadata meta=recordSource.getMetadata();
  this.outerVirtualColumns.clear();
  this.aggregators.clear();
  this.selectedColumns.clear();
  this.selectedColumnAliases.clear();
  this.groupKeyColumns.clear();
  this.aggregateColumnSequence=0;
  this.analyticColumns.clear();
  ObjList<VirtualColumn> virtualColumns=null;
  for (int i=0, k=columns.size(); i < k; i++) {
    final QueryColumn qc=columns.getQuick(i);
    final ExprNode node=qc.getAst();
    final boolean analytic=qc instanceof AnalyticColumn;
    if (!analytic && node.type == ExprNode.NodeType.LITERAL) {
      if (meta.getColumnIndexQuiet(node.token) == -1) {
        throw QueryError.invalidColumn(node.position,node.token);
      }
      if (columnNameHistogram.get(node.token) > 0) {
        throw QueryError.ambiguousColumn(node.position);
      }
      selectedColumns.add(node.token);
      addAlias(node.position,qc.getAlias() == null ? node.token : qc.getAlias());
      groupKeyColumns.add(node.token);
      continue;
    }
    if (qc.getAlias() == null) {
      qc.of(createAlias(aggregateColumnSequence++),node);
    }
    selectedColumns.add(qc.getAlias());
    addAlias(node.position,qc.getAlias());
    if (!analytic && node.type == ExprNode.NodeType.FUNCTION && FunctionFactories.isAggregate(node.token)) {
      aggregators.add(qc);
      continue;
    }
    if (node.type == ExprNode.NodeType.OPERATION || node.type == ExprNode.NodeType.FUNCTION) {
      int beforeSplit=aggregators.size();
      splitAggregates(node,aggregators);
      if (beforeSplit < aggregators.size()) {
        outerVirtualColumns.add(qc);
        continue;
      }
    }
    if (virtualColumns == null) {
      virtualColumns=new ObjList<>();
    }
    if (analytic) {
      if (qc.getAst().type != ExprNode.NodeType.FUNCTION) {
        throw QueryError.$(qc.getAst().position,"String_Node_Str");
      }
      analyticColumns.add((AnalyticColumn)qc);
    }
 else {
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),recordSource.getMetadata());
      vc.setName(qc.getAlias());
      virtualColumns.add(vc);
    }
    groupKeyColumns.add(qc.getAlias());
  }
  RecordSource rs=recordSource;
  if (virtualColumns != null) {
    rs=new VirtualColumnRecordSource(rs,virtualColumns);
  }
  ExprNode sampleBy=model.getSampleBy();
  int asz=aggregators.size();
  if (asz > 0) {
    ObjList<AggregatorFunction> af=new ObjList<>(asz);
    for (int i=0; i < asz; i++) {
      QueryColumn qc=aggregators.get(i);
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),rs.getMetadata());
      if (vc instanceof AggregatorFunction) {
        vc.setName(qc.getAlias());
        af.add((AggregatorFunction)vc);
      }
 else {
        throw QueryError.$(qc.getAst().position,"String_Node_Str");
      }
    }
    if (sampleBy == null) {
      rs=new AggregatedRecordSource(rs,groupKeyColumns,af,configuration.getDbAggregatePage());
    }
 else {
      TimestampSampler sampler=SamplerFactory.from(sampleBy.token);
      if (sampler == null) {
        throw QueryError.$(sampleBy.position,"String_Node_Str");
      }
      rs=new ResampledRecordSource(rs,getTimestampIndex(model,model.getTimestamp(),rs.getMetadata()),groupKeyColumns,af,sampler,configuration.getDbAggregatePage());
    }
  }
 else {
    if (sampleBy != null) {
      throw QueryError.$(sampleBy.position,"String_Node_Str");
    }
  }
  if (outerVirtualColumns.size() > 0) {
    ObjList<VirtualColumn> outer=new ObjList<>(outerVirtualColumns.size());
    for (int i=0, n=outerVirtualColumns.size(); i < n; i++) {
      QueryColumn qc=outerVirtualColumns.get(i);
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),rs.getMetadata());
      vc.setName(qc.getAlias());
      outer.add(vc);
    }
    rs=new VirtualColumnRecordSource(rs,outer);
  }
  if (analyticColumns.size() > 0) {
    final int n=analyticColumns.size();
    final ObjList<AnalyticFunction> functions=new ObjList<>(n);
    final RecordMetadata metadata=rs.getMetadata();
    boolean hasTwoPassFunctions=false;
    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());
      if (f == null) {
        throw QueryError.$(col.getAst().position,"String_Node_Str");
      }
      if (!hasTwoPassFunctions && (f instanceof TwoPassAnalyticFunction)) {
        hasTwoPassFunctions=true;
      }
      functions.add(f);
    }
    if (hasTwoPassFunctions) {
      rs=new CachingAnalyticRecordSource(configuration.getDbAnalyticWindowPage(),rs,functions);
    }
 else {
      rs=new AnalyticRecordSource(rs,functions);
    }
  }
  if (selectedColumns.size() > 0) {
    rs=new SelectedColumnsRecordSource(rs,selectedColumns,selectedColumnAliases);
  }
  return rs;
}

Fixed version (ground truth):
@SuppressFBWarnings("String_Node_Str") private RecordSource selectColumns0(final RecordSource recordSource,QueryModel model) throws ParserException {
  final ObjList<QueryColumn> columns=model.getColumns();
  final CharSequenceIntHashMap columnNameHistogram=model.getColumnNameHistogram();
  final RecordMetadata meta=recordSource.getMetadata();
  this.outerVirtualColumns.clear();
  this.aggregators.clear();
  this.selectedColumns.clear();
  this.selectedColumnAliases.clear();
  this.groupKeyColumns.clear();
  this.aggregateColumnSequence=0;
  this.analyticColumns.clear();
  ObjList<VirtualColumn> virtualColumns=null;
  for (int i=0, k=columns.size(); i < k; i++) {
    final QueryColumn qc=columns.getQuick(i);
    final ExprNode node=qc.getAst();
    final boolean analytic=qc instanceof AnalyticColumn;
    if (!analytic && node.type == ExprNode.NodeType.LITERAL) {
      if (meta.getColumnIndexQuiet(node.token) == -1) {
        throw QueryError.invalidColumn(node.position,node.token);
      }
      if (columnNameHistogram.get(node.token) > 0) {
        throw QueryError.ambiguousColumn(node.position);
      }
      selectedColumns.add(node.token);
      addAlias(node.position,qc.getAlias() == null ? node.token : qc.getAlias());
      groupKeyColumns.add(node.token);
      continue;
    }
    if (qc.getAlias() == null) {
      qc.of(createAlias(aggregateColumnSequence++),node);
    }
    selectedColumns.add(qc.getAlias());
    addAlias(node.position,qc.getAlias());
    if (!analytic && node.type == ExprNode.NodeType.FUNCTION && FunctionFactories.isAggregate(node.token)) {
      aggregators.add(qc);
      continue;
    }
    if (node.type == ExprNode.NodeType.OPERATION || node.type == ExprNode.NodeType.FUNCTION) {
      int beforeSplit=aggregators.size();
      splitAggregates(node,aggregators);
      if (beforeSplit < aggregators.size()) {
        outerVirtualColumns.add(qc);
        continue;
      }
    }
    if (analytic) {
      if (qc.getAst().type != ExprNode.NodeType.FUNCTION) {
        throw QueryError.$(qc.getAst().position,"String_Node_Str");
      }
      if (aggregators.size() > 0) {
        throw QueryError.$(qc.getAst().position,"String_Node_Str");
      }
      analyticColumns.add((AnalyticColumn)qc);
    }
 else {
      if (virtualColumns == null) {
        virtualColumns=new ObjList<>();
      }
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),recordSource.getMetadata());
      vc.setName(qc.getAlias());
      virtualColumns.add(vc);
    }
    groupKeyColumns.add(qc.getAlias());
  }
  RecordSource rs=recordSource;
  if (virtualColumns != null) {
    rs=new VirtualColumnRecordSource(rs,virtualColumns);
  }
  ExprNode sampleBy=model.getSampleBy();
  int asz=aggregators.size();
  if (asz > 0) {
    ObjList<AggregatorFunction> af=new ObjList<>(asz);
    for (int i=0; i < asz; i++) {
      QueryColumn qc=aggregators.get(i);
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),rs.getMetadata());
      if (vc instanceof AggregatorFunction) {
        vc.setName(qc.getAlias());
        af.add((AggregatorFunction)vc);
      }
 else {
        throw QueryError.$(qc.getAst().position,"String_Node_Str");
      }
    }
    if (sampleBy == null) {
      rs=new AggregatedRecordSource(rs,groupKeyColumns,af,configuration.getDbAggregatePage());
    }
 else {
      TimestampSampler sampler=SamplerFactory.from(sampleBy.token);
      if (sampler == null) {
        throw QueryError.$(sampleBy.position,"String_Node_Str");
      }
      rs=new ResampledRecordSource(rs,getTimestampIndex(model,model.getTimestamp(),rs.getMetadata()),groupKeyColumns,af,sampler,configuration.getDbAggregatePage());
    }
  }
 else {
    if (sampleBy != null) {
      throw QueryError.$(sampleBy.position,"String_Node_Str");
    }
  }
  if (outerVirtualColumns.size() > 0) {
    ObjList<VirtualColumn> outer=new ObjList<>(outerVirtualColumns.size());
    for (int i=0, n=outerVirtualColumns.size(); i < n; i++) {
      QueryColumn qc=outerVirtualColumns.get(i);
      VirtualColumn vc=virtualColumnBuilder.createVirtualColumn(model,qc.getAst(),rs.getMetadata());
      vc.setName(qc.getAlias());
      outer.add(vc);
    }
    rs=new VirtualColumnRecordSource(rs,outer);
  }
  if (analyticColumns.size() > 0) {
    final int n=analyticColumns.size();
    final ObjList<AnalyticFunction> functions=new ObjList<>(n);
    final RecordMetadata metadata=rs.getMetadata();
    boolean hasTwoPassFunctions=false;
    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());
      if (f == null) {
        throw QueryError.$(col.getAst().position,"String_Node_Str");
      }
      if (!hasTwoPassFunctions && (f instanceof TwoPassAnalyticFunction)) {
        hasTwoPassFunctions=true;
      }
      functions.add(f);
    }
    if (hasTwoPassFunctions) {
      rs=new CachingAnalyticRecordSource(configuration.getDbAnalyticWindowPage(),rs,functions);
    }
 else {
      rs=new AnalyticRecordSource(rs,functions);
    }
  }
  if (selectedColumns.size() > 0) {
    rs=new SelectedColumnsRecordSource(rs,selectedColumns,selectedColumnAliases);
  }
  return rs;
}