{"record":{"id":"33394decc7fbe9da","repo":"oracle/graal","slug":"too-many-terms-in-a-single-sequence","errorCode":null,"errorMessage":"too many terms in a single sequence","messagePattern":"too many terms in a single sequence","errorType":"exception","errorClass":"UnsupportedRegexException","httpStatus":null,"severity":"error","filePath":"regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/parser/ast/Term.java","lineNumber":80,"sourceCode":"\n    Term(Term copy) {\n        super(copy);\n    }\n\n    @Override\n    public abstract Term copy(RegexAST ast);\n\n    @Override\n    public abstract Term copyRecursive(RegexAST ast, CompilationBuffer compilationBuffer);\n\n    public int getSeqIndex() {\n        return seqIndex;\n    }\n\n    public void setSeqIndex(int seqIndex) {\n        this.seqIndex = seqIndex;\n        if (seqIndex >= TRegexOptions.TRegexParserTreeMaxNumberOfTermsInSequence) {\n            throw new UnsupportedRegexException(\"too many terms in a single sequence\");\n        }\n    }\n\n    @Override\n    public RegexASTSubtreeRootNode getSubTreeParent() {\n        RegexASTNode current = this;\n        while (current.getParent() != null) {\n            assert current instanceof Term;\n            if (current.getParent() instanceof RegexASTSubtreeRootNode) {\n                return (RegexASTSubtreeRootNode) current.getParent();\n            }\n            // structure is always Group -> Sequence -> Term\n            current = current.getParent().getParent();\n        }\n        // this should only be reached by nodes generated by RegexAST#createNFAInitialStates()!\n        return null;\n    }\n","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/parser/ast/Term.java#L62-L98","documentation":"Thrown by Term.setSeqIndex when a sequence's term index reaches TRegexOptions.TRegexParserTreeMaxNumberOfTermsInSequence (Short.MAX_VALUE = 32767). Sequence positions are stored in a short, so a single regex sequence with 32768+ terms cannot be represented and parsing is rejected.","triggerScenarios":"Compiling one flat sequence with more than 32767 consecutive terms, e.g. a very long literal string (every character is a term) or a generated concatenation without alternation.","commonSituations":"Embedding a large literal (a whole token, hash list, or text blob) into a pattern; patterns generated from data that concatenate thousands of quoted literals; regexes built by string concatenation in a loop that grows unbounded over releases.","solutions":["Take the long literal out of the regex and compare with String.contains/equals in application code.","Group repeated elements into quantifiers (a{5} instead of aaaaa) or character classes.","Split the pattern into several regexes and combine the results."],"exampleFix":"// before\nString pattern = \"^\" + hugeLiteral + \"$\"; // hugeLiteral > 32767 chars\n\n// after\nboolean m = input.equals(hugeLiteral); // plain string compare, no regex needed","handlingStrategy":"validation","validationCode":"if (pattern.length() > 32_000) throw new IllegalArgumentException(\"pattern too long: single sequence limited to 32767 terms\");","typeGuard":"null","tryCatchPattern":"try { compile(pattern); } catch (UnsupportedRegexException e) { if (e.getMessage().contains(\"too many terms\")) { /* shorten or split the pattern */ } }","preventionTips":["Do not embed huge literals in regexes; compare strings directly.","Use quantifiers/classes to compress repeated terms.","Cap generated pattern length."],"tags":["regex","tregex","parser","limit-exceeded","sequence"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}