{"record":{"id":"a8363a741a6ca6e0","repo":"apache/dubbo","slug":"value-s-for-idx-d-in-s-is-not-object","errorCode":null,"errorMessage":"value %s for idx %d in %s is not object","messagePattern":"value (.+?) for idx (.+?) in (.+?) is not object","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java","lineNumber":229,"sourceCode":"        Object value = obj.get(key);\n        if (!(value instanceof String)) {\n            throw new ClassCastException(\n                    String.format(\"value '%s' for key '%s' in '%s' is not String\", value, key, obj));\n        }\n        return (String) value;\n    }\n\n    /**\n     * Casts a list of unchecked JSON values to a list of checked objects in Java type.\n     * If the given list contains a value that is not a Map, throws an exception.\n     */\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public List<Map<String, ?>> checkObjectList(List<?> rawList) {\n        assert rawList != null;\n        for (int i = 0; i < rawList.size(); i++) {\n            if (!(rawList.get(i) instanceof Map)) {\n                throw new ClassCastException(\n                        String.format(\"value %s for idx %d in %s is not object\", rawList.get(i), i, rawList));\n            }\n        }\n        return (List<Map<String, ?>>) rawList;\n    }\n\n    /**\n     * Casts a list of unchecked JSON values to a list of String. If the given list\n     * contains a value that is not a String, throws an exception.\n     */\n    @SuppressWarnings(\"unchecked\")\n    @Override\n    public List<String> checkStringList(List<?> rawList) {\n        assert rawList != null;\n        for (int i = 0; i < rawList.size(); i++) {\n            if (!(rawList.get(i) instanceof String)) {\n                throw new ClassCastException(\n                        String.format(\"value '%s' for idx %d in '%s' is not string\", rawList.get(i), i, rawList));","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java#L211-L247","documentation":"Thrown by AbstractJsonUtilImpl.checkObjectList(List) when iterating rawList and an element is not a Map. The method casts an unchecked List<?> into List<Map<String,?>>, validating each entry; the first non-Map entry aborts with a ClassCastException naming the value, its index, and the whole list.getListOfObjects delegates to getList then checkObjectList, so the same exception surfaces through that path.","triggerScenarios":"jsonUtil.checkObjectList(rawList) (or getListOfObjects(obj,key)) where rawList contains at least one element that is not a Map — e.g. [\"a\", {\"b\":1}] or [1, 2, 3]. A list of pure objects passes.","commonSituations":"A JSON array of mixed types where a heterogeneous payload slips in; an array of scalars (strings/numbers) where an array of objects was expected; a flat list from an older API version; an error/status entry mixed into an otherwise-object array.","solutions":["Validate or filter the list before calling checkObjectList: rawList.stream().filter(Map.class::isInstance).map(m -> (Map<String,?>) m).collect(toList()).","If the schema requires all-object entries, reject/fix the upstream payload that produced a scalar entry.","Use getList (untyped) if you must tolerate heterogeneous entries, then handle each element by type.","Catch ClassCastException and report the offending index for triage."],"exampleFix":"// before\nList<Map<String,?>> rows = jsonUtil.checkObjectList(raw); // contains a stray String\n// after - filter to objects only\nList<Map<String,?>> rows = raw.stream()\n    .filter(Map.class::isInstance)\n    .map(m -> (Map<String,?>) m)\n    .collect(java.util.stream.Collectors.toList());","handlingStrategy":"type-guard","validationCode":"List<?> raw = ...;\nfor (Object e : raw) {\n    if (!(e instanceof Map)) {\n        // filter or reject before calling checkObjectList\n        raw = raw.stream().filter(Map.class::isInstance).collect(java.util.stream.Collectors.toList());\n        break;\n    }\n}\nreturn jsonUtil.checkObjectList(raw);","typeGuard":"private static boolean allObjects(List<?> rawList) {\n    for (Object e : rawList) if (!(e instanceof Map)) return false;\n    return true;\n}","tryCatchPattern":"try {\n    return jsonUtil.checkObjectList(rawList);\n} catch (ClassCastException e) {\n    // message names the offending index; fall back to filtering objects only\n    return rawList.stream()\n        .filter(Map.class::isInstance)\n        .map(m -> (Map<String,?>) m)\n        .collect(java.util.stream.Collectors.toList());\n}","preventionTips":["Filter a list to Map entries before calling checkObjectList when heterogeneity is possible.","Validate array element types against the schema at trust boundaries.","Use getList (untyped) and per-element handling if mixed types are legitimate."],"tags":["json","type-mismatch","classcast","list-validation","jsonutil","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}