{"record":{"id":"42c0cfd9cdf855df","repo":"flowable/flowable-engine","slug":"process-instance-tenant-id-is-null-42c0cf","errorCode":null,"errorMessage":"process instance tenant id is null","messagePattern":"process instance tenant id is null","errorType":"exception","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/ProcessInstanceQueryImpl.java","lineNumber":156,"sourceCode":"\n    @Override\n    public ProcessInstanceQuery processInstanceBusinessKey(String businessKey, String processDefinitionKey) {\n        if (businessKey == null) {\n            throw new ActivitiIllegalArgumentException(\"Business key is null\");\n        }\n        if (inOrStatement) {\n            throw new ActivitiIllegalArgumentException(\"This method is not supported in an OR statement\");\n        }\n\n        this.businessKey = businessKey;\n        this.processDefinitionKey = processDefinitionKey;\n        return this;\n    }\n\n    @Override\n    public ProcessInstanceQuery processInstanceTenantId(String tenantId) {\n        if (tenantId == null) {\n            throw new ActivitiIllegalArgumentException(\"process instance tenant id is null\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.tenantId = tenantId;\n        } else {\n            this.tenantId = tenantId;\n        }\n        return this;\n    }\n\n    @Override\n    public ProcessInstanceQuery processInstanceTenantIdLike(String tenantIdLike) {\n        if (tenantIdLike == null) {\n            throw new ActivitiIllegalArgumentException(\"process instance tenant id is null\");\n        }\n        if (inOrStatement) {\n            this.currentOrQueryObject.tenantIdLike = tenantIdLike;\n        } else {\n            this.tenantIdLike = tenantIdLike;","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/ProcessInstanceQueryImpl.java#L138-L174","documentation":"ProcessInstanceQueryImpl.processInstanceTenantId(String) throws ActivitiIllegalArgumentException when the tenantId argument is null. The Flowable/Activiti query API validates each filter method's arguments eagerly so that a malformed query fails at construction time rather than producing an unclear SQL error at query execution. A null tenant id is not a legal filter value; to query tenant-less instances there are separate dedicated methods (e.g. processInstanceWithoutTenantId).","triggerScenarios":"Calling runtimeService.createProcessInstanceQuery().processInstanceTenantId(null) — usually because the tenant id was read from a variable, config, or request parameter that was null/missing.","commonSituations":"Multi-tenant apps where the tenant is derived from a header, JWT claim, or user record that is absent; passing an Optional/nullable value without unwrapping; refactors that renamed a config key so the lookup now returns null.","solutions":["Ensure a non-null tenant id is resolved before building the query; fail fast with your own clear error if it is missing.","If you actually want instances with no tenant, call processInstanceWithoutTenantId() instead of passing null.","Add a null/empty guard on the source of the tenant id (request header, claim, config) before invoking the query.","Wrap query building in ActivitiIllegalArgumentException handling to convert it into an application-level validation error."],"exampleFix":"// before\nString tenantId = config.get(\"tenant\");\nProcessInstanceQuery q = runtimeService.createProcessInstanceQuery()\n    .processInstanceTenantId(tenantId);\n// after\nString tenantId = config.get(\"tenant\");\nif (tenantId == null) throw new IllegalStateException(\"tenant id not configured\");\nProcessInstanceQuery q = runtimeService.createProcessInstanceQuery()\n    .processInstanceTenantId(tenantId);","handlingStrategy":"validation","validationCode":"if (tenantId == null) {\n    throw new IllegalStateException(\"tenantId must be provided before querying process instances\");\n}","typeGuard":"boolean hasTenantId(String tenantId) { return tenantId != null && !tenantId.isEmpty(); }","tryCatchPattern":"try {\n    runtimeService.createProcessInstanceQuery().processInstanceTenantId(tenantId).list();\n} catch (ActivitiIllegalArgumentException e) {\n    if (e.getMessage().contains(\"tenant id is null\")) {\n        throw new BadRequestException(\"tenantId is required\");\n    }\n    throw e;\n}","preventionTips":["Resolve the tenant id once at request scope and assert non-null before any query building.","Use processInstanceWithoutTenantId() for tenant-less data instead of null.","Apply filters via conditional builders so unset values are skipped.","Log the source of the null tenant id (header, claim, config) to catch config regressions early."],"tags":["java","activiti","flowable","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"}