{"record":{"id":"42cd7af5e7e95456","repo":"alibaba/spring-ai-alibaba","slug":"input-is-not-array","errorCode":null,"errorMessage":"input is not Array","messagePattern":"input is not Array","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/ListOperatorNode.java","lineNumber":104,"sourceCode":"\t\t\tObject inputObject = t.value(inputKey).orElse(null);\n\t\t\tList<T> inputList = switch (mode) {\n\t\t\t\tcase JSON_STR -> {\n\t\t\t\t\tif (!(inputObject instanceof String)) {\n\t\t\t\t\t\tthrow new RuntimeException(\"input is not String\");\n\t\t\t\t\t}\n\t\t\t\t\tString inputJsonString = inputObject.toString();\n\t\t\t\t\tJavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, type);\n\t\t\t\t\tyield objectMapper.readValue(inputJsonString, javaType);\n\t\t\t\t}\n\t\t\t\tcase LIST -> {\n\t\t\t\t\tif (!(inputObject instanceof List)) {\n\t\t\t\t\t\tthrow new RuntimeException(\"input is not List\");\n\t\t\t\t\t}\n\t\t\t\t\tyield (List<T>) inputObject;\n\t\t\t\t}\n\t\t\t\tcase ARRAY -> {\n\t\t\t\t\tif (inputObject == null || !inputObject.getClass().isArray()) {\n\t\t\t\t\t\tthrow new RuntimeException(\"input is not Array\");\n\t\t\t\t\t}\n\t\t\t\t\tyield Arrays.asList((T[]) inputObject);\n\t\t\t\t}\n\t\t\t};\n\t\t\tList<T> listElements = inputList.stream()\n\t\t\t\t.filter(filterChain)\n\t\t\t\t.sorted(comparatorChain)\n\t\t\t\t.limit(limitNumber != null && limitNumber > 0 ? limitNumber : Long.MAX_VALUE)\n\t\t\t\t.toList();\n\n\t\t\tObject output = switch (mode) {\n\t\t\t\tcase JSON_STR -> objectMapper.writeValueAsString(listElements);\n\t\t\t\tcase LIST -> listElements;\n\t\t\t\tcase ARRAY -> listElements.toArray();\n\t\t\t};\n\n\t\t\treturn Map.of(outputKey, output);\n\t\t}","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/ListOperatorNode.java#L86-L122","documentation":"In ARRAY mode, ListOperatorNode.apply requires the state value at inputKey to be a non-null Java array (inputObject.getClass().isArray()). If the value is null or not an array (List, String, etc.) this RuntimeException is thrown before the Arrays.asList cast.","triggerScenarios":"Mode ARRAY configured while the state value under inputKey is null, a List, or a String; upstream node never ran or wrote a different structure.","commonSituations":"Assuming JSON arrays in state become Java arrays (they become Lists via Jackson); passing optional state values that may be absent.","solutions":["Use Mode.LIST instead — Jackson and most nodes produce Lists, not arrays.","Ensure the upstream node genuinely writes a primitive/object array under inputKey.","Add a null/type check on t.value(inputKey) in an upstream validation step.","Wrap in try-catch mapping this error to a workflow-level failure message."],"exampleFix":"// before\nListOperatorNode.<Item>start().mode(Mode.ARRAY).inputKey(\"items\")... // items is a List\n// after\nListOperatorNode.<Item>start().mode(Mode.LIST).inputKey(\"items\")...","handlingStrategy":"type-guard","validationCode":"Object v = state.value(\"items\").orElse(null);\nif (v == null || !v.getClass().isArray()) throw new IllegalStateException(\"'items' must be an array, got \" + (v == null ? \"null\" : v.getClass()));","typeGuard":"boolean isArrayInput(OverAllState state, String key) {\n    return state.value(key).map(v -> v != null && v.getClass().isArray()).orElse(false);\n}","tryCatchPattern":"try {\n    out = listOperator.apply(state);\n} catch (RuntimeException e) {\n    if (\"input is not Array\".equals(e.getMessage())) {\n        throw new IllegalStateException(\"State holds no array; prefer Mode.LIST for JSON-sourced data\", e);\n    }\n    throw e;\n}","preventionTips":["Avoid Mode.ARRAY unless a node explicitly emits Java arrays.","JSON arrays deserialize to Lists, not arrays — use LIST.","Check for null state values before graph execution.","Prefer LIST mode as the default and document exceptions."],"tags":["list-operator","type-mismatch","array"],"backgroundTag":"type-mismatch","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}