{"id":"35f6db159efb24e7","repo":"apache/kafka","slug":"node-id-for-group-coordinator-node-cannot-be-negat","errorCode":null,"errorMessage":"Node id for group coordinator node cannot be negative","messagePattern":"Node id for group coordinator node cannot be negative","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/clients/consumer/internals/GroupCoordinatorNode.java","lineNumber":38,"sourceCode":"\n/**\n * This subclass of {@link Node} is used by the consumer for information about\n * a Kafka node which is a group coordinator. It ensures that the idString differs from\n * a regular node with the same node ID so that the network code can maintain separate\n * network connections to the same node as a regular broker and as a group coordinator.\n * It achieves this by ensuring that the node ID is non-negative (which it must be because\n * negative node IDs are used for bootstrapping) and by prepending a '+' on the node ID to\n * create the idString. This maintains the requirement that the idString can be parsed as\n * an integer to obtain the actual node ID.\n */\npublic class GroupCoordinatorNode extends Node {\n    public GroupCoordinatorNode(int id, String host, int port) {\n        super(GroupCoordinatorNode.validateId(id), host, port, null, false, \"+\" + id);\n    }\n\n    private static int validateId(int id) {\n        if (id < 0) {\n            throw new IllegalArgumentException(\"Node id for group coordinator node cannot be negative\");\n        }\n        return id;\n    }\n}","sourceCodeStart":20,"sourceCodeEnd":42,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/clients/consumer/internals/GroupCoordinatorNode.java#L20-L42","documentation":"IllegalArgumentException thrown by GroupCoordinatorNode.validateId when constructing a GroupCoordinatorNode with a negative id. The class deliberately separates the group-coordinator connection identity from a normal broker connection by prepending '+' to the idString; because negative node ids are reserved by the client for bootstrap/unresolved nodes, a negative coordinator id would collide with that namespace and is rejected. This is an internal invariant guard rather than a runtime config check.","triggerScenarios":"Raised only when GroupCoordinatorNode's constructor is called with id < 0. In practice this is an internal API used during FindCoordinator response handling; it should not occur unless a malformed FindCoordinator response returned a negative node id, or user code instantiates GroupCoordinatorNode directly with a bad id.","commonSituations":"Effectively never seen from application code. Theoretically possible with a misbehaving broker or a custom NetworkClient plumbing bogus coordinator metadata. If observed it indicates a bug in FindCoordinator response construction or in code wrapping the consumer internals.","solutions":["If calling the constructor directly, ensure the id comes from a valid FindCoordinator response node (always non-negative in well-formed responses).","Inspect broker logs and the FindCoordinator response; a negative id indicates broker-side corruption.","File a Kafka bug report with the FindCoordinator response contents if it comes from a stock client against a healthy broker."],"exampleFix":"// before\nnew GroupCoordinatorNode(-1, host, port);\n\n// after\nnew GroupCoordinatorNode(coordinatorNode.id(), coordinatorNode.host(), coordinatorNode.port());","handlingStrategy":"validation","validationCode":"if (nodeId < 0) {\n    throw new IllegalArgumentException(\"Refusing to build GroupCoordinatorNode with negative id: \" + nodeId);\n}","typeGuard":"private static boolean isAcceptableNodeId(int id) {\n    // Broker node ids must be non-negative; negative ids are reserved for bootstrap/seed nodes.\n    return id >= 0;\n}","tryCatchPattern":null,"preventionTips":["Never construct GroupCoordinatorNode directly from untrusted/seed-list node ids; the broker advertises the real coordinator id via FindCoordinator responses.","When parsing advertised.listeners or metadata, treat any negative id as a bootstrap placeholder, not a routable broker.","Validate ids at the boundary of any metadata deserialization before constructing Node subclasses.","In tests/fakes, use non-negative ids (e.g. 0, 1, 2) rather than -1 to model coordinator nodes."],"tags":["kafka","consumer","group-coordinator","internal","invariant"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}