flowable/flowable-engine · error · FlowableIllegalArgumentException

query is null

Error message

query is null

What it means

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.

Solutions

  1. Always construct the query before calling: historyService.createHistoricActivityInstanceQuery() ... (then pass the query object).
  2. Add a null check or Objects.requireNonNull on the query parameter in your calling code.
  3. Fix the upstream method that returns null instead of a query instance.

Example fix

// before
historyService.deleteHistoricActivityInstances(query);
// after
HistoricActivityInstanceQuery query = historyService.createHistoricActivityInstanceQuery()
    .processInstanceId(processInstanceId).finishedBefore(cutoff);
historyService.deleteHistoricActivityInstances(query);
Defensive patterns

Strategy: validation

Validate before calling

Objects.requireNonNull(query, "historicActivityInstanceQuery must not be null");
historyService.deleteHistoricActivityInstances(query);

Try / catch

try {
    historyService.deleteHistoricActivityInstances(query);
} catch (FlowableIllegalArgumentException e) {
    log.error("Query was null; build it via historyService.createHistoricActivityInstanceQuery()", e);
}

Prevention

When it happens

Trigger: 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.

Common situations: Utility/helper method returning null on some code path; DI field not injected before use; refactoring that replaced query construction with a nullable variable.

Related errors


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

Appendix: source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteHistoricActivityInstancesCmd.java:36

import org.flowable.common.engine.api.FlowableIllegalArgumentException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.impl.HistoricActivityInstanceQueryImpl;
import org.flowable.engine.impl.util.CommandContextUtil;

public class DeleteHistoricActivityInstancesCmd implements Command<Object>, Serializable {

    private static final long serialVersionUID = 1L;
    protected HistoricActivityInstanceQueryImpl historicActivityInstanceQuery;

    public DeleteHistoricActivityInstancesCmd(HistoricActivityInstanceQueryImpl historicActivityInstanceQuery) {
        this.historicActivityInstanceQuery = historicActivityInstanceQuery;
    }

    @Override
    public Object execute(CommandContext commandContext) {
        if (historicActivityInstanceQuery == null) {
            throw new FlowableIllegalArgumentException("query is null");
        }
        
        CommandContextUtil.getHistoricActivityInstanceEntityManager(commandContext).deleteHistoricActivityInstances(historicActivityInstanceQuery);

        return null;
    }

}

View on GitHub (pinned to d6d39ce1c6)