{"record":{"id":"6f9dbfee64a14e23","repo":"oracle/graal","slug":"class-set-expression-maximum-nesting-level-exceede","errorCode":null,"errorMessage":"Class set expression maximum nesting level exceeded","messagePattern":"Class set expression maximum nesting level exceeded","errorType":"exception","errorClass":"UnsupportedRegexException","httpStatus":null,"severity":"error","filePath":"regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/parser/RegexLexer.java","lineNumber":1255,"sourceCode":"        Difference(\"--\");\n\n        private final String repr;\n\n        ClassSetOperator(String repr) {\n            this.repr = repr;\n        }\n\n        @Override\n        public String toString() {\n            return repr;\n        }\n    }\n\n    protected ClassSetContents parseClassSetExpression() throws RegexSyntaxException {\n        classSetNesting++;\n        try {\n            if (classSetNesting > TRegexOptions.TRegexParserTreeMaxNestingLevel) {\n                throw new UnsupportedRegexException(\"Class set expression maximum nesting level exceeded\");\n            }\n            final boolean invert = consumingLookahead(\"^\");\n            ClassSetContentsAccumulator curClassSet = new ClassSetContentsAccumulator();\n            ClassSetOperator operator = null;\n            boolean firstOperandIsRange = false;\n            int startPos = position;\n            while (!atEnd()) {\n                RegexRootNode.checkThreadInterrupted();\n                if (curChar() == ']' && (!featureEnabledCharClassFirstBracketIsLiteral() || position != startPos)) {\n                    advance();\n                    if (invert && curClassSet.mayContainStrings()) {\n                        throw handleComplementOfStringSet();\n                    }\n                    if (invert) {\n                        assert !curClassSet.mayContainStrings() && curClassSet.isCodePointSetOnly();\n                        return ClassSetContents.createCharacterClass(complementClassSet(curClassSet.getCodePointSet()));\n                    } else {\n                        EconomicSet<String> stringsCopy = EconomicSet.create(curClassSet.getStrings().size());","sourceCodeStart":1237,"sourceCodeEnd":1273,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/tregex/parser/RegexLexer.java#L1237-L1273","documentation":"Thrown by RegexLexer.parseClassSetExpression when class-set expression nesting (nested [], [^...], &&, --, ~~ operators or nested class sets in V-mode/OracleDB flavor syntax) exceeds TRegexOptions.TRegexParserTreeMaxNestingLevel (128). The parser counts nesting depth on entry to guard its recursion.","triggerScenarios":"Compiling a character class with more than 128 levels of nested set expressions, e.g. repeated [[[[...]]]] or long chains of intersection/difference operators, in flavors that support class-set syntax (Java V-mode, OracleDB).","commonSituations":"Generated character classes from data classification; unbalanced input producing accidental deep nesting; users copy-pasting nested classes from PCRE-style documentation into a flavor that recursively nests them.","solutions":["Flatten the nested class: [[a[b[c]]]] is equivalent to [abc] in most flavors.","Move set operations (&&, --, ~~) out of deeply nested positions into one level.","If the class is generated, add a nesting cap in the generator and simplify before compiling."],"exampleFix":"// before\nString pattern = \"[[[a][b][[c][d]]]]\"; // deep nesting\n\n// after\nString pattern = \"[abcd]\"; // flattened","handlingStrategy":"validation","validationCode":"int depth = 0, max = 0; for (char c : pattern.toCharArray()) { if (c == '[') { depth++; max = Math.max(max, depth); } else if (c == ']') depth--; } if (max > 100) throw new IllegalArgumentException(\"class-set nesting too deep (max 128)\");","typeGuard":"null","tryCatchPattern":"try { compile(pattern); } catch (UnsupportedRegexException e) { if (e.getMessage().contains(\"nesting\")) { /* flatten nested character classes */ } }","preventionTips":["Flatten nested character classes — [[a][b]] equals [ab].","Keep class-set operators (&&, --, ~~) at one level.","Cap nesting in generated classes."],"tags":["regex","tregex","character-class","parser","limit-exceeded"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}