{"record":{"id":"40c41de48f0954a4","repo":"flowable/flowable-engine","slug":"query-is-null","errorCode":null,"errorMessage":"query is null","messagePattern":"query is null","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstancesCmd.java","lineNumber":41,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\n\n/**\n * @author Tijs Rademakers\n */\npublic class DeleteHistoricCaseInstancesCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    \n    protected HistoricCaseInstanceQueryImpl historicCaseInstanceQuery;\n\n    public DeleteHistoricCaseInstancesCmd(HistoricCaseInstanceQueryImpl historicCaseInstanceQuery) {\n        this.historicCaseInstanceQuery = historicCaseInstanceQuery;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (historicCaseInstanceQuery == null) {\n            throw new FlowableIllegalArgumentException(\"query is null\");\n        }\n        \n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        cmmnEngineConfiguration.getHistoricCaseInstanceEntityManager().deleteHistoricCaseInstances(historicCaseInstanceQuery);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":23,"sourceCodeEnd":51,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/DeleteHistoricCaseInstancesCmd.java#L23-L51","documentation":"DeleteHistoricCaseInstancesCmd performs a bulk delete driven by a HistoricCaseInstanceQuery. If the query object itself is null, it throws FlowableIllegalArgumentException(\"query is null\") before touching the database. This validates the query handle, not its results.","triggerScenarios":"Calling CmmnHistoryService.deleteHistoricCaseInstances(null) or passing a query variable that was never initialized (failed builder chain, null return from a factory method).","commonSituations":"A helper method returning null instead of a query on error; conditional construction where the else-branch forgets to build the query; reflection/config-driven query creation failing silently.","solutions":["Null-check the query before passing it to deleteHistoricCaseInstances","Always construct the query inline: historyService.createHistoricCaseInstanceQuery()...","Fix any helper that can return a null query"],"exampleFix":"// before\nhistoryService.deleteHistoricCaseInstances(query);\n// after\nHistoricCaseInstanceQuery query = historyService.createHistoricCaseInstanceQuery().finished();\nhistoryService.deleteHistoricCaseInstances(query);","handlingStrategy":"validation","validationCode":"if (query == null) { query = historyService.createHistoricCaseInstanceQuery().finished(); }\nhistoryService.deleteHistoricCaseInstances(query);","typeGuard":"HistoricCaseInstanceQuery orDefault(HistoricCaseInstanceQuery q, CmmnHistoryService hs) { return q != null ? q : hs.createHistoricCaseInstanceQuery(); }","tryCatchPattern":"try { historyService.deleteHistoricCaseInstances(query); }\ncatch (FlowableIllegalArgumentException e) { if (\"query is null\".equals(e.getMessage())) { throw new IllegalStateException(\"query must be built before bulk delete\", e); } throw e; }","preventionTips":["Build queries inline rather than through nullable factory methods","Ensure helpers never return null queries","Wrap query construction and delete in one method to avoid uninitialized handles"],"tags":["cmmn","history","null-argument","bulk-delete"],"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"}