{"record":{"id":"3feedcdb38a09340","repo":"flowable/flowable-engine","slug":"cannot-coerce-property-to-array-index","errorCode":null,"errorMessage":"Cannot coerce property to array index: ","messagePattern":"Cannot coerce property to array index: ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/JsonNodeELResolver.java","lineNumber":370,"sourceCode":"        } else {\n            node.setNull(index);\n        }\n\n        context.setPropertyResolved(true);\n    }\n\n    protected int toIndex(Object property) {\n        int index;\n        if (property instanceof Number) {\n            index = ((Number) property).intValue();\n        } else if (property instanceof String) {\n            try {\n                index = Integer.valueOf((String) property);\n            } catch (NumberFormatException e) {\n                throw new IllegalArgumentException(\"Cannot parse array index: \" + property, e);\n            }\n        } else {\n            throw new IllegalArgumentException(\"Cannot coerce property to array index: \" + property);\n        }\n\n        return index;\n    }\n\n    /**\n     * Test whether the given base should be resolved by this ELResolver.\n     * \n     * @param base\n     *            The bean to analyze.\n     * @return base != null\n     */\n    private final boolean isResolvable(Object base) {\n        return JsonUtil.isJsonNode(base);\n    }\n}\n","sourceCodeStart":352,"sourceCodeEnd":387,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/el/JsonNodeELResolver.java#L352-L387","documentation":"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.","triggerScenarios":"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]}.","commonSituations":"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.","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"],"exampleFix":"// before\n${jsonArray[flag]}  // flag is Boolean\n// after\n${jsonArray[indexVar]}  // indexVar is Integer","handlingStrategy":"type-guard","validationCode":"if (!(prop instanceof Number) && !(prop instanceof String)) { throw new IllegalArgumentException(\"Array index must be Number or numeric String\"); }","typeGuard":"boolean isIndexable(Object p) { return p instanceof Number || (p instanceof String s && !s.isEmpty() && s.chars().allMatch(Character::isDigit)); }","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["java","el","array-index","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}