{"record":{"id":"3282350451245ad0","repo":"aeron-io/aeron","slug":"id-already-in-use-id","errorCode":null,"errorMessage":"id already in use: <id>","messagePattern":"id already in use: <id>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-cluster/src/main/java/io/aeron/cluster/logging/ClusterEventCode.java","lineNumber":187,"sourceCode":"    START(27);\n\n    static final int EVENT_CODE_TYPE = EventCodeType.CLUSTER.getTypeCode();\n    static final ClusterEventCode[] EVENT_CODE_BY_ID;\n\n    private final int id;\n\n    static\n    {\n        final ClusterEventCode[] codes = ClusterEventCode.values();\n        final int maxId = Arrays.stream(codes).mapToInt(ClusterEventCode::id).max().orElse(0);\n        EVENT_CODE_BY_ID = new ClusterEventCode[maxId + 1];\n\n        for (final ClusterEventCode code : codes)\n        {\n            final int id = code.id();\n            if (null != EVENT_CODE_BY_ID[id])\n            {\n                throw new IllegalArgumentException(\"id already in use: \" + id);\n            }\n\n            EVENT_CODE_BY_ID[id] = code;\n        }\n    }\n\n    ClusterEventCode(final int id)\n    {\n        this.id = id;\n    }\n\n    /**\n     * Get the ClusterEventCode enum value from the identifier.\n     * @param id to look up.\n     * @return the resolved enum value.\n     */\n    public static ClusterEventCode get(final int id)\n    {","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-cluster/src/main/java/io/aeron/cluster/logging/ClusterEventCode.java#L169-L205","documentation":"ClusterEventCode's static initializer registers each enum constant by its id into EVENT_CODE_BY_ID; if two constants share the same id the lookup table entry is already occupied and IllegalArgumentException is thrown. This is an internal invariant of the enum definition, only triggered by editing the enum itself.","triggerScenarios":"Adding a new ClusterEventCode constant whose id() collides with an existing constant's id; refactoring ids and accidentally duplicating one.","commonSituations":"Contributors adding new cluster event codes to the Aeron source without checking the id table; merging branches that both introduced the same id.","solutions":["Change the new enum constant's id to an unused unique value","Audit all ClusterEventCode ids for duplicates after adding a constant","Add a unit test that constructs ClusterEventCode values to surface collisions early"],"exampleFix":"// before\nFOO(17),\nBAR(17); // duplicate id\n// after\nFOO(17),\nBAR(18);","handlingStrategy":"validation","validationCode":"// For contributors: ensure new id is unique\nassert java.util.Arrays.stream(ClusterEventCode.values())\n    .mapToInt(ClusterEventCode::id).distinct().count()\n    == ClusterEventCode.values().length;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pick the next unused id when adding event codes","Add a class-init test for the enum in CI","Review id assignments in code review"],"tags":["aeron","enum","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}