{"record":{"id":"04f45944a46d5da9","repo":"flowable/flowable-engine","slug":"cannot-use-this-method-of-the-businessprocess-bean","errorCode":null,"errorMessage":"Cannot use this method of the BusinessProcess bean within an active command.","messagePattern":"Cannot use this method of the BusinessProcess bean within an active command\\.","errorType":"exception","errorClass":"FlowableCdiException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cdi/src/main/java/org/flowable/cdi/BusinessProcess.java","lineNumber":94,"sourceCode":" * @author Falko Menge\n */\n@Named\npublic class BusinessProcess implements Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    @Inject\n    private ProcessEngine processEngine;\n\n    @Inject\n    private ContextAssociationManager associationManager;\n\n    @Inject\n    private Instance<Conversation> conversationInstance;\n\n    protected void validateValidUsage() {\n        if (Context.getCommandContext() != null) {\n            throw new FlowableCdiException(\"Cannot use this method of the BusinessProcess bean within an active command.\");\n        }\n    }\n\n    public ProcessInstance startProcessById(String processDefinitionId) {\n        validateValidUsage();\n\n        ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, getAndClearCachedVariables());\n        if (!instance.isEnded()) {\n            setExecution(instance);\n        }\n        return instance;\n    }\n\n    public ProcessInstance startProcessById(String processDefinitionId, String businessKey) {\n        validateValidUsage();\n\n        ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(processDefinitionId, businessKey, getAndClearCachedVariables());\n        if (!instance.isEnded()) {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cdi/src/main/java/org/flowable/cdi/BusinessProcess.java#L76-L112","documentation":"BusinessProcess.validateValidUsage guards CDI BusinessProcess start methods so they are never invoked while a Flowable command context is active on the current thread. Starting a process from inside an active command would nest process-start operations incorrectly, so FlowableCdiException is thrown.","triggerScenarios":"Calling businessProcess.startProcessById/startProcessByKey/startProcessByMessage from inside code executing within a Flowable command (e.g. from a JavaDelegate, task listener, execution listener, or synchronous engine callback) where Context.getCommandContext() != null.","commonSituations":"Invoking the CDI BusinessProcess bean from inside a service task delegate during process execution; firing CDI events handled synchronously within an engine command that then start new processes via BusinessProcess; custom command implementations calling BusinessProcess methods.","solutions":["Do not start processes from inside delegates/listeners; start them outside the engine command, e.g. from the CDI request layer after the original operation completes.","If processes must start as a reaction, publish a CDI event handled @Observes (after transaction) or use an async executor outside the command context.","Refactor to use runtimeService.startProcessInstanceBy... directly within the command if starting inside the engine is truly intended and understood.","Move BusinessProcess.startProcess* calls to application-managed beans (request/session scope) rather than engine callbacks."],"exampleFix":"// before (inside a JavaDelegate)\nbusinessProcess.startProcessByKey(\"nextProcess\");\n// after\n@Stateless\npublic class Starter {\n  @Inject BusinessProcess businessProcess;\n  public void startNext() { businessProcess.startProcessByKey(\"nextProcess\"); } // called outside command\n}","handlingStrategy":"validation","validationCode":"if (org.flowable.engine.impl.context.Context.getCommandContext() != null) {\n    throw new IllegalStateException(\"Do not call BusinessProcess.startProcess* inside an active Flowable command\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    businessProcess.startProcessByKey(\"myProcess\");\n} catch (FlowableCdiException e) {\n    if (e.getMessage().contains(\"within an active command\")) {\n        // defer to after command completion (e.g. fire CDI event or async task)\n    }\n    throw e;\n}","preventionTips":["Never call BusinessProcess start methods from JavaDelegates, listeners, or custom commands.","Start processes from application-scoped/request-scoped CDI beans instead.","Use asynchronous CDI events for process chaining triggered inside engine commands."],"tags":["cdi","flowable","command-context","invalid-usage"],"backgroundTag":"invalid-state-transition","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}