{"record":{"id":"c1606db0441ad2ea","repo":"flowable/flowable-engine","slug":"cannot-associate-with-execution-null","errorCode":null,"errorMessage":"Cannot associate with execution: null","messagePattern":"Cannot associate with execution: null","errorType":"exception","errorClass":"FlowableCdiException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/context/DefaultContextAssociationManager.java","lineNumber":145,"sourceCode":"     * Override to add different / additional contexts.\r\n     *\r\n     * @return a list of {@link Scope}-types, which are used in the given order to resolve the broadest active context (@link #getBroadestActiveContext()})\r\n     */\r\n    protected List<Class<? extends ScopedAssociation>> getAvailableScopedAssociationClasses() {\r\n        ArrayList<Class<? extends ScopedAssociation>> scopeTypes = new ArrayList<>();\r\n        scopeTypes.add(ConversationScopedAssociation.class);\r\n        scopeTypes.add(RequestScopedAssociation.class);\r\n        return scopeTypes;\r\n    }\r\n\r\n    protected ScopedAssociation getScopedAssociation() {\r\n        return ProgrammaticBeanLookup.lookup(getBroadestActiveContext(), beanManager);\r\n    }\r\n\r\n    @Override\r\n    public void setExecution(Execution execution) {\r\n        if (execution == null) {\r\n            throw new FlowableCdiException(\"Cannot associate with execution: null\");\r\n        }\r\n\r\n        if (Context.getCommandContext() != null) {\r\n            throw new FlowableCdiException(\"Cannot work with scoped associations inside command context.\");\r\n        }\r\n\r\n        ScopedAssociation scopedAssociation = getScopedAssociation();\r\n        Execution associatedExecution = scopedAssociation.getExecution();\r\n        if (associatedExecution != null && !associatedExecution.getId().equals(execution.getId())) {\r\n            throw new FlowableCdiException(\"Cannot associate \" + execution + \", already associated with \" + associatedExecution + \". Disassociate first!\");\r\n        }\r\n\r\n        if (LOGGER.isTraceEnabled()) {\r\n            LOGGER.trace(\"Associating {} (@{})\", execution, scopedAssociation.getClass().getAnnotations()[0].annotationType().getSimpleName());\r\n        }\r\n        scopedAssociation.setExecution(execution);\r\n    }\r\n\r","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/context/DefaultContextAssociationManager.java#L127-L163","documentation":"DefaultContextAssociationManager.setExecution(Execution) associates the current CDI scope with a process execution. Passing null is rejected outright with this FlowableCdiException because a null association is meaningless — use disAssociate() to clear an existing association.","triggerScenarios":"Calling businessProcess.associateExecution(null) / setExecution(null), typically when the execution lookup (e.g. runtimeService.createExecutionQuery()...singleResult()) returned null and its result was passed straight through.","commonSituations":"Execution already ended so the query for it returns null; typo'd execution/business-key; using process instance id where an execution id is required and vice versa.","solutions":["Verify the execution exists before associating: runtimeService.createExecutionQuery().executionId(id).singleResult() != null.","Call businessProcess.disAssociate() instead of passing null to clear the current association.","Check you are passing the process instance id / execution id you actually intend (not a task id)."],"exampleFix":"// before\nbusinessProcess.associateExecution(executionQuery.singleResult()); // may be null\n// after\nExecution e = executionQuery.singleResult();\nif (e != null) businessProcess.associateExecution(e);","handlingStrategy":"validation","validationCode":"Execution e = runtimeService.createExecutionQuery().executionId(executionId).singleResult();\nif (e == null) throw new IllegalArgumentException(\"execution \" + executionId + \" not found\");","typeGuard":"static boolean isNonNullExecution(Execution ex) { return ex != null && ex.getId() != null; }","tryCatchPattern":"try { businessProcess.associateExecution(e); } catch (FlowableCdiException e) { /* null guard failed; resolve execution again */ }","preventionTips":["Never pass query results straight to associateExecution without a null check","Use disAssociate() to clear associations, not null","Distinguish execution ids from task ids and business keys"],"tags":["cdi","null-argument","execution-association"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}