quarkusio/quarkus · error · IllegalArgumentException

Unable to create Charset from: '${trimmedCharset}'

Error message

Unable to create Charset from: '${trimmedCharset}'

What it means

CharsetConverter.convert() turns a config string into a java.nio.charset.Charset. When Charset.forName(trimmedCharset) fails (unknown or unsupported charset name), it wraps the exception in IllegalArgumentException("Unable to create Charset from: '<value>'").

Source

Thrown at core/runtime/src/main/java/io/quarkus/runtime/configuration/CharsetConverter.java:35

    private static final long serialVersionUID = 2320905063828247874L;

    @Override
    public Charset convert(String value) {
        if (value == null) {
            return null;
        }

        String trimmedCharset = value.trim();

        if (trimmedCharset.isEmpty()) {
            return null;
        }

        try {
            return Charset.forName(trimmedCharset);
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to create Charset from: '" + trimmedCharset + "'", e);
        }
    }
}

View on GitHub (pinned to e1c734241f)

Solutions

  1. Use a canonical charset name: 'UTF-8', 'ISO-8859-1', 'US-ASCII', etc.
  2. Run Charset.isSupported(name) or Charset.forName in a scratch program to validate the name on your JDK.
  3. Check for typos and stray characters (BOM, quotes) in the property value.
  4. If nullable, leave the property unset rather than supplying a bad value.

Example fix

// before
quarkus.http.body.charset=utf8
// after
quarkus.http.body.charset=UTF-8
Defensive patterns

Strategy: validation

Validate before calling

boolean isValidCharset(String s) {
    if (s == null) return false;
    String t = s.trim();
    return !t.isEmpty() && java.nio.charset.Charset.isSupported(t);
}

Type guard

java.nio.charset.Charset tryParseCharset(String s) {
    try { return (s == null || s.isBlank()) ? null : java.nio.charset.Charset.forName(s.trim()); }
    catch (Exception e) { return null; }
}

Try / catch

try {
    // consume the converted charset
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Unable to create Charset from:")) {
        charset = StandardCharsets.UTF_8; // sane default
    } else { throw e; }
}

Prevention

When it happens

Trigger: Setting a quarkus property that maps to Charset (e.g. quarkus.http.* charset settings, file encoding configs) to an invalid name like 'utf8' vs 'UTF-8', a typo, or an empty/whitespace-only non-null value that passes trimming.

Common situations: Typo in application.properties (e.g. 'utf-8' works, 'utf8' may fail depending on JDK); charset supported on one JDK but not another; OS-specific default encoding names copied into config.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/1e31b20d4c59f393. Report an issue: GitHub.