{"record":{"id":"d1e721b9159281ac","repo":"apache/cassandra","slug":"not-a-node-id","errorCode":null,"errorMessage":"Not a node id: ","messagePattern":"Not a node id: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tcm/membership/NodeId.java","lineNumber":56,"sourceCode":"\n    private final int id;\n\n    public NodeId(int id)\n    {\n        this.id = id;\n    }\n\n    public static NodeId fromString(String nodeOrHostId)\n    {\n        if (nodeOrHostId.length() == UUID.randomUUID().toString().length())\n            return NodeId.fromUUID(UUID.fromString(nodeOrHostId));\n        return new NodeId(Integer.parseInt(nodeOrHostId));\n    }\n\n    public static NodeId fromUUID(UUID uuid)\n    {\n        if (!isValidNodeId(uuid))\n            throw new UnsupportedOperationException(\"Not a node id: \" + uuid); // see RemoveTest#testBadHostId\n\n        long id = 0x0FFFFFFFFFFFFFFFL & uuid.getLeastSignificantBits();\n        return new NodeId(Ints.checkedCast(id));\n    }\n\n    public static boolean isValidNodeId(UUID uuid)\n    {\n        long id = 0x0FFFFFFFFFFFFFFFL & uuid.getLeastSignificantBits();\n        return (uuid.getMostSignificantBits() == NODE_ID_UUID_MAGIC && id < Integer.MAX_VALUE) ||\n                (uuid.getMostSignificantBits() == 0 && uuid.getLeastSignificantBits() < Integer.MAX_VALUE); // old check, for existing cluster upgrades, no need upstream\n    }\n\n    @Deprecated(since = \"CEP-21\")\n    public UUID toUUID()\n    {\n        long lsb = 0xC000000000000000L | id;\n        return new UUID(NODE_ID_UUID_MAGIC, lsb);\n    }","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tcm/membership/NodeId.java#L38-L74","documentation":"NodeId.fromUUID converts a UUID to a NodeId only when the UUID was generated by fromString/from node-id encoding, i.e. its least significant bits hold a small non-negative int (isValidNodeId). It throws UnsupportedOperationException for any other UUID, such as a random hostId or schema-version UUID.","triggerScenarios":"Calling NodeId.fromUUID(uuid) with a random UUID (e.g. hostId from system.local or a schema version) whose 0x0FFFFFFFFFFFFFFF-masked least significant bits are not a valid positive node id.","commonSituations":"Confusing a node's hostId with its nodeId in TCM tooling; passing random UUIDs generated by UUID.randomUUID(); mixing gossip-era hostIds into TCM directory lookups.","solutions":["Pass the actual TCM node id-derived UUID (one produced by NodeId's own encoding), not a random hostId","Check isValidNodeId(uuid) before calling fromUUID and handle false gracefully","Use NodeId.fromString(String) when you have the numeric id like \"1\"","Look up the NodeId via the cluster Directory by endpoint/hostId instead of guessing a UUID"],"exampleFix":"// before\nNodeId id = NodeId.fromUUID(hostId); // random UUID -> throws\n// after\nNodeId id = NodeId.isValidNodeId(hostId)\n    ? NodeId.fromUUID(hostId)\n    : metadata.directory.peerId(endpoint);","handlingStrategy":"validation","validationCode":"if (!NodeId.isValidNodeId(uuid)) throw new IllegalArgumentException(uuid + \" is not a node id; use the directory lookup instead\");","typeGuard":"boolean isNodeIdUuid(java.util.UUID u) { return NodeId.isValidNodeId(u); }","tryCatchPattern":"try { return NodeId.fromUUID(uuid); } catch (UnsupportedOperationException e) { return resolveFromDirectory(uuid); }","preventionTips":["Never pass random UUIDs (hostId, schema version) where a NodeId UUID is expected","Resolve hostId -> NodeId via the TCM Directory, not by reinterpreting the UUID","Check isValidNodeId before conversion"],"tags":["cassandra","tcm","uuid"],"backgroundTag":"invalid-argument-format","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}