{"record":{"id":"2d4760560b9b7055","repo":"flowable/flowable-engine","slug":"case-definition-id-is-null-2d4760","errorCode":null,"errorMessage":"Case definition id is null","messagePattern":"Case definition id is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/HistoricCaseInstanceQueryImpl.java","lineNumber":158,"sourceCode":"\n    public HistoricCaseInstanceQueryImpl(CommandExecutor commandExecutor, CmmnEngineConfiguration cmmnEngineConfiguration) {\n        super(commandExecutor, cmmnEngineConfiguration.getVariableServiceConfiguration());\n        this.cmmnEngineConfiguration = cmmnEngineConfiguration;\n    }\n\n    @Override\n    protected void ensureVariablesInitialized() {\n        super.ensureVariablesInitialized();\n\n        for (HistoricCaseInstanceQueryImpl orQueryObject : orQueryObjects) {\n            orQueryObject.ensureVariablesInitialized();\n        }\n    }\n\n    @Override\n    public HistoricCaseInstanceQueryImpl caseDefinitionId(String caseDefinitionId) {\n        if (caseDefinitionId == null) {\n            throw new FlowableIllegalArgumentException(\"Case definition id is null\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.caseDefinitionId = caseDefinitionId;\n        } else {\n            this.caseDefinitionId = caseDefinitionId;\n        }\n        return this;\n    }\n\n    @Override\n    public HistoricCaseInstanceQuery caseDefinitionIds(Set<String> caseDefinitionIds) {\n        if (caseDefinitionIds == null) {\n            throw new FlowableIllegalArgumentException(\"Case definition ids is null\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.caseDefinitionIds = caseDefinitionIds;\n        } else {\n            this.caseDefinitionIds = caseDefinitionIds;","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/history/HistoricCaseInstanceQueryImpl.java#L140-L176","documentation":"Flowable's HistoricCaseInstanceQueryImpl.caseDefinitionId() validates its argument before storing it. Passing null would produce a broken SQL query later, so the engine fails fast with FlowableIllegalArgumentException. The caller must supply a non-null case definition id string.","triggerScenarios":"Calling historicCaseInstanceQuery.caseDefinitionId(null), or passing a variable/expression that resolves to null (e.g. an unset request parameter or lookup result).","commonSituations":"REST/UI layers forwarding optional query filters straight into the query builder; variables read from maps/JSON where the key is absent; refactors that changed how the id is obtained and now return null.","solutions":["Ensure a non-null case definition id before calling caseDefinitionId, e.g. resolve it via the repository service","If the filter is optional, skip calling caseDefinitionId instead of passing null","Use caseDefinitionIds(Set) only with a non-null, non-empty set","Catch FlowableIllegalArgumentException to return a 400-style validation error to the caller"],"exampleFix":"// before\nquery.caseDefinitionId(request.getCaseDefinitionId()); // NPE-ish: may be null\n// after\nString id = request.getCaseDefinitionId();\nif (id != null) {\n    query.caseDefinitionId(id);\n}","handlingStrategy":"validation","validationCode":"if (caseDefinitionId == null) { throw new IllegalArgumentException(\"caseDefinitionId is required\"); }\nquery.caseDefinitionId(caseDefinitionId);","typeGuard":"boolean hasDefinitionId = (id instanceof String s) && !s.isEmpty();","tryCatchPattern":"try {\n    query.caseDefinitionId(id);\n} catch (FlowableIllegalArgumentException e) {\n    throw new BadRequestException(\"Invalid case definition id filter\", e);\n}","preventionTips":["Wrap optional filters in null/blank checks before applying them","Use Objects.requireNonNullElse to default instead of passing null","Centralize query building in a helper that skips null filters","Write unit tests covering absent filter fields"],"tags":["flowable","cmmn","null-check","query-api"],"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"}