{"record":{"id":"bac0bcfc435d376d","repo":"oracle/graal","slug":"too-many-transitions","errorCode":null,"errorMessage":"too many transitions","messagePattern":"too many transitions","errorType":"exception","errorClass":"UnsupportedRegexException","httpStatus":null,"severity":"error","filePath":"regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/nodes/dfa/TRegexDFAExecutorNode.java","lineNumber":240,"sourceCode":"    }\n\n    @Override\n    public int getNumberOfStates() {\n        return states.length;\n    }\n\n    private static int calcNumberOfTransitions(RegexSource source, DFAAbstractNode[] states) {\n        int sum = 0;\n        for (DFAAbstractNode state : states) {\n            if (state instanceof DFAAbstractStateNode s) {\n                sum += s.getSuccessors().length;\n            }\n            if (state instanceof DFAStateNode dfaState && !dfaState.treeTransitionMatching() && dfaState.getSequentialMatchers().getNoMatchSuccessor() >= 0) {\n                sum++;\n            }\n        }\n        if (sum > source.getOptions().getMaxDFASize()) {\n            throw new UnsupportedRegexException(\"too many transitions\");\n        }\n        return sum;\n    }\n\n    public CounterTracker[] getCounterTrackers() {\n        return counterTrackers;\n    }\n\n    public boolean recordExecution() {\n        return debugRecorder != null;\n    }\n\n    public TRegexDFAExecutorDebugRecorder getDebugRecorder() {\n        return debugRecorder;\n    }\n\n    TruffleString.ByteIndexOfCodePointSetNode getIndexOfNode(int index) {\n        if (indexOfNodes == null) {","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/nodes/dfa/TRegexDFAExecutorNode.java#L222-L258","documentation":"Thrown by TRegexDFAExecutorNode.calcNumberOfTransitions when the sum of successor edges over all DFA states (plus no-match successors of sequential matchers) exceeds source.getOptions().getMaxDFASize(). This caps the size of the compiled DFA so code generation stays bounded.","triggerScenarios":"Compiling a regex to a DFA whose total transition count grows beyond the configured MaxDFASize — typically patterns with many distinct character classes or long alternations of literals, where the deterministic automaton blows up.","commonSituations":"Large generated alternations (dictionaries, token lists); wide Unicode case-insensitive classes; the guest language raising or lowering the DFA size option; a regex that is fine on one GraalVM version but exceeds a changed default on another.","solutions":["Simplify the pattern: replace long literal alternations with a common-prefix factoring or a trie-like structure, or use a character class where possible.","Split the regex into several smaller ones and merge results in code.","Rely on automatic fallback to the backtracking NFA engine (UnsupportedRegexException is caught in TRegexCompiler.java:79) instead of forcing DFA compilation.","If you control RegexOptions, review getMaxDFASize() before raising it — the cost is compiled-code size."],"exampleFix":"// before\nString pattern = \"cat|car|can|cap|cad|...\"; // hundreds of literal alternatives\n\n// after\nString pattern = \"ca[t rnpd]\"; // or split into groups sharing prefixes: \"ca(?:t|r|n|p|d)|...\"","handlingStrategy":"fallback","validationCode":"int branches = pattern.split(\"\\\\|\", -1).length - 1; if (branches > 500) throw new IllegalArgumentException(\"alternation too wide; DFA transition limit risk\");","typeGuard":"null","tryCatchPattern":"try { compileDfa(pattern); } catch (UnsupportedRegexException e) { compileBacktracking(pattern); } // mirrors TRegexCompiler.java:79","preventionTips":["Factor long literal alternations by common prefix.","Split very wide alternations into several patterns.","Leave the DFA size option at its default; raising it trades compile time and code size."],"tags":["regex","tregex","dfa","limit-exceeded","compilation"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}