{"record":{"id":"2978b51aceca0cee","repo":"alibaba/spring-ai-alibaba","slug":"listoperatornode-apply-failed-wraps-caught-except","errorCode":null,"errorMessage":"ListOperatorNode apply failed (wraps caught exception)","messagePattern":"ListOperatorNode apply failed \\(wraps caught exception\\)","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":125,"sourceCode":"\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}\n\t\tcatch (Exception e) {\n\t\t\tlog.error(\"ListOperatorNode apply failed, message: {}\", e.getMessage());\n\t\t\tthrow new RuntimeException(e);\n\t\t}\n\t}\n\n\tpublic static class Builder<T> {\n\n\t\tprivate Mode mode;\n\n\t\tprivate String inputKey;\n\n\t\tprivate String outputKey;\n\n\t\tprivate final List<Predicate<T>> filters;\n\n\t\tprivate final List<Comparator<T>> comparators;\n\n\t\tprivate Long limitNumber;\n\n\t\tprivate Class<T> type;","sourceCodeStart":107,"sourceCodeEnd":143,"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#L107-L143","documentation":"ListOperatorNode.apply wraps its entire body in try/catch; any exception inside (the mode type guards above, Jackson parse errors, filter/transform/sort failures) is logged and rethrown as a wrapping RuntimeException. The message 'ListOperatorNode apply failed' indicates the node's processing pipeline failed; the original cause (bad JSON, wrong element type, exception in a user-supplied comparator/filter) is in getCause().","triggerScenarios":"Any failure within apply: malformed JSON string in JSON_STR mode, elements not assignable to T when parsing/deserializing, exceptions thrown by configured filterChain/transformers/sort comparators, or null input for any mode.","commonSituations":"Jackson failing to parse element type T (missing type info for generic elements); user comparator throwing on heterogeneous elements; JSON string with wrong structure (object instead of array).","solutions":["Log/inspect e.getCause() — it names the real failing step.","Validate the input JSON parses to a List of the expected element type before the node runs.","Ensure filters/transformers/comparators passed via the Builder are null-safe and type-safe.","Specify the concrete element type via the Builder's type parameter rather than raw Object."],"exampleFix":"// before\ncatch (Exception e) {\n    log.error(\"ListOperatorNode apply failed, message: {}\", e.getMessage());\n    throw new RuntimeException(e);\n}\n// after\ncatch (Exception e) {\n    log.error(\"ListOperatorNode apply failed\", e);\n    throw new RuntimeException(\"ListOperatorNode apply failed\", e);\n}","handlingStrategy":"try-catch","validationCode":"String json = (String) state.value(\"items\").orElse(null);\nif (json != null) {\n    JsonNode n = objectMapper.readTree(json);\n    if (!n.isArray()) throw new IllegalStateException(\"Expected JSON array for ListOperatorNode\");\n}","typeGuard":"boolean isValidListOperatorInput(OverAllState state, String key, Mode mode) {\n    return switch (mode) {\n        case JSON_STR -> state.value(key).map(v -> v instanceof String).orElse(false);\n        case LIST -> state.value(key).map(v -> v instanceof List).orElse(false);\n        case ARRAY -> state.value(key).map(v -> v != null && v.getClass().isArray()).orElse(false);\n    };\n}","tryCatchPattern":"try {\n    out = listOperator.apply(state);\n} catch (RuntimeException e) {\n    log.error(\"ListOperator failed, root cause: {}\", e.getCause(), e);\n    throw e.getCause() instanceof RuntimeException re ? re : e;\n}","preventionTips":["Always inspect getCause() — the wrapper hides the real error.","Validate JSON input shape before the node in tests.","Keep filters/comparators null-safe and exception-free.","Pin the concrete element type T in the Builder to avoid cast/parse surprises."],"tags":["list-operator","wrapped-exception","json-parse"],"backgroundTag":"json-parse-error","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}