{"record":{"id":"e79b394137bf035e","repo":"flowable/flowable-engine","slug":"query-is-null-e79b39","errorCode":null,"errorMessage":"query is null","messagePattern":"query is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricActivityInstancesCmd.java","lineNumber":36,"sourceCode":"import org.flowable.common.engine.api.FlowableIllegalArgumentException;\nimport org.flowable.common.engine.impl.interceptor.Command;\nimport org.flowable.common.engine.impl.interceptor.CommandContext;\nimport org.flowable.engine.impl.HistoricActivityInstanceQueryImpl;\nimport org.flowable.engine.impl.util.CommandContextUtil;\n\npublic class DeleteHistoricActivityInstancesCmd implements Command<Object>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected HistoricActivityInstanceQueryImpl historicActivityInstanceQuery;\n\n    public DeleteHistoricActivityInstancesCmd(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {\n        this.historicActivityInstanceQuery = historicActivityInstanceQuery;\n    }\n\n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (historicActivityInstanceQuery == null) {\n            throw new FlowableIllegalArgumentException(\"query is null\");\n        }\n        \n        CommandContextUtil.getHistoricActivityInstanceEntityManager(commandContext).deleteHistoricActivityInstances(historicActivityInstanceQuery);\n\n        return null;\n    }\n\n}\n","sourceCodeStart":18,"sourceCodeEnd":45,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricActivityInstancesCmd.java#L18-L45","documentation":"DeleteHistoricActivityInstancesCmd bulk-deletes historic activity instances matching a supplied query object. If the query reference is null there is nothing to execute and FlowableIllegalArgumentException is thrown. The library requires an actual (typically uninitialized-style is fine but non-null) HistoricActivityInstanceQuery instance.","triggerScenarios":"Calling HistoryService.deleteHistoricActivityInstances(query) with query == null — often the result of a method that was supposed to build the query but returned null, or a field never initialized.","commonSituations":"Utility/helper method returning null on some code path; DI field not injected before use; refactoring that replaced query construction with a nullable variable.","solutions":["Always construct the query before calling: historyService.createHistoricActivityInstanceQuery() ... (then pass the query object).","Add a null check or Objects.requireNonNull on the query parameter in your calling code.","Fix the upstream method that returns null instead of a query instance."],"exampleFix":"// before\nhistoryService.deleteHistoricActivityInstances(query);\n// after\nHistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery()\n    .processInstanceId(processInstanceId).finishedBefore(cutoff);\nhistoryService.deleteHistoricActivityInstances(query);","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(query, \"historicActivityInstanceQuery must not be null\");\nhistoryService.deleteHistoricActivityInstances(query);","typeGuard":null,"tryCatchPattern":"try {\n    historyService.deleteHistoricActivityInstances(query);\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Query was null; build it via historyService.createHistoricActivityInstanceQuery()\", e);\n}","preventionTips":["Always build queries with historyService.createHistoricActivityInstanceQuery() immediately before use","Never let helper methods return null query objects; return an empty-filtered query instead","Validate non-null method parameters in your service layer"],"tags":["flowable","history","null-argument"],"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"}