apache/kafka · error · ConfigException

String must be non-empty

Error message

String must be non-empty

What it means

Thrown by NonEmptyString.ensureValid when the value is non-null but isEmpty(). Notably this validator allows null (it only checks `s != null && s.isEmpty()`), so it is used for configs that are optional but, when present, must be non-empty. Distinct from NonEmptyStringWithoutControlChars in that it does not check for ISO control characters.

Source

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

            if (validators == null) return "";
            StringBuilder desc = new StringBuilder();
            for (Validator v: validators) {
                if (desc.length() > 0) {
                    desc.append(',').append(' ');
                }
                desc.append(v);
            }
            return desc.toString();
        }
    }

    public static class NonEmptyString implements Validator {

        @Override
        public void ensureValid(String name, Object o) {
            String s = (String) o;
            if (s != null && s.isEmpty()) {
                throw new ConfigException(name, o, "String must be non-empty");
            }
        }

        @Override
        public String toString() {
            return "non-empty string";
        }
    }

    public static class NonEmptyStringWithoutControlChars implements Validator {

        public static NonEmptyStringWithoutControlChars nonEmptyStringWithoutControlChars() {
            return new NonEmptyStringWithoutControlChars();
        }

        @Override
        public void ensureValid(String name, Object value) {
            String s = (String) value;

View on GitHub (pinned to c31c9215e1)

Solutions

  1. Either remove the key entirely (null is accepted by this validator) or set it to a non-empty value.
  2. Fix properties-file lines that end with '=' and no value; comment them out (#) if unused.
  3. Guard env-var substitution to skip the key when the variable is unset rather than emitting an empty string.

Example fix

// before
props.put("client.id", "");

// after
// option A: omit the key
// option B: provide a real value
props.put("client.id", "order-service-producer");
Defensive patterns

Strategy: validation

Validate before calling

// NonEmptyString allows null (used when default is absent) but rejects empty strings:
for (Map.Entry<String, ?> e : props.entrySet()) {
    Object v = e.getValue();
    if (v instanceof String && ((String) v).isEmpty()) {
        throw new IllegalArgumentException(e.getKey() + " must be non-empty");
    }
}

Type guard

// Represent as Optional<String> in your own config model; convert to Properties only when present:
Optional<String> clientId = Optional.ofNullable(load("client.id"));
clientId.ifPresent(v -> props.put("client.id", v));

Try / catch

try {
    def.parse(props);
} catch (ConfigException ce) {
    if (ce.getMessage().equals("String must be non-empty")) {
        props.remove(ce.getName()); // treat empty as 'unset' if appropriate
    } else throw ce;
}

Prevention

When it happens

Trigger: A ConfigKey validated with NonEmptyString (registered via .validator(new NonEmptyString())) is supplied the empty string "" in the properties Map. Triggered during ConfigDef.parse() when ensureValid runs.

Common situations: Optional string configs (e.g. client.id, sasl/mechanism strings in some modules, or component-specific identifiers) where the user wrote "key=" with nothing after the equals sign in a properties file, or env-var substitution produced an empty string.

Related errors


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