{"record":{"id":"45682555a5f54dd4","repo":"flowable/flowable-engine","slug":"cannot-find-plan-item-instance-with-id","errorCode":null,"errorMessage":"Cannot find plan item instance with id ","messagePattern":"Cannot find plan item instance with id ","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetIdentityLinksForPlanItemInstanceCmd.java","lineNumber":48,"sourceCode":" */\npublic class GetIdentityLinksForPlanItemInstanceCmd implements Command<List<IdentityLink>>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n\n    protected String planItemInstanceId;\n\n    public GetIdentityLinksForPlanItemInstanceCmd(String planItemInstanceId) {\n        this.planItemInstanceId = planItemInstanceId;\n    }\n\n    @SuppressWarnings({ \"unchecked\", \"rawtypes\" })\n    @Override\n    public List<IdentityLink> execute(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        PlanItemInstance planItemInstance = cmmnEngineConfiguration.getPlanItemInstanceEntityManager().findById(planItemInstanceId);\n\n        if (planItemInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find plan item instance with id \" + planItemInstanceId, PlanItemInstanceEntity.class);\n        }\n\n        return (List) cmmnEngineConfiguration.getIdentityLinkServiceConfiguration().getIdentityLinkService()\n                .findIdentityLinksBySubScopeIdAndType(planItemInstanceId, ScopeTypes.PLAN_ITEM);\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/GetIdentityLinksForPlanItemInstanceCmd.java#L30-L56","documentation":"Thrown by GetIdentityLinksForPlanItemInstanceCmd when no PlanItemInstance exists with the given id. The command fetches the plan item via PlanItemInstanceEntityManager.findById and throws FlowableObjectNotFoundException when null. Plan item instances disappear when their parent case completes or the plan item is terminated/completed.","triggerScenarios":"Calling identity-link APIs for a plan item whose parent case already ended, using a stale plan item id captured before the case moved on, or passing a case instance id / stage id where a plan item instance id is expected.","commonSituations":"Async clients caching plan item ids too long; querying after a terminate/delete of the case; copying the wrong id from logs or the ACT_/FLW_ tables; unit tests reusing ids across runs.","solutions":["Re-query the plan item first: cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id).count() > 0.","Refresh the id from the live case (createPlanItemInstanceQuery().caseInstanceId(caseId).list()).","If the case ended, switch to history queries (cmmnHistoryService) for the plan item data.","Validate id type/length at input boundaries to catch misuse of foreign keys."],"exampleFix":"// before\nList<IdentityLink> links = cmmnRuntimeService.getIdentityLinksForPlanItemInstance(planItemId);\n// after\nPlanItemInstance pii = cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemId).singleResult();\nif (pii == null) { throw new IllegalStateException(\"Plan item gone: \" + planItemId); }\nList<IdentityLink> links = cmmnRuntimeService.getIdentityLinksForPlanItemInstance(planItemId);","handlingStrategy":"validation","validationCode":"if (cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(planItemInstanceId).count() == 0) {\n    throw new IllegalArgumentException(\"Unknown plan item instance id: \" + planItemInstanceId);\n}","typeGuard":"boolean planItemInstanceAlive(String id) {\n    return cmmnRuntimeService.createPlanItemInstanceQuery().planItemInstanceId(id).count() > 0;\n}","tryCatchPattern":"try {\n    links = cmmnRuntimeService.getIdentityLinksForPlanItemInstance(planItemInstanceId);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Plan item {} no longer exists\", planItemInstanceId);\n    links = Collections.emptyList();\n}","preventionTips":["Re-fetch plan item ids from the live case before use","Expect ids to vanish on case completion/termination","Use history APIs for past plan items","Validate id source/type at boundaries"],"tags":["flowable","cmmn","not-found","plan-item"],"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-14T11:17:12.474Z"}