Program: 25390
Project: 25390
Buggy source:
private void findCubePositions(ASTNode ast,List<CubeQueryInfo> cubeQueries,int queryEndPos) throws SemanticException {
  int child_count=ast.getChildCount();
  if (ast.getToken() != null) {
    if (ast.getToken().getType() == HiveParser.TOK_QUERY && ((ASTNode)ast.getChild(0)).getToken().getType() == HiveParser.KW_CUBE) {
      CubeQueryInfo cqi=new CubeQueryInfo();
      cqi.cubeAST=ast;
      if (ast.getParent() != null) {
        ASTNode parent=(ASTNode)ast.getParent();
        cqi.startPos=ast.getCharPositionInLine();
        int ci=ast.getChildIndex();
        if (parent.getToken() == null || parent.getToken().getType() == HiveParser.TOK_EXPLAIN) {
          cqi.endPos=queryEndPos;
        }
 else         if (parent.getChildCount() > ci + 1) {
          if (parent.getToken().getType() == HiveParser.TOK_SUBQUERY) {
            cqi.endPos=parent.getChild(ci + 1).getCharPositionInLine() - 2;
          }
 else           if (parent.getToken().getType() == HiveParser.TOK_UNION) {
            cqi.endPos=parent.getChild(ci + 1).getCharPositionInLine() - 11;
          }
 else {
            LOG.warn("String_Node_Str" + ast.dump());
            throw new SemanticException("String_Node_Str");
          }
        }
 else {
          cqi.endPos=parent.getParent().getChild(1).getCharPositionInLine() - 2;
        }
      }
      cubeQueries.add(cqi);
    }
 else {
      for (int child_pos=0; child_pos < child_count; ++child_pos) {
        findCubePositions((ASTNode)ast.getChild(child_pos),cubeQueries,queryEndPos);
      }
    }
  }
}

Fixed version (ground truth):
private void findCubePositions(ASTNode ast,List<CubeQueryInfo> cubeQueries,String originalQuery) throws SemanticException {
  int child_count=ast.getChildCount();
  if (ast.getToken() != null) {
    if (ast.getToken().getType() == HiveParser.TOK_QUERY && ((ASTNode)ast.getChild(0)).getToken().getType() == HiveParser.KW_CUBE) {
      CubeQueryInfo cqi=new CubeQueryInfo();
      cqi.cubeAST=ast;
      if (ast.getParent() != null) {
        ASTNode parent=(ASTNode)ast.getParent();
        cqi.startPos=ast.getCharPositionInLine();
        int ci=ast.getChildIndex();
        if (parent.getToken() == null || parent.getToken().getType() == HiveParser.TOK_EXPLAIN) {
          cqi.endPos=originalQuery.length();
        }
 else         if (parent.getChildCount() > ci + 1) {
          if (parent.getToken().getType() == HiveParser.TOK_SUBQUERY) {
            cqi.endPos=getEndPos(originalQuery,getEndPos(originalQuery,parent.getChild(ci + 1).getCharPositionInLine()),"String_Node_Str");
            ;
          }
 else           if (parent.getToken().getType() == HiveParser.TOK_UNION) {
            cqi.endPos=getEndPos(originalQuery,parent.getChild(ci + 1).getCharPositionInLine() - 1,"String_Node_Str");
          }
 else {
            LOG.warn("String_Node_Str" + ast.dump());
            throw new SemanticException("String_Node_Str");
          }
        }
 else {
          cqi.endPos=getEndPos(originalQuery,getEndPos(originalQuery,parent.getParent().getChild(1).getCharPositionInLine()),"String_Node_Str","String_Node_Str");
        }
      }
      cubeQueries.add(cqi);
    }
 else {
      for (int child_pos=0; child_pos < child_count; ++child_pos) {
        findCubePositions((ASTNode)ast.getChild(child_pos),cubeQueries,originalQuery);
      }
    }
  }
}