{"record":{"id":"c399bc3ccedf2a78","repo":"apache/cassandra","slug":"illegal-state","errorCode":null,"errorMessage":"Illegal state: ","messagePattern":"Illegal state: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/tcm/Commit.java","lineNumber":426,"sourceCode":"\n            messagingService.accept(message.responseWith(result), message.from());\n        }\n\n        private void checkCMSState()\n        {\n            switch (cmsStateSupplier.get())\n            {\n                case RESET:\n                case LOCAL:\n                    break;\n                case REMOTE:\n                    throw new NotCMSException(\"Not currently a member of the CMS, can't commit\");\n                case GOSSIP:\n                    String msg = \"Tried to commit when in gossip mode\";\n                    logger.error(msg);\n                    throw new IllegalStateException(msg);\n                default:\n                    throw new IllegalStateException(\"Illegal state: \" + cmsStateSupplier.get());\n            }\n        }\n    }\n\n    public interface Replicator\n    {\n        Replicator NO_OP = (a,b) -> {};\n        void send(Result result, InetAddressAndPort source);\n    }\n\n    public static class DefaultReplicator implements Replicator\n    {\n        public static class RoutingHelper\n        {\n            private final Directory directory;\n            private final EndpointLookup endpoints;\n\n            public RoutingHelper(ClusterMetadata metadata)","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/tcm/Commit.java#L408-L444","documentation":"This is the default arm of the same switch in Commit.checkCMSState (Commit.java:426): when the CMS state supplier returns a value that is neither LOCAL, REMOTE, nor GOSSIP, the code throws IllegalStateException(\"Illegal state: \" + state). It is a defensive invariant guard against an unknown/uninitialized ClusterMetadataService state, meaning the node's cluster-metadata mode is not one of the recognized values.","triggerScenarios":"Commit.doVerb invokes checkCMSState and cmsStateSupplier.get() returns an enum value outside LOCAL/REMOTE/GOSSIP — e.g. an uninitialized or transiently null/unknown CMS state during startup or a future state added without updating the switch.","commonSituations":"Node startup race where cluster metadata service state is not yet resolved when a commit verb arrives; custom builds or newer protocol versions introducing an extra CMS state; corrupted in-memory CMS state.","solutions":["Log/inspect the reported state value to see which unexpected CMSState was returned and why the state supplier resolved to it.","Ensure the node has fully initialized ClusterMetadataService before participating in TCM commits (gate doVerb on service initialization).","If running a mixed-version cluster, verify the peer's TCM state enum is compatible with this node's version.","Restart the affected node to reinitialize the CMS state if it is stuck in an unknown value."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"ClusterMetadataService.CMSState s = ClusterMetadataService.instance().state();\nif (s != CMSState.LOCAL && s != CMSState.REMOTE && s != CMSState.GOSSIP)\n    logger.warn(\"CMS state {} unrecognized; delaying commit\", s);","typeGuard":null,"tryCatchPattern":"try { checkCMSState(); } catch (IllegalStateException e) { logger.error(\"Unexpected CMS state during commit\", e); /* defer or abort the commit */ }","preventionTips":["Gate TCM verbs on ClusterMetadataService initialization","Keep CMS state enums in sync across mixed versions","Restart nodes whose CMS state is stuck in an unknown value"],"tags":["tcm","illegal-state","cluster-metadata","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}