{"record":{"id":"83bd044bd4cdcdee","repo":"apache/pulsar","slug":"failed-to-load-config-into-existing-configuration","errorCode":null,"errorMessage":"Failed to load config into existing configuration data","messagePattern":"Failed to load config into existing configuration data","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ConfigurationDataUtils.java","lineNumber":108,"sourceCode":"\n    private static final ObjectMapper MAPPER = create();\n\n    private ConfigurationDataUtils() {}\n\n    @SuppressWarnings(\"unchecked\")\n    public static <T> T loadData(Map<String, Object> config,\n                                 T existingData,\n                                 Class<T> dataCls) {\n        try {\n            String existingConfigJson = MAPPER.writeValueAsString(existingData);\n            Map<String, Object> existingConfig = MAPPER.readValue(existingConfigJson, Map.class);\n            Map<String, Object> newConfig = new HashMap<>();\n            newConfig.putAll(existingConfig);\n            newConfig.putAll(config);\n            String configJson = MAPPER.writeValueAsString(newConfig);\n            return MAPPER.readValue(configJson, dataCls);\n        } catch (IOException e) {\n            throw new RuntimeException(\"Failed to load config into existing configuration data\", e);\n        }\n\n    }\n\n}\n\n","sourceCodeStart":90,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/conf/ConfigurationDataUtils.java#L90-L115","documentation":"loadData merges an incoming config map into an existing configuration object's map, serializes the merged map to JSON, and deserializes it back into the target configuration class. Any Jackson IOException during that write/read cycle (unknown properties that aren't ignored, type mismatches between the map values and target field types, invalid JSON-convertible values) is rethrown as this RuntimeException.","triggerScenarios":"Calling ConfigurationDataUtils.loadData(configMap, existingConfig, SomeConfigurationData.class) where a map key maps to a field of an incompatible type (e.g. a String where an int or Map is expected), or a value that Jackson cannot serialize/deserialize.","commonSituations":"Loading client/producer/consumer config from properties files where all values are Strings but the target fields are typed (int, boolean, enums); passing a config map containing keys with wrong value types; typos in keys whose values then coerce incorrectly.","solutions":["Inspect the wrapped IOException cause for the exact field and value type mismatch.","Convert values in the map to the correct Java types before calling loadData (e.g. parse numbers, booleans).","Verify every key matches a field name on the target ConfigurationData class (typos produce coercion failures).","Wrap the loadData call in try-catch and fall back to sanitized/validated config in the caller."],"exampleFix":"// before\nprops.forEach((k, v) -> configMap.put(k, v)); // all Strings\n// after\nconfigMap.put(\"negativeAckRedeliveryDelayMs\", Long.parseLong(props.getProperty(\"negativeAckRedeliveryDelayMs\")));","handlingStrategy":"validation","validationCode":"// Validate types before calling loadData\nObjects.requireNonNull(configMap, \"configMap\");\nconfigMap.forEach((k, v) -> System.out.println(k + \" -> \" + (v == null ? \"null\" : v.getClass().getSimpleName())));","typeGuard":"boolean isLoadable(Map<String,Object> cfg) { return cfg != null && cfg.values().stream().noneMatch(v -> v == null); }","tryCatchPattern":"try { return ConfigurationDataUtils.loadData(map, existing, ClientConfigurationData.class); } catch (RuntimeException e) { log.error(\"Config load failed\", e.getCause()); throw new IllegalArgumentException(\"Invalid client configuration\", e); }","preventionTips":["Coerce properties-file strings to proper types (Long, Boolean, enums) before merging into the config map.","Cross-check keys against the fields of the target ConfigurationData class.","Log the IOException cause which names the exact failing field."],"tags":["configuration","jackson","deserialization","type-mismatch"],"backgroundTag":"config-deserialization-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}