{"record":{"id":"94f90c6830eb3595","repo":"alibaba/COLA","slug":"state-machine-is-not-built-yet-can-not-work","errorCode":null,"errorMessage":"State machine is not built yet, can not work","messagePattern":"State machine is not built yet, can not work","errorType":"exception","errorClass":"StateMachineException","httpStatus":null,"severity":"error","filePath":"cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java","lineNumber":131,"sourceCode":"                transit = transition;\n            }\n            result.add(transit);\n        }\n        return result;\n    }\n\n    private State getState(S currentStateId) {\n        State state = StateHelper.getState(stateMap, currentStateId);\n        if (state == null) {\n            showStateMachine();\n            throw new StateMachineException(currentStateId + \" is not found, please check state machine\");\n        }\n        return state;\n    }\n\n    private void isReady() {\n        if (!ready) {\n            throw new StateMachineException(\"State machine is not built yet, can not work\");\n        }\n    }\n\n    @Override\n    public String accept(Visitor visitor) {\n        StringBuilder sb = new StringBuilder();\n        sb.append(visitor.visitOnEntry(this));\n        for (State state : stateMap.values()) {\n            sb.append(state.accept(visitor));\n        }\n        sb.append(visitor.visitOnExit(this));\n        return sb.toString();\n    }\n\n    @Override\n    public void showStateMachine() {\n        SysOutVisitor sysOutVisitor = new SysOutVisitor();\n        accept(sysOutVisitor);","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/alibaba/COLA/blob/352e1a867538d9cd40e1b11e4028fa652fc97557/cola-components/cola-component-statemachine/src/main/java/com/alibaba/cola/statemachine/impl/StateMachineImpl.java#L113-L149","documentation":"StateMachineImpl tracks a 'ready' flag that is set only after build() completes. isReady(), checked by fireEvent, fireParallelEvent, and verify, throws this StateMachineException when the machine is used before it has been built, preventing operations on an incomplete machine.","triggerScenarios":"Calling fireEvent/fireParallelEvent/verify on a state machine instance obtained but whose builder build() has not finished or was never called; using a machine retained from an aborted builder chain.","commonSituations":"Builder chain interrupted by an exception before build(); asynchronous usage where consumers get a reference to the machine before initialization completes.","solutions":["Always finish the builder chain with build(machineId) before using the machine","Obtain instances via StateMachineFactory.get(machineId), which only returns built machines","Fix any exception in the builder chain that leaves the machine unbuilt","Ensure initialization completes (synchronously or via a ready check) before consumers fire events"],"exampleFix":"// before\nStateMachine sm = builder.buildStateMachine(); // chain without proper build finish\nsm.fireEvent(...); // throws\n\n// after\nStateMachine sm = StateMachineBuilder.builder()\n    .states(...).end().build(\"orderSM\"); // ready\nsm.fireEvent(...);","handlingStrategy":"validation","validationCode":"// only expose machines obtained from the factory, which enforces built machines\nStateMachine sm = StateMachineFactory.get(machineId); // throws early if unbuilt","typeGuard":null,"tryCatchPattern":"try {\n    sm.fireEvent(...);\n} catch (StateMachineException e) {\n    if (e.getMessage().contains(\"not built yet\")) {\n        sm = finishBuild(machineId); // complete initialization then retry once\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always complete the builder chain with build(machineId)","Handle builder exceptions so a partially built machine is never leaked","Retrieve machines only via StateMachineFactory.get","Gate event firing behind an initialization-complete flag"],"tags":["statemachine","not-initialized","lifecycle"],"backgroundTag":"module-init-failed","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"}