{"record":{"id":"ebe087bd653c5dd6","repo":"apache/kafka","slug":"null-argument-not-allowed","errorCode":null,"errorMessage":"Null argument not allowed.","messagePattern":"Null argument not allowed\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java","lineNumber":37,"sourceCode":"import org.apache.kafka.common.annotation.InterfaceAudience;\nimport org.apache.kafka.common.annotation.InterfaceStability;\n\nimport java.util.Locale;\nimport java.util.Objects;\n\n/**\n * An endpoint for a raft quorum voter.\n */\n@InterfaceStability.Stable\n@InterfaceAudience.Public\npublic class RaftVoterEndpoint {\n    private final String listener;\n    private final String host;\n    private final int port;\n\n    private static String requireNonNullAllCapsNonEmpty(String input) {\n        if (input == null) {\n            throw new IllegalArgumentException(\"Null argument not allowed.\");\n        }\n        if (!input.trim().equals(input)) {\n            throw new IllegalArgumentException(\"Leading or trailing whitespace is not allowed.\");\n        }\n        if (input.isEmpty()) {\n            throw new IllegalArgumentException(\"Empty string is not allowed.\");\n        }\n        if (!input.toUpperCase(Locale.ROOT).equals(input)) {\n            throw new IllegalArgumentException(\"String must be UPPERCASE.\");\n        }\n        return input;\n    }\n\n    /**\n     * Create an endpoint for a metadata quorum voter.\n     *\n     * @param listener          The human-readable name for this endpoint. For example, CONTROLLER.\n     * @param host              The DNS hostname for this endpoint.","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java#L19-L55","documentation":"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.","triggerScenarios":"Constructing `new RaftVoterEndpoint(null, host, port)` or passing null as the listener argument to addVoter/removeVoter RPC building paths.","commonSituations":"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.","solutions":["Supply a non-null listener name matching a configured listener (e.g. \"CONTROLLER\").","If sourcing from config, default to the controller listener name explicitly: `props.getProperty(\"listener\", \"CONTROLLER\")`.","Add a null check upstream of the constructor call."],"exampleFix":"// before\nnew RaftVoterEndpoint(listenerName, host, port);\n\n// after\nString name = Objects.requireNonNull(listenerName, \"listener name\");\nnew RaftVoterEndpoint(name, host, port);","handlingStrategy":"validation","validationCode":"String name = Objects.requireNonNull(listenerName, \"listener name must not be null\");\nnew RaftVoterEndpoint(name, host, port);","typeGuard":"static String requireListener(String s) {\n    if (s == null) throw new IllegalArgumentException(\"listener is null\");\n    return s;\n}","tryCatchPattern":"try {\n    endpoint = new RaftVoterEndpoint(listener, host, port);\n} catch (IllegalArgumentException e) {\n    throw new ConfigurationException(\"Invalid raft voter endpoint: \" + e.getMessage(), e);\n}","preventionTips":["Source listener names only from broker config (which guarantees non-null) or validate at the config-loading boundary.","Keep a constant for the controller listener name rather than passing strings around.","Add an integration test that builds a RaftVoterEndpoint from your config loader."],"tags":["admin-client","kraft","raft-voter","validation","illegal-argument"],"backgroundTag":null,"analyzedSha":"996fb4585aa1bcc8980b0e1b8d6b168b986cd979","analyzedAt":"2026-08-11T22:03:28.655Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}