{"record":{"id":"41525ddee3c6a6ed","repo":"apache/kafka","slug":"empty-string-is-not-allowed","errorCode":null,"errorMessage":"Empty string is not allowed.","messagePattern":"Empty string is not allowed\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java","lineNumber":43,"sourceCode":"/**\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.\n     * @param port              The network port for this endpoint.\n     */\n    public RaftVoterEndpoint(\n        String listener,\n        String host,\n        int port","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/apache/kafka/blob/996fb4585aa1bcc8980b0e1b8d6b168b986cd979/clients/src/main/java/org/apache/kafka/clients/admin/RaftVoterEndpoint.java#L25-L61","documentation":"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.","triggerScenarios":"Constructing `new RaftVoterEndpoint(\"\", host, port)`; reading a listener name from a config key that exists but has an empty value.","commonSituations":"Properties file with `listener.name=` (no value); JSON config with \"listener\": \"\"; defaulting a missing key to empty string instead of a real default.","solutions":["Provide a real listener name such as \"CONTROLLER\".","When loading config, treat empty as missing and fall back to a sensible default.","Validate non-empty before constructing: `if (listener == null || listener.isEmpty()) throw ...`."],"exampleFix":"// before\nString listener = props.getProperty(\"listener\", \"\");\nnew RaftVoterEndpoint(listener, host, port);\n\n// after\nString listener = props.getProperty(\"listener\", \"CONTROLLER\");\nnew RaftVoterEndpoint(listener, host, port);","handlingStrategy":"validation","validationCode":"if (listener == null || listener.isEmpty()) {\n    throw new IllegalArgumentException(\"listener name required\");\n}\nnew RaftVoterEndpoint(listener, host, port);","typeGuard":"static String requireNonEmptyListener(String s) {\n    if (s == null || s.isEmpty()) throw new IllegalArgumentException(\"listener empty\");\n    return s;\n}","tryCatchPattern":"try {\n    new RaftVoterEndpoint(listener, host, port);\n} catch (IllegalArgumentException e) {\n    throw new IllegalStateException(\"Voter config invalid: \" + e.getMessage(), e);\n}","preventionTips":["Default listener name to a constant (\"CONTROLLER\") when reading config.","Reject empty config values at the config-loading boundary.","Validate the full voter descriptor before issuing addVoter calls."],"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"}