{"record":{"id":"a2d52bf3a32107a4","repo":"apache/dubbo","slug":"value-s-for-key-s-in-s-is-not-string","errorCode":null,"errorMessage":"value '%s' for key '%s' in '%s' is not String","messagePattern":"value '(.+?)' for key '(.+?)' in '(.+?)' is not String","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java","lineNumber":213,"sourceCode":"            }\n        }\n        throw new IllegalArgumentException(String.format(\"value '%s' for key '%s' is not a long integer\", value, key));\n    }\n\n    /**\n     * Gets a string from an object for the given key.  If the key is not present, this returns null.\n     * If the value is not a String, throws an exception.\n     */\n    @Override\n    public String getString(Map<String, ?> obj, String key) {\n        assert obj != null;\n        assert key != null;\n        if (!obj.containsKey(key)) {\n            return null;\n        }\n        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            }","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/json/impl/AbstractJsonUtilImpl.java#L195-L231","documentation":"Thrown by AbstractJsonUtilImpl.getString(Map,String) when obj contains key but its value is not a String. getString returns null for an absent key, so this ClassCastException fires only when the key is present but the value is a Number, Boolean, Map, List, or other non-String reference. It signals a schema/type mismatch: a JSON scalar/object/array where a JSON string was expected.","triggerScenarios":"jsonUtil.getString(obj, key) where obj.get(key) exists and is not a String — e.g. JSON {\"name\": 42} or {\"name\": true} or {\"name\": {\"first\":\"a\"}} with getString(obj, \"name\").","commonSituations":"A field that was a string got changed to a number/boolean upstream; an ID field switching from numeric string to actual number; a conditional payload where the field is sometimes text and sometimes a structured object; an enum/code field returned as a number; localization turning a value into a nested object.","solutions":["Inspect obj.get(key)'s runtime type and reconcile with the expected schema.","If the value may legitimately be non-string, coerce with String.valueOf(raw) before use.","Normalize the producer to emit strings for that field.","Catch ClassCastException and report the offending key/value for triage."],"exampleFix":"// before\nString name = jsonUtil.getString(obj, \"name\"); // name is Integer 42\n// after - coerce safely\nObject raw = obj.get(\"name\");\nString name = raw == null ? null : (raw instanceof String ? (String) raw : String.valueOf(raw));","handlingStrategy":"type-guard","validationCode":"Object raw = obj.get(key);\nif (raw != null && !(raw instanceof String)) {\n    return String.valueOf(raw); // coerce non-string scalars\n}\nreturn jsonUtil.getString(obj, key);","typeGuard":"private static boolean isStringOrNull(Object value) {\n    return value == null || value instanceof String;\n}","tryCatchPattern":"try {\n    return jsonUtil.getString(obj, key);\n} catch (ClassCastException e) {\n    Object raw = obj.get(key);\n    return raw == null ? null : String.valueOf(raw); // coerce instead of failing\n}","preventionTips":["Coerce with String.valueOf when the field may be a non-string scalar.","Validate the schema for fields read with getString.","Reconcile with the producer when a string field changes to a number/boolean."],"tags":["json","type-mismatch","classcast","jsonutil","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}