{"record":{"id":"e34957a47ad05b92","repo":"flowable/flowable-engine","slug":"processinstanceid-is-null-e34957","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/DeleteHistoricProcessInstanceCmd.java","lineNumber":44,"sourceCode":"import org.flowable.engine.impl.util.CommandContextUtil;\nimport org.flowable.engine.impl.util.Flowable5Util;\n\n/**\n * @author Frederik Heremans\n */\npublic class DeleteHistoricProcessInstanceCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String processInstanceId;\n\n    public DeleteHistoricProcessInstanceCmd(String processInstanceId) {\n        this.processInstanceId = processInstanceId;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (processInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"processInstanceId is null\");\n        }\n        // Check if process instance is still running\n        HistoricProcessInstanceEntity instance = CommandContextUtil.getHistoricProcessInstanceEntityManager(commandContext).findById(processInstanceId);\n\n        if (instance == null) {\n            throw new FlowableObjectNotFoundException(\"No historic process instance found with id: \" + processInstanceId, HistoricProcessInstance.class);\n        }\n        if (instance.isDeleted()) {\n            return null;\n        }\n        if (instance.getEndTime() == null) {\n            throw new FlowableException(\"Process instance is still running, cannot delete \" + instance);\n        }\n\n        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, instance.getProcessDefinitionId())) {\n            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();\n            compatibilityHandler.deleteHistoricProcessInstance(processInstanceId);\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/DeleteHistoricProcessInstanceCmd.java#L26-L62","documentation":"DeleteHistoricProcessInstanceCmd.validate that the processInstanceId given to the command is not null before doing anything. The Flowable engine throws FlowableIllegalArgumentException when a caller invokes deletion of a historic process instance without supplying an id. This is an argument contract check, not a data lookup problem.","triggerScenarios":"Calling runtimeDataService/historyService APIs that end up executing DeleteHistoricProcessInstanceCmd with a null id, e.g. historyService.deleteHistoricProcessInstance(null), or passing a variable that was never assigned the process instance id.","commonSituations":"Developers storing the process instance id in a variable that failed to initialize, wiring the wrong variable into a delete call, or calling delete after a start call returned an object they did not keep the id from.","solutions":["Pass a non-null, valid historic process instance id to deleteHistoricProcessInstance","Verify the variable holding the id is populated before invoking the delete command","Fetch the id from the HistoricProcessInstanceQuery result instead of a stale reference"],"exampleFix":"// before\nhistoryService.deleteHistoricProcessInstance(processInstanceId); // processInstanceId was null\n// after\nif (processInstanceId != null) {\n    historyService.deleteHistoricProcessInstance(processInstanceId);\n}","handlingStrategy":"validation","validationCode":"if (processInstanceId == null || processInstanceId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"processInstanceId must be provided before deletion\");\n}","typeGuard":"boolean hasProcessInstanceId = id -> id != null && !id.trim().isEmpty();","tryCatchPattern":"try {\n    historyService.deleteHistoricProcessInstance(id);\n} catch (FlowableIllegalArgumentException e) {\n    logger.warn(\"Null id passed to deleteHistoricProcessInstance\", e);\n}","preventionTips":["Always capture the id returned when the process instance starts","Null-check ids before invoking history APIs","Keep process instance ids in typed holders, not raw Object fields"],"tags":["flowable","null-argument","history","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-14T11:17:12.474Z"}