{"record":{"id":"815b10a70c0ec3fd","repo":"aeron-io/aeron","slug":"invalid-state-counter-code","errorCode":null,"errorMessage":"invalid state counter code: ","messagePattern":"invalid state counter code: ","errorType":"exception","errorClass":"ClusterException","httpStatus":null,"severity":"error","filePath":"aeron-cluster/src/main/java/io/aeron/cluster/ClusterBackup.java","lineNumber":195,"sourceCode":"            if (counter.isClosed())\n            {\n                return CLOSED;\n            }\n\n            return get(counter.get());\n        }\n\n        /**\n         * Get the {@link State} with matching {@link #code()}.\n         *\n         * @param code to lookup.\n         * @return the {@link State} matching {@link #code()}.\n         */\n        public static State get(final long code)\n        {\n            if (code < 0 || code > (STATES.length - 1))\n            {\n                throw new ClusterException(\"invalid state counter code: \" + code);\n            }\n\n            return STATES[(int)code];\n        }\n    }\n\n    /**\n     * Defines the type of node that this will receive log data from.\n     */\n    public enum SourceType\n    {\n        /**\n         * Receive from any node in the cluster.\n         */\n        ANY,\n        /**\n         * Only receive data from the leader node.\n         */","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-cluster/src/main/java/io/aeron/cluster/ClusterBackup.java#L177-L213","documentation":"ClusterBackup.State.get(code) maps a cluster backup state counter value to its State enum. It throws ClusterException when the code is negative or beyond the last state, since no such state exists. The counter likely came from a different or incompatible Aeron version, or was corrupted.","triggerScenarios":"Calling ClusterBackup.State.get() with a counter value read from a CountersReader that is < 0 or >= STATES.length, e.g. reading the wrong counter ID or a counter from an incompatible Aeron version.","commonSituations":"Mixing Aeron client/cluster versions (counter layout changed), passing a counter ID instead of the counter value, or reading a stale/unregistered counter.","solutions":["Check the counter value being passed is the actual state value, not a counter ID or offset.","Ensure all Aeron artifacts (client, cluster, archive) are the same version.","Validate the code is within 0..State.values().length-1 before calling get().","Re-read the counter from the correct CountersReader in case of corruption or a torn read."],"exampleFix":"// before\nState state = ClusterBackup.State.get(counterId); // wrong: ID, not value\n// after\nlong value = counters.getCounterValue(counterId);\nState state = (value >= 0 && value < State.values().length) ? ClusterBackup.State.get(value) : null;","handlingStrategy":"type-guard","validationCode":"if (code < 0 || code >= ClusterBackup.State.values().length) { return null; }","typeGuard":"static ClusterBackup.State safeState(long code) { return (code >= 0 && code < ClusterBackup.State.values().length) ? ClusterBackup.State.get(code) : null; }","tryCatchPattern":"try {\n    state = ClusterBackup.State.get(value);\n} catch (ClusterException e) {\n    log.error(\"unknown backup state counter value {}: version mismatch?\", value);\n}","preventionTips":["Read the counter value, not the counter ID, before mapping to State","Keep Aeron client/cluster/archive versions aligned","Validate counter values in range before calling get()"],"tags":["enum","counter","value-out-of-range","aeron-cluster"],"backgroundTag":"invalid-enum-value","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}