{"record":{"id":"6c161f00736821f9","repo":"flowable/flowable-engine","slug":"processinstanceid-is-null-6c161f","errorCode":null,"errorMessage":"processInstanceId is null","messagePattern":"processInstanceId is null","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java","lineNumber":40,"sourceCode":"import org.activiti.engine.impl.interceptor.Command;\nimport org.activiti.engine.impl.interceptor.CommandContext;\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 ActivitiIllegalArgumentException(\"processInstanceId is null\");\n        }\n        // Check if process instance is still running\n        HistoricProcessInstance instance = commandContext\n                .getHistoricProcessInstanceEntityManager()\n                .findHistoricProcessInstance(processInstanceId);\n\n        if (instance == null) {\n            throw new ActivitiObjectNotFoundException(\"No historic process instance found with id: \" + processInstanceId, HistoricProcessInstance.class);\n        }\n        if (instance.getEndTime() == null) {\n            throw new ActivitiException(\"Process instance is still running, cannot delete historic process instance: \" + processInstanceId);\n        }\n\n        commandContext\n                .getHistoricProcessInstanceEntityManager()\n                .deleteHistoricProcessInstanceById(processInstanceId);\n\n        return null;","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/DeleteHistoricProcessInstanceCmd.java#L22-L58","documentation":"DeleteHistoricProcessInstanceCmd deletes a historic process instance by id and first checks that the id is non-null, throwing ActivitiIllegalArgumentException otherwise. Historic cleanup requires an explicit instance id.","triggerScenarios":"historyService.deleteHistoricProcessInstance(processInstanceId) with null id — e.g. an uninitialized variable, an API caller omitting the id, or a batch cleaner iterating records where the id field is null.","commonSituations":"Retention/cleanup jobs reading ids from a report where some rows have null ids; REST handlers missing a body field; wrong getter returning the wrong column.","solutions":["Pass a valid non-null processInstanceId","Filter out null ids in cleanup loops before invoking","Validate the id in the calling layer (REST param / DTO)"],"exampleFix":"// before\nhistoryService.deleteHistoricProcessInstance(instanceId);\n// after\nif (instanceId != null) {\n    historyService.deleteHistoricProcessInstance(instanceId);\n}","handlingStrategy":"validation","validationCode":"if (processInstanceId == null || processInstanceId.isEmpty()) return; // or throw\nboolean exists = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).count() > 0;","typeGuard":"boolean hasInstanceId(String id) { return id != null && !id.trim().isEmpty(); }","tryCatchPattern":"try { historyService.deleteHistoricProcessInstance(id); } catch (ActivitiIllegalArgumentException e) { log.warn(\"Skipping historic delete: {}\", e.getMessage()); }","preventionTips":["Skip null ids in cleanup jobs","Validate DTO/request fields before invoking history commands","Check historic existence before delete to distinguish null vs not-found"],"tags":["validation","null-argument","history"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}