flowable/flowable-engine · error · IllegalArgumentException
Cannot coerce property to array index:
Error message
Cannot coerce property to array index:
What it means
JsonNodeELResolver.toIndex throws IllegalArgumentException('Cannot coerce property to array index: ' + property) when the property object is neither a Number nor a String, so it cannot be interpreted as a JSON array index. Only numeric types and numeric strings are valid array indices here.
Solutions
- Convert the property to a Number or numeric String before array access
- Check the expression so the value inside [] is the intended integer variable, not an object/boolean
- Cast or transform the variable (e.g. .intValue(), toString of a number) prior to indexing
Example fix
// before
${jsonArray[flag]} // flag is Boolean
// after
${jsonArray[indexVar]} // indexVar is Integer Defensive patterns
Strategy: type-guard
Validate before calling
if (!(prop instanceof Number) && !(prop instanceof String)) { throw new IllegalArgumentException("Array index must be Number or numeric String"); } Type guard
boolean isIndexable(Object p) { return p instanceof Number || (p instanceof String s && !s.isEmpty() && s.chars().allMatch(Character::isDigit)); } Try / catch
try { expr.getValue(ctx); } catch (FlowableException e) { if (e.getCause() instanceof IllegalArgumentException iae && iae.getMessage().startsWith("Cannot coerce")) { throw new IllegalArgumentException("Array index must be numeric", iae); } throw e; } Prevention
- Never pass booleans, objects, or JSON nodes as array indexes
- Coerce/convert variables to Integer before using them as indexes
- Review bracket expressions to confirm the inner value is the intended numeric variable
When it happens
Trigger: Indexing a JSON array with a non-numeric, non-string object such as a Boolean, Map, or JsonNode, e.g. ${jsonArray[true]} or ${jsonArray[someObject]}.
Common situations: Accidentally passing a nested JSON node or POJO as the index; using a boolean flag variable as an index; template generation that interpolates the wrong variable into the brackets.
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 parse array index:
- Cannot coerce property to array index:
- Cannot convert value of type
- Could not set field
- Could not set field
AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11).
Data as JSON: /api/errors/3feedcdb38a09340.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/JsonNodeELResolver.java:370
} else {
node.setNull(index);
}
context.setPropertyResolved(true);
}
protected int toIndex(Object property) {
int index;
if (property instanceof Number) {
index = ((Number) property).intValue();
} else if (property instanceof String) {
try {
index = Integer.valueOf((String) property);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Cannot parse array index: " + property, e);
}
} else {
throw new IllegalArgumentException("Cannot coerce property to array index: " + property);
}
return index;
}
/**
* Test whether the given base should be resolved by this ELResolver.
*
* @param base
* The bean to analyze.
* @return base != null
*/
private final boolean isResolvable(Object base) {
return JsonUtil.isJsonNode(base);
}
}
View on GitHub (pinned to d6d39ce1c6)