{"record":{"id":"f9ba9701a129dd9a","repo":"alibaba/COLA","slug":"transition-already-exist-you-can-not-add-anoth","errorCode":null,"errorMessage":"${transition} already Exist, you can not add another one","messagePattern":"(.+?) already Exist, you can not add another one","errorType":"exception","errorClass":"StateMachineException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/EventTransitions.java","lineNumber":45,"sourceCode":"            transitions.add(transition);\n            eventTransitions.put(event, transitions);\n        }\n        else{\n            List existingTransitions = eventTransitions.get(event);\n            verify(existingTransitions, transition);\n            existingTransitions.add(transition);\n        }\n    }\n\n    /**\n     * Per one source and target state, there is only one transition is allowed\n     * @param existingTransitions\n     * @param newTransition\n     */\n    private void verify(List<Transition<S,E,C>> existingTransitions, Transition<S,E,C> newTransition) {\n        for (Transition transition : existingTransitions) {\n            if (transition.equals(newTransition)) {\n                throw new StateMachineException(transition + \" already Exist, you can not add another one\");\n            }\n        }\n    }\n\n    public List<Transition<S,E,C>> get(E event){\n        return eventTransitions.get(event);\n    }\n\n    public List<Transition<S,E,C>> allTransitions(){\n        List<Transition<S,E,C>> allTransitions = new ArrayList<>();\n        for(List<Transition<S,E,C>> transitions : eventTransitions.values()){\n            allTransitions.addAll(transitions);\n        }\n        return allTransitions;\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":62,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/EventTransitions.java#L27-L62","documentation":"EventTransitions stores transitions grouped by event. verify() is called from put() and throws this StateMachineException if an equal transition (same event, source, target) already exists, preventing silent overwrites/duplicates in the state machine definition.","triggerScenarios":"Calling builder states().state(...).event(...).from(s).to(t) twice for the identical (event, source, target) triple, or programmatically adding a duplicate Transition via put().","commonSituations":"Copy-pasted builder blocks registering the same transition twice; merging two state machine definitions that both define the same transition; generated configuration duplicating edges.","solutions":["Remove the duplicate transition registration in the builder so each (event, source, target) is declared once","If multiple targets are needed under one event, use conditions (when(...)) on distinct transitions rather than identical duplicates","Review generated/merged state machine configs for duplicated edges before build"],"exampleFix":"// before\n.from(STATE_A).to(STATE_B)  // in block 1\n.from(STATE_A).to(STATE_B)  // duplicate in block 2 -> throws\n\n// after\n.from(STATE_A).to(STATE_B).when(condition1)\n.from(STATE_A).to(STATE_C).when(condition2)","handlingStrategy":"validation","validationCode":"// keep a Set of 'event|source|target' keys while building to detect duplicates\nif (!transitionKeys.add(event + \"|\" + source + \"|\" + target)) {\n    throw new IllegalStateException(\"duplicate transition\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    sm = builder.build(machineId);\n} catch (StateMachineException e) {\n    if (e.getMessage().contains(\"already Exist\")) {\n        // dedupe the builder configuration and rebuild\n    } else {\n        throw e;\n    }\n}","preventionTips":["Declare each (event, source, target) transition exactly once","Use conditions (when) for branching instead of duplicate edges","Review generated/merged state machine configs for duplicate edges","Centralize transition definitions to avoid copy-paste duplicates"],"tags":["statemachine","duplicate-registration","transition"],"backgroundTag":"file-already-exists","analyzedSha":"352e1a867538d9cd40e1b11e4028fa652fc97557","analyzedAt":"2026-09-08T00:46:23.972Z","contentChangedAt":"2026-09-08T00:46:23.972Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}