Program: 31171
Project: 31171
Buggy source:
private RecordSource compileJoins(QueryModel model,JournalReaderFactory factory) throws ParserException {
  ObjList<QueryModel> joinModels=model.getJoinModels();
  IntList ordered=model.getOrderedJoinModels();
  RecordSource master=null;
  try {
    boolean needColumnNameHistogram=model.getColumns().size() > 0;
    model.getColumnNameHistogram().clear();
    for (int i=0, n=ordered.size(); i < n; i++) {
      int index=ordered.getQuick(i);
      QueryModel m=joinModels.getQuick(index);
      RecordSource slave=m.getRecordSource();
      if (slave == null) {
        slave=compileJournal(m,factory);
        if (m.getAlias() != null) {
          slave.getMetadata().setAlias(m.getAlias().token);
        }
      }
      if (needColumnNameHistogram) {
        model.createColumnNameHistogram(slave);
      }
      if (master == null) {
        master=analyseAndCompileOrderBy(model,slave);
      }
 else {
switch (m.getJoinType()) {
case QueryModel.JOIN_CROSS:
          master=new CrossJoinRecordSource(master,slave);
        break;
case QueryModel.JOIN_ASOF:
      master=createAsOfJoin(model.getTimestamp(),m,master,slave);
    break;
default :
  master=createHashJoin(m,master,slave);
break;
}
}
ExprNode filter=m.getPostJoinWhereClause();
if (filter != null) {
master=new FilteredRecordSource(master,virtualColumnBuilder.createVirtualColumn(model,filter,master.getMetadata()),filter);
}
}
if (joinModelIsFalse(model)) {
return new NoOpJournalRecordSource(master);
}
return master;
}
 catch (ParserException e) {
Misc.free(master);
throw e;
}
}

Fixed version (ground truth):
private RecordSource compileJoins(QueryModel model,JournalReaderFactory factory) throws ParserException {
  ObjList<QueryModel> joinModels=model.getJoinModels();
  IntList ordered=model.getOrderedJoinModels();
  RecordSource master=null;
  try {
    boolean needColumnNameHistogram=model.getColumns().size() > 0;
    model.getColumnNameHistogram().clear();
    for (int i=0, n=ordered.size(); i < n; i++) {
      int index=ordered.getQuick(i);
      QueryModel m=joinModels.getQuick(index);
      RecordSource slave=m.getRecordSource();
      if (slave == null) {
        slave=compileJournal(m,factory);
      }
 else {
        slave=filter(m,slave);
      }
      if (m.getAlias() != null) {
        slave.getMetadata().setAlias(m.getAlias().token);
      }
      if (needColumnNameHistogram) {
        model.createColumnNameHistogram(slave);
      }
      if (master == null) {
        master=analyseAndCompileOrderBy(model,slave);
      }
 else {
switch (m.getJoinType()) {
case QueryModel.JOIN_CROSS:
          master=new CrossJoinRecordSource(master,slave);
        break;
case QueryModel.JOIN_ASOF:
      master=createAsOfJoin(model.getTimestamp(),m,master,slave);
    break;
default :
  master=createHashJoin(m,master,slave);
break;
}
}
ExprNode filter=m.getPostJoinWhereClause();
if (filter != null) {
master=new FilteredRecordSource(master,virtualColumnBuilder.createVirtualColumn(model,filter,master.getMetadata()),filter);
}
}
if (joinModelIsFalse(model)) {
return new NoOpJournalRecordSource(master);
}
return master;
}
 catch (ParserException e) {
Misc.free(master);
throw e;
}
}