{"record":{"id":"9ef1083a2ab6c0a1","repo":"alibaba/COLA","slug":"there-is-no-statemachine-instance-for-machineid","errorCode":null,"errorMessage":"There is no stateMachine instance for ${machineId}, please build it first","messagePattern":"There is no stateMachine instance for (.+?), please build it first","errorType":"exception","errorClass":"StateMachineException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java","lineNumber":28,"sourceCode":" *\n * @author Frank Zhang\n * @date 2020-02-08 10:21 PM\n */\npublic class StateMachineFactory {\n    static Map<String /* machineId */, StateMachine> stateMachineMap = new ConcurrentHashMap<>();\n\n    public static <S, E, C> void register(StateMachine<S, E, C> stateMachine){\n        String machineId = stateMachine.getMachineId();\n        if(stateMachineMap.get(machineId) != null){\n            throw new StateMachineException(\"The state machine with id [\"+machineId+\"] is already built, no need to build again\");\n        }\n        stateMachineMap.put(stateMachine.getMachineId(), stateMachine);\n    }\n\n    public static <S, E, C> StateMachine<S, E, C> get(String machineId){\n        StateMachine stateMachine = stateMachineMap.get(machineId);\n        if(stateMachine == null){\n            throw new StateMachineException(\"There is no stateMachine instance for \"+machineId+\", please build it first\");\n        }\n        return stateMachine;\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":33,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/StateMachineFactory.java#L10-L33","documentation":"StateMachineFactory.get() looks up a built state machine by machineId in the static registry and throws this StateMachineException when no machine with that id has been built/registered. It is a lookup failure: the caller referenced a machine id that was never built in this JVM.","triggerScenarios":"Calling StateMachineFactory.get(\"someId\") before building the machine, with a typo in the machineId, or after the building code never ran (e.g. missing configuration/bean initialization).","commonSituations":"Typos or renamed machine ids; consumer code running in a different JVM/module than the builder; startup ordering where get() runs before build().","solutions":["Build the machine first via StateMachineBuilder before calling get(), with the exact same machineId","Verify the machineId string matches the one used at build time (extract it to a constant)","Check initialization ordering / ensure the builder bean is initialized before consumers call get()"],"exampleFix":"// before\nStateMachine<...> sm = StateMachineFactory.get(\"orderSM\"); // never built -> throws\n\n// after\nStateMachine<...> sm = StateMachineFactory.get(STATE_MACHINE_ID);\nif (sm == null) {\n    sm = buildOrderStateMachine(STATE_MACHINE_ID);\n}","handlingStrategy":"validation","validationCode":"StateMachine sm = StateMachineFactory.get(machineId);\nif (sm == null) {\n    throw new IllegalStateException(\"Build state machine first: \" + machineId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    sm = StateMachineFactory.get(machineId);\n} catch (StateMachineException e) {\n    if (e.getMessage().contains(\"please build it first\")) {\n        sm = buildStateMachine(machineId); // build then retry\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always build before get, or get-and-build-if-null","Extract machineId strings into shared constants","Verify builder code runs in the same JVM as consumers","Check startup initialization ordering"],"tags":["statemachine","resource-not-found","factory"],"backgroundTag":"entity-not-found","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"}