{"record":{"id":"c9ba7dd4303302d1","repo":"flowable/flowable-engine","slug":"no-plan-item-instance-found-for-id-c9ba7d","errorCode":null,"errorMessage":"No plan item instance found for id ","messagePattern":"No plan item instance found for id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/RemoveLocalVariablesCmd.java","lineNumber":48,"sourceCode":"    protected Collection<String> variableNames;\n    \n    public RemoveLocalVariablesCmd(String planItemInstanceId, Collection<String> variableNames) {\n        this.planItemInstanceId = planItemInstanceId;\n        this.variableNames = variableNames;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (planItemInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"planItemInstanceId is null\");\n        }\n        if (variableNames == null) {\n            throw new FlowableIllegalArgumentException(\"variableNames is null\");\n        }\n     \n        PlanItemInstanceEntity planItemInstanceEntity = CommandContextUtil.getPlanItemInstanceEntityManager(commandContext).findById(planItemInstanceId);\n        if (planItemInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No plan item instance found for id \" + planItemInstanceId, PlanItemInstanceEntity.class);\n        }\n        planItemInstanceEntity.removeVariables(variableNames);\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":30,"sourceCodeEnd":56,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/RemoveLocalVariablesCmd.java#L30-L56","documentation":"Flowable's RemoveLocalVariablesCmd removes local variables from a CMMN plan item instance. Before doing so it looks up the plan item instance by the given id; if no such entity exists in the database, it throws FlowableObjectNotFoundException so the caller knows the id does not reference an existing plan item instance.","triggerScenarios":"Calling RuntimeService/TaskService local variable removal (e.g. removeLocalVariables(planItemInstanceId, names)) with a planItemInstanceId that does not exist, was already deleted (case/completed plan item purged), or belongs to another engine database.","commonSituations":"Stale ids cached in application code after case instance completion; using a case instance id or plan item id interchangeably; querying the wrong CMMN database/schema in multi-datasource setups.","solutions":["Verify the plan item instance id exists before calling: PlanItemInstanceQuery q = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id); singleResult() != null","Use the correct id type — plan item instance ids come from PlanItemInstance.getId(), not CaseInstance.getId() or Task.getId()","Check you are connected to the same database/schema the case was created in","If the plan item may legitimately be gone, catch FlowableObjectNotFoundException and handle gracefully"],"exampleFix":"// before\ncmmnRuntimeService.removeLocalVariables(planItemInstanceId, names);\n// after\nif (cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).count() > 0) {\n    cmmnRuntimeService.removeLocalVariables(planItemInstanceId, names);\n} else {\n    logger.warn(\"Plan item instance {} not found, skipping variable removal\", planItemInstanceId);\n}","handlingStrategy":"validation","validationCode":"boolean exists = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).count() > 0;\nif (!exists) throw new IllegalArgumentException(\"Unknown planItemInstanceId: \" + planItemInstanceId);","typeGuard":null,"tryCatchPattern":"try { cmmnRuntimeService.removeLocalVariables(id, names); } catch (FlowableObjectNotFoundException e) { log.warn(\"Plan item instance {} not found\", id); }","preventionTips":["Always resolve plan item ids from a fresh PlanItemInstance query","Never reuse ids across case completions or database resets","Distinguish plan item instance ids from case/task ids"],"tags":["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"}