{"record":{"id":"1c23a9c51f9850b8","repo":"flowable/flowable-engine","slug":"query-is-null-1c23a9","errorCode":null,"errorMessage":"query is null","messagePattern":"query is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/delete/DeleteHistoricCaseInstancesUsingBatchesCmd.java","lineNumber":64,"sourceCode":" */\npublic class DeleteHistoricCaseInstancesUsingBatchesCmd implements Command<String> {\n\n    protected HistoricCaseInstanceQueryImpl historicCaseInstanceQuery;\n    protected int batchSize;\n    protected boolean sequential;\n    protected String batchName;\n\n    public DeleteHistoricCaseInstancesUsingBatchesCmd(HistoricCaseInstanceQueryImpl query, int batchSize, String batchName, boolean sequential) {\n        this.historicCaseInstanceQuery = 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 (historicCaseInstanceQuery == 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        CmmnEngineConfiguration engineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        BatchService batchService = engineConfiguration.getBatchServiceConfiguration()\n                .getBatchService();\n\n        long numberOfCaseInstancesToDelete = historicCaseInstanceQuery.count();\n\n        ObjectNode batchConfiguration = engineConfiguration.getObjectMapper().createObjectNode();\n        batchConfiguration.put(\"numberOfInstances\", numberOfCaseInstancesToDelete);\n        batchConfiguration.put(\"batchSize\", batchSize);\n        if (sequential) {\n            batchConfiguration.put(\"sequential\", true);\n        }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/delete/DeleteHistoricCaseInstancesUsingBatchesCmd.java#L46-L82","documentation":"Thrown by DeleteHistoricCaseInstancesUsingBatchesCmd.execute() when the HistoricCaseInstanceQuery passed to the command is null. The command needs a query to slice case instance ids into batches for deletion; without it no work can be planned.","triggerScenarios":"Calling the command (or the management-service method wrapping it) with historicCaseInstanceQuery == null, typically by passing an uninitialized variable or skipping query construction.","commonSituations":"Refactoring that left the query unassigned; conditional code paths where the query build step is skipped; API misuse assuming the command builds its own query.","solutions":["Construct a query first: historyService.createHistoricCaseInstanceQuery() (add filters as needed) and pass it to the command/management method","Add a null check on the query before invoking the command","Ensure the code path building the query always executes before the delete call"],"exampleFix":"// before\nHistoricCaseInstanceQuery query = null;\nmanagementService.bulkDeleteHistoricCaseInstances(query, 10, true);\n// after\nHistoricCaseInstanceQuery query = historyService.createHistoricCaseInstanceQuery().finished();\nmanagementService.bulkDeleteHistoricCaseInstances(query, 10, true);","handlingStrategy":"type-guard","validationCode":"if (historicCaseInstanceQuery == null) {\n    historicCaseInstanceQuery = historyService.createHistoricCaseInstanceQuery();\n}\nmanagementService.bulkDeleteHistoricCaseInstances(historicCaseInstanceQuery, batchSize, sequential);","typeGuard":"boolean isUsableQuery(HistoricCaseInstanceQuery q) { return q != null; }","tryCatchPattern":"try { cmd.execute(commandContext); } catch (FlowableIllegalArgumentException e) { if (e.getMessage().equals(\"query is null\")) { log.error(\"Pass a created HistoricCaseInstanceQuery\", e); } throw e; }","preventionTips":["Always create the query via historyService.createHistoricCaseInstanceQuery() immediately before the delete call","Also validate batchSize > 0 in the same guard","Avoid optional/unassigned query variables across code paths"],"tags":["flowable","cmmn","null-argument","query","validation"],"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"}