flowable/flowable-engine · error · FlowableException
Cannot aggregate variable: ${varInstance}
Error message
Cannot aggregate variable: ${varInstance} What it means
In the same aggregator, when the aggregation context is not OVERVIEW, each collected instance value must still be a JSON node; if not, Flowable throws "Cannot aggregate variable: " + varInstance. The overview and non-overview branches are complementary: whichever context state applies, the value must be JSON-representable as a node.
Source
Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/delegate/JsonPlanItemVariableAggregator.java:162
case JodaDateTimeType.TYPE_NAME:
case UUIDType.TYPE_NAME:
// For all these types it is OK to use toString as their string representation is what we want to have
objectNode.put(targetVarName, varInstance.getValue().toString());
break;
case ByteArrayType.TYPE_NAME:
objectNode.put(targetVarName, (byte[]) varInstance.getValue());
break;
default:
if (PlanItemVariableAggregatorContext.OVERVIEW.equals(context.getState())) {
// We can only use the aggregated variable if we are in an overview state
Object value = varInstance.getValue();
if (jsonMapper.isJsonNode(value)) {
objectNode.set(targetVarName, JsonUtil.asFlowableJsonNode(value));
} else {
throw new FlowableException("Cannot aggregate overview variable: " + varInstance);
}
} else {
throw new FlowableException("Cannot aggregate variable: " + varInstance);
}
}
}
}
}
return objectNode.getImplementationValue();
}
@Override
public Object aggregateMultiVariables(DelegatePlanItemInstance planItemInstance, List<? extends VariableInstance> instances,
PlanItemVariableAggregatorContext context) {
VariableJsonMapper objectMapper = cmmnEngineConfiguration.getVariableJsonMapper();
FlowableArrayNode arrayNode = objectMapper.createArrayNode();
for (VariableInstance instance : instances) {
arrayNode.add(JsonUtil.asFlowableJsonNode(instance.getValue()));
}View on GitHub (pinned to d6d39ce1c6)
Solutions
- Store JSON node values for all variables included in repetition aggregation.
- In the producing delegate/listener, wrap values with JsonUtil/JsonMapper before setVariable.
- Exclude non-JSON variables from the aggregation configuration's variable list.
- Migrate/normalize existing case variables to JSON for in-flight cases.
Example fix
// before
execution.setVariable("score", 42);
// after
ObjectNode node = JsonUtil.createObjectNode();
node.put("score", 42);
execution.setVariable("scoreData", node); Defensive patterns
Strategy: validation
Validate before calling
Object value = varInstance.getValue();
if (!(value instanceof com.fasterxml.jackson.databind.JsonNode)) {
throw new IllegalArgumentException("Aggregated variable must hold a JSON node, got: " + value.getClass());
} Type guard
boolean canAggregate(VariableInstance v) {
return v.getValue() instanceof com.fasterxml.jackson.databind.JsonNode;
} Try / catch
try {
Object result = aggregator.aggregateSingleVariable(planItemInstance, context);
} catch (org.flowable.common.engine.api.FlowableException e) {
if (e.getMessage().startsWith("Cannot aggregate variable")) { log.error("Non-JSON value collected: {}", e.getMessage()); }
throw e;
} Prevention
- Enforce JSON typing for all repetition-collected variables via a shared variable-setting utility.
- Audit scripts/delegates that set aggregation source variables for non-JSON writes.
- Cover aggregation paths with integration tests using realistic variable values.
When it happens
Trigger: Repetition aggregation in a non-overview state (e.g. aggregating completed plan item variables into a result list) encounters an instance variable whose value is not a JSON node (plain String, Integer, POJO, byte[]).
Common situations: Delegates or scripts storing primitive/POJO values into variables that the aggregation configuration then collects; mixed variable types across repetitions; upgrading and changing what a delegate stores without migrating existing case variables.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot aggregate overview variable: ${varInstance}
- ${className} does not implement the ${CmmnTriggerableActivit
- ${className} does not implement the ${CmmnActivityBehavior.c
- ${delegateInstance.getClass().getName()} doesn't implement $
- ${delegateInstance.getClass().getName()} doesn't implement $
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/05e6541ad425bca4.
Report an issue: GitHub.