apache/kafka · error · IllegalArgumentException

Empty string is not allowed.

Error message

Empty string is not allowed.

What it means

Thrown by RaftVoterEndpoint.requireNonNullAllCapsNonEmpty when the listener string is the empty string "". An empty listener name cannot correspond to any endpoint, so the constructor rejects it. Note this check runs after the whitespace check, so a value of just spaces will trip the whitespace branch first.

Source

Thrown at clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java:43

/**
 * An endpoint for a raft quorum voter.
 */
@InterfaceStability.Stable
@InterfaceAudience.Public
public class RaftVoterEndpoint {
    private final String listener;
    private final String host;
    private final int port;

    private static String requireNonNullAllCapsNonEmpty(String input) {
        if (input == null) {
            throw new IllegalArgumentException("Null argument not allowed.");
        }
        if (!input.trim().equals(input)) {
            throw new IllegalArgumentException("Leading or trailing whitespace is not allowed.");
        }
        if (input.isEmpty()) {
            throw new IllegalArgumentException("Empty string is not allowed.");
        }
        if (!input.toUpperCase(Locale.ROOT).equals(input)) {
            throw new IllegalArgumentException("String must be UPPERCASE.");
        }
        return input;
    }

    /**
     * Create an endpoint for a metadata quorum voter.
     *
     * @param listener          The human-readable name for this endpoint. For example, CONTROLLER.
     * @param host              The DNS hostname for this endpoint.
     * @param port              The network port for this endpoint.
     */
    public RaftVoterEndpoint(
        String listener,
        String host,
        int port

View on GitHub (pinned to 996fb4585a)

Solutions

  1. Provide a real listener name such as "CONTROLLER".
  2. When loading config, treat empty as missing and fall back to a sensible default.
  3. Validate non-empty before constructing: `if (listener == null || listener.isEmpty()) throw ...`.

Example fix

// before
String listener = props.getProperty("listener", "");
new RaftVoterEndpoint(listener, host, port);

// after
String listener = props.getProperty("listener", "CONTROLLER");
new RaftVoterEndpoint(listener, host, port);
Defensive patterns

Strategy: validation

Validate before calling

if (listener == null || listener.isEmpty()) {
    throw new IllegalArgumentException("listener name required");
}
new RaftVoterEndpoint(listener, host, port);

Type guard

static String requireNonEmptyListener(String s) {
    if (s == null || s.isEmpty()) throw new IllegalArgumentException("listener empty");
    return s;
}

Try / catch

try {
    new RaftVoterEndpoint(listener, host, port);
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("Voter config invalid: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Constructing `new RaftVoterEndpoint("", host, port)`; reading a listener name from a config key that exists but has an empty value.

Common situations: Properties file with `listener.name=` (no value); JSON config with "listener": ""; defaulting a missing key to empty string instead of a real default.

Related errors


AI-assisted analysis of apache/kafka@996fb4585a (2026-08-11). Data as JSON: /api/errors/41525ddee3c6a6ed. Report an issue: GitHub.