{"record":{"id":"d2b2a14817224256","repo":"oracle/graal","slug":"literal-parsing-is-not-supported","errorCode":null,"errorMessage":"Literal parsing is not supported","messagePattern":"Literal parsing is not supported","errorType":"exception","errorClass":"UnsupportedRegexException","httpStatus":null,"severity":"error","filePath":"regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/flavor/java/JavaRegexLexer.java","lineNumber":155,"sourceCode":"        }\n    }\n\n    private static final TBitSet WHITESPACE = TBitSet.valueOf('\\t', '\\n', '\\f', '\\r', ' ');\n    private static final TBitSet PREDEFINED_CHAR_CLASSES = TBitSet.valueOf('D', 'H', 'S', 'V', 'W', 'd', 'h', 's', 'v', 'w');\n    private static final TBitSet LATIN1_CHARS_THAT_CASE_FOLD_TO_NON_LATIN1_CHARS = TBitSet.valueOf(0x49, 0x4b, 0x53, 0x69, 0x6b, 0x73, 0xb5, 0xc5, 0xe5, 0xff);\n\n    final JavaUnicodeProperties unicode;\n    private final Deque<JavaFlags> flagsStack = new ArrayDeque<>();\n    private JavaFlags currentFlags;\n    private final CodePointSetAccumulator curCharClass = new CodePointSetAccumulator();\n\n    public JavaRegexLexer(RegexSource source, JavaFlags flags, CompilationBuffer compilationBuffer) {\n        super(source, compilationBuffer);\n        if (flags.isCanonEq()) {\n            throw new UnsupportedRegexException(\"Canonical equivalence is not supported\");\n        }\n        if (flags.isLiteral()) {\n            throw new UnsupportedRegexException(\"Literal parsing is not supported\");\n        }\n        this.unicode = JavaUnicodeProperties.create(source.getOptions());\n        this.currentFlags = flags;\n    }\n\n    @Override\n    protected boolean isPredefCharClass(char c) {\n        return PREDEFINED_CHAR_CLASSES.get(c);\n    }\n\n    JavaFlags getLocalFlags() {\n        return currentFlags;\n    }\n\n    public void pushLocalFlags() {\n        flagsStack.push(currentFlags);\n    }\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/flavor/java/JavaRegexLexer.java#L137-L173","documentation":"JavaRegexLexer rejects Pattern.LITERAL at construction with UnsupportedRegexException: literal (non-meta) parsing mode is not implemented by the TRegex Java-flavor frontend, even though java.util.regex supports treating the whole pattern as a literal string.","triggerScenarios":"Pattern.compile(userInput, Pattern.LITERAL) executed on Espresso/TRegex, or any library that uses LITERAL to safely match arbitrary user-provided strings containing regex metacharacters.","commonSituations":"Search/replace features that take raw user text as a pattern; security-conscious code that deliberately avoids pattern injection by using LITERAL; log-grepping tools running on GraalVM.","solutions":["Quote the pattern manually instead of using the flag: Pattern.compile(Pattern.quote(userInput)) without LITERAL.","For simple substring search, skip regex entirely and use String.contains/String.indexOf or TruffleString operations.","Update libraries that unconditionally pass LITERAL, or run them on a context where the host engine handles the compile."],"exampleFix":"// before\nPattern p = Pattern.compile(userInput, Pattern.LITERAL); // throws on TRegex\n\n// after\nPattern p = Pattern.compile(Pattern.quote(userInput)); // equivalent literal semantics","handlingStrategy":"fallback","validationCode":"if ((flags & Pattern.LITERAL) != 0) {\n    pattern = Pattern.quote(pattern);\n    flags &= ~Pattern.LITERAL;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return Pattern.compile(pattern, flags);\n} catch (com.oracle.truffle.regex.UnsupportedRegexException e) {\n    if ((flags & Pattern.LITERAL) != 0) {\n        return Pattern.compile(Pattern.quote(pattern), flags & ~Pattern.LITERAL);\n    }\n    throw e;\n}","preventionTips":["Use Pattern.quote(...) instead of the LITERAL flag — portable across engines.","For plain substring search, prefer indexOf/contains over regex entirely.","Upgrade or patch libraries that hard-code Pattern.LITERAL."],"tags":["regex","truffle","espresso","java-util-pattern","literal","unsupported-flag"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}