{"record":{"id":"bb5983589f2a620e","repo":"flowable/flowable-engine","slug":"unsupported-variablecontainer-for-key-case-inst","errorCode":null,"errorMessage":"Unsupported variableContainer for key '${CASE_INSTANCE_KEY}': ${scopeContainer.class.name}","messagePattern":"Unsupported variableContainer for key '(.+?)': (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/scripting/CmmnVariableScopeResolver.java","lineNumber":105,"sourceCode":"                throw new FlowableException(\"The service '\" + key + \"' is not available in the current context. Please enable services in scripting.\");\n            }\n        } else if (CASE_INSTANCE_KEY.equals(key)) {\n            if (scopeContainer instanceof CaseInstance) {\n                return scopeContainer;\n\n            } else if (scopeContainer instanceof PlanItemInstance planItemInstance) {\n                if (StringUtils.isNotEmpty(planItemInstance.getCaseInstanceId())) {\n                    return CommandContextUtil.getCaseInstanceEntityManager().findById(planItemInstance.getCaseInstanceId());\n                }\n\n            } else if (scopeContainer instanceof Task task) {\n                if (StringUtils.isNotEmpty(task.getScopeId()) && ScopeTypes.CMMN.equals(task.getScopeType())) {\n                    return CommandContextUtil.getCaseInstanceEntityManager().findById(task.getScopeId());\n                }\n\n            }\n\n            throw new FlowableException(\"Unsupported variableContainer for key '\" + CASE_INSTANCE_KEY + \"': \" + scopeContainer.getClass().getName());\n\n        } else if (PLAN_ITEM_INSTANCE_KEY.equals(key)) {\n            if (scopeContainer instanceof PlanItemInstance) {\n                return scopeContainer;\n\n            }  else if (scopeContainer instanceof Task task) {\n                if (StringUtils.isNotEmpty(task.getSubScopeId()) && ScopeTypes.CMMN.equals(task.getScopeType())) {\n                    return CommandContextUtil.getPlanItemInstanceEntityManager().findById(task.getSubScopeId());\n                }\n\n            }\n\n            throw new FlowableException(\"Unsupported variableContainer for key '\" + PLAN_ITEM_INSTANCE_KEY + \"': \" + scopeContainer.getClass().getName());\n\n        } else if (TASK_KEY.equals(key)) {\n            if (scopeContainer instanceof Task) {\n                return scopeContainer;\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/scripting/CmmnVariableScopeResolver.java#L87-L123","documentation":"CmmnVariableScopeResolver.get resolves well-known scripting variable keys (e.g. 'caseInstance') against the current variableContainer. When the container type does not map to the requested key (e.g. asking for the case instance while the container is a plain Task that is not CMMN-scoped, or a VariableScope that is neither CaseInstanceEntity, PlanItemInstance nor a CMMN Task), it throws this FlowableException. It signals a mismatch between the scripted variable being requested and the context in which the script runs.","triggerScenarios":"Calling variableScopeResolver.get(CASE_INSTANCE_KEY, scopeContainer) (directly or via CMMN script/expression variable resolution) with a scopeContainer that is not a CaseInstanceEntity, PlanItemInstance, or a Task whose scopeType is CMMN; e.g. requesting caseInstance inside a script executed with a standalone TaskHelper/VariableScope not attached to a case.","commonSituations":"Custom script tasks or delegates in CMMN using the implicit 'caseInstance' variable outside a case context; mixing process (BPMN) tasks with CMMN variable resolvers; upgrading Flowable and changing how the resolver is invoked from custom code.","solutions":["Ensure the script/expression requesting 'caseInstance' executes within a CMMN case context (scopeContainer is a CaseInstanceEntity or CMMN-scoped Task/PlanItemInstance)","If the container is a Task, verify task.getScopeType() equals ScopeTypes.CMMN and scopeId is set before resolving","Pass the correct VariableContainer type for the key being resolved, or resolve the case instance explicitly via CaseInstanceEntityManager.findById","Log scopeContainer.getClass().getName() to identify which unsupported container type is being passed and adjust the call site"],"exampleFix":"// before\nObject caseInstance = resolver.get(CASE_INSTANCE_KEY, someVariableScope);\n// after\nif (someVariableScope instanceof CaseInstanceEntity || (someVariableScope instanceof Task t && ScopeTypes.CMMN.equals(t.getScopeType()))) {\n    Object caseInstance = resolver.get(CASE_INSTANCE_KEY, someVariableScope);\n} else {\n    throw new IllegalStateException(\"caseInstance not available in this context\");\n}","handlingStrategy":"validation","validationCode":"boolean canResolveCaseInstance(Object container) {\n    return container instanceof CaseInstanceEntity\n        || container instanceof PlanItemInstance\n        || (container instanceof org.flowable.task.api.Task t && ScopeTypes.CMMN.equals(t.getScopeType()));\n}","typeGuard":"boolean isCmmnScoped(Task t) { return t != null && t.getScopeId() != null && ScopeTypes.CMMN.equals(t.getScopeType()); }","tryCatchPattern":"try { return resolver.get(CASE_INSTANCE_KEY, container); } catch (FlowableException e) { if (e.getMessage().contains(\"Unsupported variableContainer\")) { log.warn(\"No case context for container {}\", container); return null; } throw e; }","preventionTips":["Reference 'caseInstance' only in scripts inside a case context","Verify scopeType is CMMN before resolving CMMN keys from Tasks","Log container class names during development to catch context mismatches early"],"tags":["cmmn","scripting","variable-resolution","flowable"],"backgroundTag":"unsupported-operation","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"}