oracle/graal · error · IllegalArgumentException
unsupported locale: %s
Error message
unsupported locale: %s
What it means
Thrown by PythonLocaleData.getLocaleData when the encoding part of the locale string does not name a charset known to the JVM. After splitting on '.', Charset.forName(encoding) throws UnsupportedCharsetException or IllegalCharsetNameException, which the method converts into IllegalArgumentException('unsupported locale: ...').
Source
Thrown at regex/src/com.oracle.truffle.regex/src/com/oracle/truffle/regex/flavor/python/PythonLocaleData.java:93
private final CodePointSet wordChars;
private final CodePointSet nonWordChars;
private final byte[] caseFolding;
public static PythonLocaleData getLocaleData(String locale) {
if (locale.equals("C")) {
return createCachedLocaleData(false, Charset.forName("US-ASCII"));
} else {
int dot = locale.indexOf('.');
if (dot == -1) {
throw new IllegalArgumentException("malformed locale: " + locale);
}
String language = locale.substring(0, dot);
String encoding = locale.substring(dot + 1);
try {
return createCachedLocaleData(language.startsWith("tr_"), Charset.forName(encoding));
} catch (UnsupportedCharsetException | IllegalCharsetNameException e) {
throw new IllegalArgumentException("unsupported locale: " + locale);
}
}
}
public CodePointSet getWordCharacters() {
return wordChars;
}
public CodePointSet getNonWordCharacters() {
return nonWordChars;
}
public void caseFoldUnfold(CodePointSetAccumulator charClass, CodePointSetAccumulator copy) {
charClass.copyTo(copy);
int iFolding = 0;
for (Range r : copy) {
iFolding = caseFoldingBinarySearch(iFolding, r.lo);
while (iFolding < caseFoldingSize() && caseFoldingFrom(iFolding) >= r.lo && caseFoldingFrom(iFolding) <= r.hi) {View on GitHub (pinned to a66e9ccd1d)
Solutions
- Use a canonical, widely-supported encoding in the locale string, ideally '.UTF-8'
- Map environment encoding aliases to canonical Java charset names at the call site (e.g. 'cp1254' -> 'windows-1254', 'ANSI_X3.4-1968' -> 'US-ASCII')
- Fall back to 'C' when the encoding cannot be resolved and locale-specific behavior is optional
- If a legitimate charset is missing, run the JVM with full charset support (include jdk.charsets)
Example fix
// before
PythonLocaleData.getLocaleData("tr_TR.cp1254"); // unknown name
// after
PythonLocaleData.getLocaleData("tr_TR.windows-1254"); Defensive patterns
Strategy: validation
Validate before calling
boolean isSupportedLocale(String locale) {
if (locale.equals("C")) return true;
int dot = locale.indexOf('.');
if (dot <= 0) return false;
try {
java.nio.charset.Charset.forName(locale.substring(dot + 1));
return true;
} catch (java.nio.charset.UnsupportedCharsetException | java.nio.charset.IllegalCharsetNameException e) {
return false;
}
} Prevention
- Resolve the charset with Charset.forName yourself before requesting locale data, and map aliases to canonical names
- Default to 'C' or '.UTF-8' when the environment encoding is unknown to the JVM
When it happens
Trigger: Calling getLocaleData with a locale whose suffix after '.' is not a valid/installed charset, e.g. 'en_US.US-ASCII-TYPO', 'xx.BOGUS', 'tr_TR.905' (bare codes the JVM does not resolve), or an encoding not present in the JVM's charset providers.
Common situations: Guest Python code reading LC_ALL/LC_CTYPE from a Unix environment and forwarding values whose encoding aliases the JVM does not know (e.g. 'ANSI_X3.4-1968', 'cp1254', numeric codes); containers with unusual locale settings; JVMs where extended charset support (jdk.charsets) is not on the module path.
Related errors
- malformed locale: %s
- nargs not allowed
- illegal type for element %s: %s
- %s missing element %s
- Not an annotation type
AI-assisted analysis of oracle/graal@a66e9ccd1d (2026-08-14).
Data as JSON: /api/errors/95d66586bc7bfd5c.
Report an issue: GitHub.