{"id":"02b0f33c2dee72d7","repo":"apache/kafka","slug":"non-string-value-found-in-original-settings-for-ke","errorCode":null,"errorMessage":"Non-string value found in original settings for key entry.getKey(): (entry.getValue() == null ? null : entry.getValue().getClass().getName())","messagePattern":"Non-string value found in original settings for key entry\\.getKey\\(\\): \\(entry\\.getValue\\(\\) == null \\? null : entry\\.getValue\\(\\)\\.getClass\\(\\)\\.getName\\(\\)\\)","errorType":"exception","errorClass":"ClassCastException","httpStatus":null,"severity":"error","filePath":"clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java","lineNumber":268,"sourceCode":"\n    public Map<String, Object> originals(Map<String, Object> configOverrides) {\n        Map<String, Object> copy = new RecordingMap<>();\n        copy.putAll(originals);\n        copy.putAll(configOverrides);\n        return copy;\n    }\n\n    /**\n     * Get all the original settings, ensuring that all values are of type String.\n     *\n     * @return the original settings\n     * @throws ClassCastException if any of the values are not strings\n     */\n    public Map<String, String> originalsStrings() {\n        Map<String, String> copy = new RecordingMap<>();\n        for (Map.Entry<String, ?> entry : originals.entrySet()) {\n            if (!(entry.getValue() instanceof String))\n                throw new ClassCastException(\"Non-string value found in original settings for key \" + entry.getKey() +\n                        \": \" + (entry.getValue() == null ? null : entry.getValue().getClass().getName()));\n            copy.put(entry.getKey(), (String) entry.getValue());\n        }\n        return copy;\n    }\n\n    /**\n     * Gets all original settings with the given prefix, stripping the prefix before adding it to the output.\n     *\n     * @param prefix the prefix to use as a filter\n     * @return a Map containing the settings with the prefix\n     */\n    public Map<String, Object> originalsWithPrefix(String prefix) {\n        return originalsWithPrefix(prefix, true);\n    }\n\n    /**\n     * Gets all original settings with the given prefix.","sourceCodeStart":250,"sourceCodeEnd":286,"githubUrl":"https://github.com/apache/kafka/blob/c31c9215e131f8c17e79f8901b48c13ee6aa8e7a/clients/src/main/java/org/apache/kafka/common/config/AbstractConfig.java#L250-L286","documentation":"ClassCastException thrown by AbstractConfig.originalsStrings() when iterating the raw `originals` map and encountering a value that is not a String. originalsStrings() is documented to require all original settings to be strings; it constructs a Map<String,String> and casts each value. The message reports the offending key and (if non-null) the value's Java class name so the caller can see exactly which entry is mis-typed. This is a type-contract violation on the inputs supplied to the config constructor, not a parse error.","triggerScenarios":"Calling config.originalsStrings() after building an AbstractConfig from a Map<?,?> originals that contains a non-String value, e.g. a List (for a list-typed property supplied programmatically rather than as a comma-separated string), a Number/Boolean, or a Password object. Connect and some tools call originalsStrings() to externalize or log settings as strings.","commonSituations":"See trigger scenarios.","solutions":["Supply originals as String values only (e.g. pass a Properties object or Map<String,String> with list values as comma-separated strings), so originalsStrings() can return them verbatim.","If you need typed values, use the parsed accessors (getList, getInt, ...) instead of originalsStrings().","Audit which key triggered the cast (named in the message) and convert that entry to a string at the source.","Avoid mixing a pre-parsed Map<String,Object> with code that expects originalsStrings(); pick one representation."],"exampleFix":"// before: originals contain a non-String value\nMap<String, Object> originals = new HashMap<>();\noriginals.put(\"bootstrap.servers\", Arrays.asList(\"host1:9092\", \"host2:9092\"));\nAbstractConfig config = new AbstractConfig(def, originals);\nMap<String, String> strings = config.originalsStrings(); // ClassCastException: List\n\n// after: pass originals as strings\nMap<String, Object> originals = new HashMap<>();\noriginals.put(\"bootstrap.servers\", \"host1:9092,host2:9092\");\nAbstractConfig config = new AbstractConfig(def, originals);\nMap<String, String> strings = config.originalsStrings(); // ok","handlingStrategy":"type-guard","validationCode":"// originalsStrings() requires every value to be a String; pre-filter or coerce.\njava.util.Map<String, String> safe = new java.util.HashMap<>();\nfor (java.util.Map.Entry<String, ?> e : config.originals().entrySet()) {\n    Object v = e.getValue();\n    if (v instanceof String s) {\n        safe.put(e.getKey(), s);\n    } else if (v != null) {\n        safe.put(e.getKey(), String.valueOf(v)); // explicit coercion, no surprise CCE\n    }\n}","typeGuard":"boolean allOriginalsAreStrings(org.apache.kafka.common.config.AbstractConfig cfg) {\n    return cfg.originals().values().stream().allMatch(v -> v == null || v instanceof String);\n}","tryCatchPattern":"try {\n    Map<String, String> raw = config.originalsStrings();\n} catch (ClassCastException cce) {\n    // message: \"Non-string value found in original settings for key ...\"\n    log.warn(\"Mixing typed and string originals is unsafe; coercing manually\", cce);\n    Map<String, String> raw = config.originals().entrySet().stream()\n        .collect(java.util.stream.Collectors.toMap(\n            Map.Entry::getKey,\n            e -> e.getValue() == null ? null : String.valueOf(e.getValue())));\n}","preventionTips":["Build your Properties/Map with String values only when you plan to call originalsStrings().","Do not mix parsed numeric/boolean values into the map you hand to the constructor if you later need originalsStrings().","Prefer originals() (returns Map<String,?>) unless you specifically need String-only semantics."],"tags":["configuration","kafka-client","classcast","configdef"],"analyzedSha":"c31c9215e131f8c17e79f8901b48c13ee6aa8e7a","analyzedAt":"2026-08-03T12:34:05.770Z","schemaVersion":2}