{"record":{"id":"dab2dd16ebd0649e","repo":"flowable/flowable-engine","slug":"plan-item-instance-planiteminstanceid-doesn-t-e","errorCode":null,"errorMessage":"plan item instance ${planItemInstanceId} doesn't exist","messagePattern":"plan item instance (.+?) doesn't exist","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetPlanItemVariableInstanceCmd.java","lineNumber":50,"sourceCode":"\n    public GetPlanItemVariableInstanceCmd(String planItemInstanceId, String variableName) {\n        this.planItemInstanceId = planItemInstanceId;\n        this.variableName = variableName;\n    }\n\n    @Override\n    public VariableInstance execute(CommandContext commandContext) {\n        if (planItemInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"planItemInstanceId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variableName is null\");\n        }\n\n        PlanItemInstanceEntity planItemInstance = CommandContextUtil.getPlanItemInstanceEntityManager(commandContext).findById(planItemInstanceId);\n\n        if (planItemInstance == null) {\n            throw new FlowableObjectNotFoundException(\"plan item instance \" + planItemInstanceId + \" doesn't exist\", PlanItemInstance.class);\n        }\n\n        return planItemInstance.getVariableInstance(variableName, false);\n    }\n}\n","sourceCodeStart":32,"sourceCodeEnd":56,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetPlanItemVariableInstanceCmd.java#L32-L56","documentation":"After validating both arguments, GetPlanItemVariableInstanceCmd loads the plan item and throws FlowableObjectNotFoundException ('plan item instance <id> doesn't exist') when findById returns null. Unlike the null-argument errors, the inputs are well-formed but the referenced plan item is not present in the runtime tables.","triggerScenarios":"Reading a local variable for a plan item that already completed or whose case instance ended; using an id from a previous transaction/test run; querying the wrong engine database; passing a case or stage id instead of a plan item id.","commonSituations":"Variable listeners firing after completion race; cached ids in UI sessions pointing at terminated items; test fixtures replaying old ids; multi-environment deployments with divergent data.","solutions":["Check existence first via createPlanItemInstanceQuery().planItemInstanceId(id).singleResult().","If the plan item ended, use history services (HistoricVariableInstance queries) for past values.","Re-fetch fresh ids from the live case instance before variable access.","Confirm the caller and engine share the same database/schema."],"exampleFix":"// before\nVariableInstance vi = cmmnRuntimeService.getPlanItemVariableInstance(planItemId, varName);\n// after\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemId).singleResult();\nVariableInstance vi = (pii != null) ? cmmnRuntimeService.getPlanItemVariableInstance(planItemId, varName) : null;","handlingStrategy":"try-catch","validationCode":"PlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).singleResult();\nif (pii == null) return null;","typeGuard":"boolean planItemInstanceExists(String id) {\n    return cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id).count() > 0;\n}","tryCatchPattern":"try {\n    vi = cmmnRuntimeService.getPlanItemVariableInstance(planItemInstanceId, variableName);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Plan item {} gone; falling back to history\", planItemInstanceId);\n    vi = fromHistory(planItemInstanceId, variableName);\n}","preventionTips":["Pre-query existence before reading variables","Fall back to history services for completed items","Refresh ids each time instead of caching","Handle concurrent completion races defensively"],"tags":["flowable","cmmn","not-found","variables"],"backgroundTag":"entity-not-found","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"}