flowable/flowable-engine · error · FlowableException

Cannot set tenant context to null

Error message

Cannot set tenant context to null

What it means

CurrentTenant.setTenantContext throws FlowableException if the given TenantContext is null. The engine holds a static TenantContext used for tenant resolution; replacing it with null would break every subsequent tenant lookup, so it is disallowed.

Solutions

  1. Construct or obtain a valid TenantContext implementation before setting it
  2. Check why the provider returned null (missing bean/config) and fix initialization order
  3. Use getTenantContext to keep the existing context if you intended no change

Example fix

// before
currentTenant.setTenantContext(resolveTenantContext());
// after
TenantContext ctx = resolveTenantContext();
if (ctx != null) {
    currentTenant.setTenantContext(ctx);
}
Defensive patterns

Strategy: type-guard

Validate before calling

TenantContext ctx = tenantContextProvider.get();
if (ctx == null) {
    throw new IllegalStateException("TenantContext provider returned null; check engine configuration");
}
CurrentTenant.setTenantContext(ctx);

Type guard

boolean isValidTenantContext(TenantContext ctx) {
    return ctx != null;
}

Try / catch

try {
    CurrentTenant.setTenantContext(ctx);
} catch (FlowableException e) {
    logger.error("TenantContext setup failed: {}", e.getMessage());
}

Prevention

When it happens

Trigger: Calling CurrentTenant.setTenantContext(null), typically during engine shutdown/customization, or a factory method returning null that is passed directly into the setter.

Common situations: Spring/config bean for TenantContext not yet initialized (null injected); custom TenantContext factory returning null on misconfiguration.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/4d8f2acc2dd80f50. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/tenant/CurrentTenant.java:31

package org.flowable.common.engine.impl.tenant;

import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.tenant.TenantContext;

/**
 * @author Filip Hrisafov
 */
public abstract class CurrentTenant {

    private static TenantContext tenantContext = new ThreadLocalTenantContext();

    public static TenantContext getTenantContext() {
        return tenantContext;
    }

    public static void setTenantContext(TenantContext tenantContext) {
        if (tenantContext == null) {
            throw new FlowableException("Cannot set tenant context to null");
        }
        CurrentTenant.tenantContext = tenantContext;
    }

}

View on GitHub (pinned to d6d39ce1c6)