{"record":{"id":"406bec37ebac7788","repo":"flowable/flowable-engine","slug":"processinstanceid-is-null-406bec","errorCode":null,"errorMessage":"processInstanceId is null","messagePattern":"processInstanceId is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteProcessInstanceCmd.java","lineNumber":44,"sourceCode":"\n/**\n * @author Joram Barrez\n */\npublic class DeleteProcessInstanceCmd implements Command<Void>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String processInstanceId;\n    protected String deleteReason;\n\n    public DeleteProcessInstanceCmd(String processInstanceId, String deleteReason) {\n        this.processInstanceId = processInstanceId;\n        this.deleteReason = deleteReason;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (processInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"processInstanceId is null\");\n        }\n\n        ExecutionEntity processInstanceEntity = CommandContextUtil.getExecutionEntityManager(commandContext).findById(processInstanceId);\n        if (processInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No process instance found for id '\" + processInstanceId + \"'\", ProcessInstance.class);\n        }\n        if (processInstanceEntity.isDeleted()) {\n            return null;\n        }\n\n        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstanceEntity.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.deleteProcessInstance(processInstanceId, deleteReason);\n        } else {\n            CommandContextUtil.getExecutionEntityManager(commandContext).deleteProcessInstance(processInstanceEntity.getProcessInstanceId(), deleteReason, false, true);\n        }\n\n        return null;","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteProcessInstanceCmd.java#L26-L62","documentation":"DeleteProcessInstanceCmd requires a non-null processInstanceId; it validates this before any database lookup and throws FlowableIllegalArgumentException. It is a fast-fail guard so callers do not hit a downstream NPE in findById.","triggerScenarios":"Calling runtimeService.deleteProcessInstance(null, reason), or passing a variable that was never assigned/resolved (e.g. from an unbound expression or method parameter).","commonSituations":"Dynamic code where the instance id comes from a request body or process variable that is missing; copy-paste code passing the wrong variable; bulk-delete helpers that forward null entries.","solutions":["Ensure the id variable is set before calling deleteProcessInstance.","Validate/fail early in your own code when the id is absent.","If ids come from user input, reject empty/null values at the API boundary.","Check you are passing the process instance id, not the execution id or business key."],"exampleFix":"// before\nruntimeService.deleteProcessInstance(processInstanceId, \"cancelled\");\n// after\nif (processInstanceId == null) {\n    throw new IllegalArgumentException(\"processInstanceId required\");\n}\nruntimeService.deleteProcessInstance(processInstanceId, \"cancelled\");","handlingStrategy":"validation","validationCode":"if (processInstanceId == null || processInstanceId.isBlank()) throw new IllegalArgumentException(\"processInstanceId required\");","typeGuard":null,"tryCatchPattern":"try { rs.deleteProcessInstance(id, reason); } catch (FlowableIllegalArgumentException e) { log.warn(\"Missing instance id\", e); }","preventionTips":["Validate ids at the API/service boundary","Avoid forwarding variables that may be null into engine commands","Distinguish processInstanceId from executionId/businessKey"],"tags":["workflow","null-argument","validation","process-instance"],"backgroundTag":"null-argument","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"}