flowable/flowable-engine · error · FlowableException
Could not determine an active context to associate the…
Error message
Could not determine an active context to associate the current process instance / task instance with.
What it means
getBroadestActiveContext() iterates the candidate ScopedAssociation scope types and tries beanManager.getContext(scopeType) on each; if none of the CDI contexts are active (ContextNotActiveException for all), it fails hard with this FlowableException because the CDI integration has nowhere to store the current process instance / task association.
Solutions
- Run the code inside an active CDI context (request/conversation/session); in web apps ensure the request goes through the CDI-enabled filter (Weld ContextFilter).
- For background work, activate a context programmatically (e.g. Weld's BoundRequest / context activation APIs) before calling BusinessProcess methods.
- Use engine services (RuntimeService/TaskService) directly instead of the CDI-scoped association when no CDI context exists.
Example fix
// before executorService.submit(() -> businessProcess.associateExecution(executionId)); // after executorService.submit(() -> runtimeService.setVariable(executionId, "k", v)); // no CDI context needed
Defensive patterns
Strategy: fallback
Validate before calling
boolean cdiActive = javax.enterprise.inject.spi.CDI.current().select(BusinessProcess.class)
.get() != null; // plus run inside request/conversation scope Type guard
null
Try / catch
try { return businessProcess.getVariable(name); } catch (FlowableException e) { return runtimeService.getVariable(executionId, name); } Prevention
- Only use BusinessProcess APIs from CDI-managed, context-active code (JSF/JAX-RS request threads)
- In background threads, activate a CDI context explicitly or use engine services directly
- In tests, boot a CDI container (Weld SE) instead of calling BusinessProcess raw
When it happens
Trigger: Calling BusinessProcess methods (associateExecution, setExecution, getVariable, startTask, etc.) outside any active CDI context — e.g. from a non-managed thread, a static initializer, a timer, or before the CDI container provides request/conversation/session contexts.
Common situations: Invoking business-process APIs from background threads (scheduled jobs, message listeners) without opening a request context; unit tests without a CDI container (Weld/OpenWebBeans) booted; CDI contexts destroyed by an earlier conversation.end() call.
Related errors
- Can only unacquire BPMN or CMMN external job. Job with id
- Cannot associate , already associated with . Disassociate…
- Cannot associate execution by id: no execution with id '
- Cannot associate with execution: null
- Cannot disassociate execution, no
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/099e26d0289ecc61.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/context/DefaultContextAssociationManager.java:123
}
@Inject
private BeanManager beanManager;
protected Class<? extends ScopedAssociation> getBroadestActiveContext() {
for (Class<? extends ScopedAssociation> scopeType : getAvailableScopedAssociationClasses()) {
Annotation scopeAnnotation = scopeType.getAnnotations().length > 0 ? scopeType.getAnnotations()[0] : null;
if (scopeAnnotation == null || !beanManager.isScope(scopeAnnotation.annotationType())) {
throw new FlowableException("ScopedAssociation must carry exactly one annotation and it must be a @Scope annotation");
}
try {
beanManager.getContext(scopeAnnotation.annotationType());
return scopeType;
} catch (ContextNotActiveException e) {
LOGGER.trace("Context {} not active.", scopeAnnotation.annotationType());
}
}
throw new FlowableException("Could not determine an active context to associate the current process instance / task instance with.");
}
/**
* Override to add different / additional contexts.
*
* @return a list of {@link Scope}-types, which are used in the given order to resolve the broadest active context (@link #getBroadestActiveContext()})
*/
protected List<Class<? extends ScopedAssociation>> getAvailableScopedAssociationClasses() {
ArrayList<Class<? extends ScopedAssociation>> scopeTypes = new ArrayList<>();
scopeTypes.add(ConversationScopedAssociation.class);
scopeTypes.add(RequestScopedAssociation.class);
return scopeTypes;
}
protected ScopedAssociation getScopedAssociation() {
return ProgrammaticBeanLookup.lookup(getBroadestActiveContext(), beanManager);
}
View on GitHub (pinned to d6d39ce1c6)