{"record":{"id":"d8f281315217d7f9","repo":"prestodb/presto","slug":"type-calculation-is-too-large-stack-overflow-whil","errorCode":null,"errorMessage":"Type calculation is too large (stack overflow while parsing)","messagePattern":"Type calculation is too large \\(stack overflow while parsing\\)","errorType":"exception","errorClass":"ParsingException","httpStatus":null,"severity":"error","filePath":"presto-parser/src/main/java/com/facebook/presto/type/TypeCalculation.java","lineNumber":71,"sourceCode":"        {\n            throw new ParsingException(message, e, line, charPositionInLine);\n        }\n    };\n\n    private TypeCalculation() {}\n\n    public static Long calculateLiteralValue(\n            String calculation,\n            Map<String, Long> inputs)\n    {\n        try {\n            ParserRuleContext tree = parseTypeCalculation(calculation);\n            CalculateTypeVisitor visitor = new CalculateTypeVisitor(inputs);\n            BigInteger result = visitor.visit(tree);\n            return result.longValueExact();\n        }\n        catch (StackOverflowError e) {\n            throw new ParsingException(\"Type calculation is too large (stack overflow while parsing)\");\n        }\n    }\n\n    private static ParserRuleContext parseTypeCalculation(String calculation)\n    {\n        TypeCalculationLexer lexer = new TypeCalculationLexer(new CaseInsensitiveStream(new ANTLRInputStream(calculation)));\n        CommonTokenStream tokenStream = new CommonTokenStream(lexer);\n        TypeCalculationParser parser = new TypeCalculationParser(tokenStream);\n\n        lexer.removeErrorListeners();\n        lexer.addErrorListener(ERROR_LISTENER);\n\n        parser.removeErrorListeners();\n        parser.addErrorListener(ERROR_LISTENER);\n\n        ParserRuleContext tree;\n        try {\n            // first, try parsing with potentially faster SLL mode","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-parser/src/main/java/com/facebook/presto/type/TypeCalculation.java#L53-L89","documentation":"Catch of StackOverflowError in calculateLiteralValue: the recursive type-calculation grammar parser blew the call stack while parsing the calculation expression (typically a pathologically long or deeply nested expression). It is rethrown as a ParsingException telling the user the type calculation is too large.","triggerScenarios":"Thrown at presto-parser/src/main/java/com/facebook/presto/type/TypeCalculation.java:71 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Simplify or shorten the type calculation expression in the type signature","Reduce nesting/number of operators in the calculated type definition"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}