{"record":{"id":"2c7b6c0f1416db3c","repo":"oracle/graal","slug":"unknown-encoding-s-supported-encodings-are-ut","errorCode":null,"errorMessage":"unknown encoding '%s'. Supported encodings are: UTF-8,UTF-16,UTF-16-RAW,UTF-32,BYTES,LATIN-1","messagePattern":"unknown encoding '(.+?)'\\. Supported encodings are: UTF-8,UTF-16,UTF-16-RAW,UTF-32,BYTES,LATIN-1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/RegexOptions.java","lineNumber":241,"sourceCode":"        RegexFlavor get() {\n            return FLAVOR_CACHE[ordinal()];\n        }\n    }\n\n    private static RegexFlavor getDefaultFlavor() {\n        return FlavorOption.ECMAScript.get();\n    }\n\n    @Option(category = OptionCategory.USER, stability = OptionStability.STABLE, help = \"Regex flavor to use.\", usageSyntax = \"ECMAScript|JavaUtilPattern|OracleDB|Python|Ruby\") //\n    public static final OptionKey<FlavorOption> Flavor = new OptionKey<>(FlavorOption.ECMAScript);\n\n    public static final String ENCODING_NAME = \"Encoding\";\n\n    @Option(name = \"Encoding\", category = OptionCategory.USER, stability = OptionStability.STABLE, help = \"Input string encoding.\", usageSyntax = \"UTF-8|UTF-16|UTF-16-RAW|UTF-32|BYTES|LATIN-1\") //\n    public static final OptionKey<Encoding> EncodingOption = new OptionKey<>(Encoding.UTF_16_RAW, new OptionType<>(\"Encoding\", name -> {\n        Encoding enc = Encoding.getEncoding(name);\n        if (enc == null) {\n            throw new IllegalArgumentException(String.format(\"unknown encoding '%s'. Supported encodings are: UTF-8,UTF-16,UTF-16-RAW,UTF-32,BYTES,LATIN-1\", name));\n        }\n        return enc;\n    }));\n\n    public static final String PYTHON_METHOD_NAME = \"PythonMethod\";\n    public static final String MATCHING_MODE_NAME = \"MatchingMode\";\n    public static final String MATCHING_MODE_SEARCH = \"search\";\n    public static final String MATCHING_MODE_MATCH = \"match\";\n    public static final String MATCHING_MODE_FULLMATCH = \"fullmatch\";\n    private static final String[] MATCHING_MODE_OPTIONS = {MATCHING_MODE_SEARCH, MATCHING_MODE_MATCH, MATCHING_MODE_FULLMATCH};\n\n    @Option(category = OptionCategory.USER, stability = OptionStability.STABLE, help = \"Regex matching mode. Supported modes are: \" +\n                    \"'search': Default. Search for a match anywhere in the input string. \" +\n                    \"'match': Anchor match at starting index. \" +\n                    \"'fullmatch': Anchor match at starting and end index.\", usageSyntax = \"search|match|fullmatch\") //\n    public static final OptionKey<MatchingMode> MatchingMode = new OptionKey<>(com.oracle.truffle.regex.tregex.parser.MatchingMode.search);\n\n    public static final String PYTHON_LOCALE_NAME = \"PythonLocale\";","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/oracle/graal/blob/a66e9ccd1d7bf2552883939aa0788dfd0e294aab/regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/RegexOptions.java#L223-L259","documentation":"The TRegex 'Encoding' option (RegexOptions.EncodingOption) accepts only UTF-8, UTF-16, UTF-16-RAW, UTF-32, BYTES, LATIN-1. Its OptionType converter calls Encoding.getEncoding(name) and throws IllegalArgumentException for any other string.","triggerScenarios":"Setting the polyglot/regex option 'regex.Encoding' to an unsupported value, e.g. 'UTF8', 'utf-16le', 'ascii', or 'UTF_16_RAW' (wrong separator/case/spelling not recognized by the lookup).","commonSituations":"Config files migrated from other engines whose encoding names differ (e.g. ICU/ICU4J or Python codecs names); typos or hyphen/underscore confusion; new scripts passing options via Context.newBuilder().option(\"regex.Encoding\", ...).","solutions":["Use one of the exact supported spellings: UTF-8, UTF-16, UTF-16-RAW, UTF-32, BYTES, LATIN-1.","If the value comes from user config, validate it against the supported list before starting the Context and fail with a helpful message.","Map friendly aliases (e.g. 'utf8' -> 'UTF-8') in your own config layer before forwarding to the engine."],"exampleFix":"// before\nContext ctx = Context.newBuilder().option(\"regex.Encoding\", \"UTF8\").build(); // throws\n\n// after\nContext ctx = Context.newBuilder().option(\"regex.Encoding\", \"UTF-8\").build();","handlingStrategy":"validation","validationCode":"import java.util.Set;\nprivate static final Set<String> TREGEX_ENCODINGS = Set.of(\"UTF-8\", \"UTF-16\", \"UTF-16-RAW\", \"UTF-32\", \"BYTES\", \"LATIN-1\");\n\nstatic String checkEncoding(String name) {\n    if (!TREGEX_ENCODINGS.contains(name)) {\n        throw new IllegalArgumentException(\"regex.Encoding must be one of \" + TREGEX_ENCODINGS + \", got: \" + name);\n    }\n    return name;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate user-supplied engine options before building the polyglot Context.","Keep an alias map (utf8->UTF-8, utf_16_raw->UTF-16-RAW) in your config layer.","Pin encoding names in config as constants instead of free-form strings."],"tags":["regex","truffle","graalvm","configuration","encoding","options"],"backgroundTag":null,"analyzedSha":"a66e9ccd1d7bf2552883939aa0788dfd0e294aab","analyzedAt":"2026-08-14T13:58:47.161Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}