apache/kafka · error · ConfigException

Expected value to be either true or false

Error message

Expected value to be either true or false

What it means

Thrown by ConfigDef.parseType in the BOOLEAN branch when the supplied value is a String but, after trimming, is not equal (ignoring case) to "true" or "false". Boolean configs only accept the two literal strings or a java.lang.Boolean; any other string content fails parsing before any custom Validator runs.

Source

Thrown at clients/src/main/java/org/apache/kafka/common/config/ConfigDef.java:719

     * @return The parsed object
     */
    public static Object parseType(String name, Object value, Type type) {
        try {
            if (value == null) return null;

            String trimmed = null;
            if (value instanceof String)
                trimmed = ((String) value).trim();

            switch (type) {
                case BOOLEAN:
                    if (value instanceof String) {
                        if (trimmed.equalsIgnoreCase("true"))
                            return true;
                        else if (trimmed.equalsIgnoreCase("false"))
                            return false;
                        else
                            throw new ConfigException(name, value, "Expected value to be either true or false");
                    } else if (value instanceof Boolean)
                        return value;
                    else
                        throw new ConfigException(name, value, "Expected value to be either true or false");
                case PASSWORD:
                    if (value instanceof Password)
                        return value;
                    else if (value instanceof String)
                        return new Password(trimmed);
                    else
                        throw new ConfigException(name, value, "Expected value to be a string, but it was a " + value.getClass().getName());
                case STRING:
                    if (value instanceof String)
                        return trimmed;
                    else
                        throw new ConfigException(name, value, "Expected value to be a string, but it was a " + value.getClass().getName());
                case INT:
                    if (value instanceof Integer) {

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Set the property to the literal string true or false (case-insensitive), e.g. enable.auto.commit=false.
  2. If the value originates from an env var or template that emits 0/1, yes/no, or on/off, normalize it to true/false before passing the properties to the Kafka client.
  3. Strip surrounding quotes and whitespace introduced by shell or YAML parsing.
  4. For configs driven by users, document the accepted literals in your property file comments to prevent recurrence.

Example fix

// before
enable.auto.commit=yes

// after
enable.auto.commit=false
Defensive patterns

Strategy: validation

Validate before calling

// A BOOLEAN config value that arrived as a String but isn't 'true'/'false'. Normalize at the boundary.
static String normalizeBooleanString(String name, String raw) {
    if (raw == null) {
        throw new IllegalArgumentException("Config '" + name + "' (boolean) is null.");
    }
    String t = raw.trim();
    if (t.equalsIgnoreCase("true"))  return "true";
    if (t.equalsIgnoreCase("false")) return "false";
    throw new IllegalArgumentException(
        "Config '" + name + "' must be \"true\" or \"false\" (case-insensitive), got: " + raw);
}
// Apply before putting the value into props:
props.setProperty("enable.idempotence", normalizeBooleanString("enable.idempotence", rawValue));

Type guard

static boolean isParsableBoolean(Object v) {
    if (v instanceof Boolean) return true;
    if (v instanceof String) {
        String t = ((String) v).trim();
        return t.equalsIgnoreCase("true") || t.equalsIgnoreCase("false");
    }
    return false;
}

Prevention

When it happens

Trigger: Passing a string such as "yes", "1", "on", "True " (extra whitespace is handled, but typos are not), "enable", or an empty string to a Type.BOOLEAN config key; reading the value from an env var or YAML/properties file that uses non-canonical truthiness.

Common situations: Operator sets enable.auto.commit=yes or auto.offset.reset=true! in a properties file; Helm/Ansible template renders a numeric 1 or the literal 'on' into a boolean field; env var reads 0/1 and is passed unconverted; copy-paste from a tutorial that used a different dialect.

Related errors


AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03). Data as JSON: /data/errors/a9a5e3bf2384d7a9.json. Report an issue: GitHub.