apache/kafka · error · IllegalArgumentException

Null argument not allowed.

Error message

Null argument not allowed.

What it means

Thrown by RaftVoterEndpoint's internal validator requireNonNullAllCapsNonEmpty when an input string (the listener name) is null. RaftVoterEndpoint describes a single voter's network endpoint for KRaft quorum operations (add/remove voter). The listener name must match a configured broker listener name, which by Kafka convention are uppercase identifiers like CONTROLLER.

Source

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

import org.apache.kafka.common.annotation.InterfaceAudience;
import org.apache.kafka.common.annotation.InterfaceStability;

import java.util.Locale;
import java.util.Objects;

/**
 * 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.

View on GitHub (pinned to 996fb4585a)

Solutions

  1. Supply a non-null listener name matching a configured listener (e.g. "CONTROLLER").
  2. If sourcing from config, default to the controller listener name explicitly: `props.getProperty("listener", "CONTROLLER")`.
  3. Add a null check upstream of the constructor call.

Example fix

// before
new RaftVoterEndpoint(listenerName, host, port);

// after
String name = Objects.requireNonNull(listenerName, "listener name");
new RaftVoterEndpoint(name, host, port);
Defensive patterns

Strategy: validation

Validate before calling

String name = Objects.requireNonNull(listenerName, "listener name must not be null");
new RaftVoterEndpoint(name, host, port);

Type guard

static String requireListener(String s) {
    if (s == null) throw new IllegalArgumentException("listener is null");
    return s;
}

Try / catch

try {
    endpoint = new RaftVoterEndpoint(listener, host, port);
} catch (IllegalArgumentException e) {
    throw new ConfigurationException("Invalid raft voter endpoint: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Constructing `new RaftVoterEndpoint(null, host, port)` or passing null as the listener argument to addVoter/removeVoter RPC building paths.

Common situations: Loading voter configuration from a property file where the listener key is absent; passing a value derived from a missing Optional without fallback; programmatic voter management where the listener name is computed but unset.

Related errors


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