{"record":{"id":"ed6a8fc1e2c925f9","repo":"flowable/flowable-engine","slug":"query-is-null-ed6a8f","errorCode":null,"errorMessage":"query is null","messagePattern":"query is null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/delete/DeleteHistoricProcessInstancesUsingBatchesCmd.java","lineNumber":63,"sourceCode":" */\npublic class DeleteHistoricProcessInstancesUsingBatchesCmd implements Command<String> {\n\n    protected HistoricProcessInstanceQueryImpl historicProcessInstanceQuery;\n    protected int batchSize;\n    protected boolean sequential;\n    protected String batchName;\n\n    public DeleteHistoricProcessInstancesUsingBatchesCmd(HistoricProcessInstanceQueryImpl query, int batchSize, String batchName, boolean sequential) {\n        this.historicProcessInstanceQuery = query;\n        this.batchSize = batchSize;\n        this.batchName = batchName;\n        this.sequential = sequential;\n    }\n\n    @Override\n    public String execute(CommandContext commandContext) {\n        if (historicProcessInstanceQuery == null) {\n            throw new FlowableIllegalArgumentException(\"query is null\");\n        }\n\n        if (batchSize <= 0) {\n            throw new FlowableIllegalArgumentException(\"batchSize has to be larger than 0\");\n        }\n\n        ProcessEngineConfigurationImpl engineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);\n        BatchService batchService = engineConfiguration.getBatchServiceConfiguration()\n                .getBatchService();\n\n        long numberOfProcessInstancesToDelete = historicProcessInstanceQuery.count();\n\n        ObjectNode batchConfiguration = engineConfiguration.getObjectMapper().createObjectNode();\n        batchConfiguration.put(\"numberOfInstances\", numberOfProcessInstancesToDelete);\n        batchConfiguration.put(\"batchSize\", batchSize);\n        if (sequential) {\n            batchConfiguration.put(\"sequential\", true);\n        }","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/delete/DeleteHistoricProcessInstancesUsingBatchesCmd.java#L45-L81","documentation":"DeleteHistoricProcessInstancesUsingBatchesCmd.execute validates its inputs before creating the batch. If the historicProcessInstanceQuery field is null it throws FlowableIllegalArgumentException('query is null'). The command cannot select which historic process instances to delete without a query, so null is rejected up front.","triggerScenarios":"Executing DeleteHistoricProcessInstancesUsingBatchesCmd constructed without calling setHistoricProcessInstanceQuery (or with an explicit null HistoricProcessInstanceQuery) — DeleteHistoricProcessInstancesUsingBatchesCmd.java:63.","commonSituations":"Programmatic use of the command (e.g. via managementService command executor) forgetting to set the query; builder-style wiring where the query assignment is skipped on a code path; refactoring that removed the query initialization.","solutions":["Set a non-null HistoricProcessInstanceQuery on the command before executing it (setHistoricProcessInstanceQuery).","Create the query via historyService.createHistoricProcessInstanceQuery() and configure its filter.","Validate command fields before submitting it to the command executor."],"exampleFix":"// before\nDeleteHistoricProcessInstancesUsingBatchesCmd cmd = new DeleteHistoricProcessInstancesUsingBatchesCmd();\ncmd.setBatchSize(10);\n// after\nDeleteHistoricProcessInstancesUsingBatchesCmd cmd = new DeleteHistoricProcessInstancesUsingBatchesCmd();\ncmd.setHistoricProcessInstanceQuery(historyService.createHistoricProcessInstanceQuery().finished());\ncmd.setBatchSize(10);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(query, \"historicProcessInstanceQuery must be set\");\ncmd.setHistoricProcessInstanceQuery(query);\ncmd.execute(commandContext);","typeGuard":null,"tryCatchPattern":"try {\n    managementService.executeCommand(new DeleteHistoricProcessInstancesUsingBatchesCmd(query, batchSize, sequential));\n} catch (FlowableIllegalArgumentException e) {\n    if (\"query is null\".equals(e.getMessage())) {\n        // fix command construction and retry once\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always call setHistoricProcessInstanceQuery immediately after constructing the command.","Add a unit test asserting the command throws when the query is missing."],"tags":["null-argument","command","validation","flowable"],"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"}