Program: 30744
Project: 30744
Buggy source:
private QueryModel parseQuery(boolean subQuery) throws ParserException {
  CharSequence tok;
  QueryModel model=queryModelPool.next();
  tok=tok();
  if (Chars.equals(tok,"String_Node_Str")) {
    parseWithClauses(model);
    tok=tok();
  }
  if (Chars.equals(tok,"String_Node_Str")) {
    parseSelectColumns(model);
    tok=tok();
  }
  if (Chars.equals(tok,'(')) {
    model.setNestedModel(parseQuery(true));
    expectTok(')');
    tok=lexer.optionTok();
    if (tok != null && !journalAliasStop.contains(tok)) {
      lexer.unparse();
      model.setAlias(literal());
      tok=lexer.optionTok();
    }
    ExprNode timestamp=parseTimestamp(tok);
    if (timestamp != null) {
      model.setTimestamp(timestamp);
      tok=lexer.optionTok();
    }
  }
 else {
    lexer.unparse();
    parseWithClauseOrJournalName(model,model);
    tok=lexer.optionTok();
    if (tok != null && !journalAliasStop.contains(tok)) {
      lexer.unparse();
      model.setAlias(literal());
      tok=lexer.optionTok();
    }
    ExprNode timestamp=parseTimestamp(tok);
    if (timestamp != null) {
      model.setTimestamp(timestamp);
      tok=lexer.optionTok();
    }
    if (Chars.equalsNc("String_Node_Str",tok)) {
      parseLatestBy(model);
      tok=lexer.optionTok();
    }
  }
  int joinType;
  while (tok != null && (joinType=joinStartSet.get(tok)) != -1) {
    model.addJoinModel(parseJoin(tok,joinType,model));
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    model.setWhereClause(expr());
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    expectTok(tok(),"String_Node_Str");
    model.setSampleBy(expectLiteral());
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    expectTok(tok(),"String_Node_Str");
    do {
      tok=tok();
      if (Chars.equals(tok,')')) {
        throw err("String_Node_Str");
      }
      lexer.unparse();
      ExprNode n=expectLiteral();
      tok=lexer.optionTok();
      if (tok != null && Chars.equalsIgnoreCase(tok,"String_Node_Str")) {
        model.addOrderBy(n,QueryModel.ORDER_DIRECTION_DESCENDING);
        tok=lexer.optionTok();
      }
 else {
        model.addOrderBy(n,QueryModel.ORDER_DIRECTION_ASCENDING);
        if (tok != null && Chars.equalsIgnoreCase(tok,"String_Node_Str")) {
          tok=lexer.optionTok();
        }
      }
      if (model.getOrderBy().size() >= MAX_ORDER_BY_COLUMNS) {
        throw err("String_Node_Str");
      }
    }
 while (tok != null && Chars.equals(tok,','));
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    ExprNode lo=expr();
    ExprNode hi=null;
    tok=lexer.optionTok();
    if (tok != null && Chars.equals(tok,',')) {
      hi=expr();
      tok=lexer.optionTok();
    }
    model.setLimit(lo,hi);
  }
  if (subQuery) {
    lexer.unparse();
  }
 else   if (tok != null) {
    throw ParserException.position(lexer.position()).put("String_Node_Str").put(tok);
  }
  resolveJoinColumns(model);
  return model;
}

Fixed version (ground truth):
private QueryModel parseQuery(boolean subQuery) throws ParserException {
  CharSequence tok;
  QueryModel model=queryModelPool.next();
  tok=tok();
  if (Chars.equals(tok,"String_Node_Str")) {
    parseWithClauses(model);
    tok=tok();
  }
  if (Chars.equals(tok,"String_Node_Str")) {
    parseSelectColumns(model);
    tok=tok();
  }
  if (Chars.equals(tok,'(')) {
    model.setNestedModel(parseQuery(true));
    expectTok(')');
    tok=lexer.optionTok();
    if (tok != null && !journalAliasStop.contains(tok)) {
      lexer.unparse();
      model.setAlias(literal());
      tok=lexer.optionTok();
    }
    ExprNode timestamp=parseTimestamp(tok);
    if (timestamp != null) {
      model.setTimestamp(timestamp);
      tok=lexer.optionTok();
    }
  }
 else {
    lexer.unparse();
    parseWithClauseOrJournalName(model,model);
    tok=lexer.optionTok();
    if (tok != null && !journalAliasStop.contains(tok)) {
      lexer.unparse();
      model.setAlias(literal());
      tok=lexer.optionTok();
    }
    ExprNode timestamp=parseTimestamp(tok);
    if (timestamp != null) {
      model.setTimestamp(timestamp);
      tok=lexer.optionTok();
    }
    if (Chars.equalsNc("String_Node_Str",tok)) {
      parseLatestBy(model);
      tok=lexer.optionTok();
    }
  }
  int joinType;
  while (tok != null && (joinType=joinStartSet.get(tok)) != -1) {
    model.addJoinModel(parseJoin(tok,joinType,model));
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    model.setWhereClause(expr());
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    expectTok("String_Node_Str");
    model.setSampleBy(expectLiteral());
    tok=lexer.optionTok();
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    expectTok("String_Node_Str");
    do {
      tok=tok();
      if (Chars.equals(tok,')')) {
        throw err("String_Node_Str");
      }
      lexer.unparse();
      ExprNode n=expectLiteral();
      tok=lexer.optionTok();
      if (tok != null && Chars.equalsIgnoreCase(tok,"String_Node_Str")) {
        model.addOrderBy(n,QueryModel.ORDER_DIRECTION_DESCENDING);
        tok=lexer.optionTok();
      }
 else {
        model.addOrderBy(n,QueryModel.ORDER_DIRECTION_ASCENDING);
        if (tok != null && Chars.equalsIgnoreCase(tok,"String_Node_Str")) {
          tok=lexer.optionTok();
        }
      }
      if (model.getOrderBy().size() >= MAX_ORDER_BY_COLUMNS) {
        throw err("String_Node_Str");
      }
    }
 while (tok != null && Chars.equals(tok,','));
  }
  if (tok != null && Chars.equals(tok,"String_Node_Str")) {
    ExprNode lo=expr();
    ExprNode hi=null;
    tok=lexer.optionTok();
    if (tok != null && Chars.equals(tok,',')) {
      hi=expr();
      tok=lexer.optionTok();
    }
    model.setLimit(lo,hi);
  }
  if (subQuery) {
    lexer.unparse();
  }
 else   if (tok != null) {
    throw ParserException.position(lexer.position()).put("String_Node_Str").put(tok);
  }
  resolveJoinColumns(model);
  return model;
}