{"record":{"id":"0d2b7d1f6aeec803","repo":"apache/pulsar","slug":"failed-to-initialize-s-field-while-setting-value-0d2b7d","errorCode":null,"errorMessage":"failed to initialize %s field while setting value %s","messagePattern":"failed to initialize (.+?) field while setting value (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java","lineNumber":156,"sourceCode":"     * @param obj\n     *            object which needs to be updated\n     * @throws IllegalArgumentException\n     *             if the properties key-value contains incorrect value type\n     */\n    public static <T> void update(Map<String, String> properties, T obj) throws IllegalArgumentException {\n        Field[] fields = obj.getClass().getDeclaredFields();\n        Arrays.stream(fields).forEach(f -> {\n            if (properties.containsKey(f.getName())) {\n                try {\n                    f.setAccessible(true);\n                    String v = properties.get(f.getName());\n                    if (!StringUtils.isBlank(v)) {\n                        f.set(obj, value(trim(v), f));\n                    } else {\n                        setEmptyValue(v, f, obj);\n                    }\n                } catch (Exception e) {\n                    throw new IllegalArgumentException(format(\"failed to initialize %s field while setting value %s\",\n                            f.getName(), properties.get(f.getName())), e);\n                }\n            }\n        });\n    }\n\n    /**\n     * Converts value as per appropriate DataType of the field.\n     *\n     * @param strValue\n     *            : string value of the object\n     * @param field\n     *            : field of the attribute\n     * @return\n     */\n    public static Object value(String strValue, Field field) {\n        requireNonNull(field);\n        // if field is not primitive type","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java#L138-L174","documentation":"FieldParser.update() reflectively sets fields of an object from a String properties map. Any exception while parsing or assigning a field (bad value, unsupported type, access failure) is rethrown as IllegalArgumentException naming the field and raw value, with the underlying exception as cause.","triggerScenarios":"Calling FieldParser.update(properties, obj) where a properties value cannot be converted for its matching field, e.g. properties {\"port\":\"abc\"} on an int port field, or a field type value()/setEmptyValue() cannot handle.","commonSituations":"Loading broker/service configuration from a properties file or environment overrides where one key holds a malformed value; renamed or type-changed config fields after a Pulsar upgrade; blank values for primitive fields.","solutions":["Read the wrapped cause to identify the real failure, then fix the value of the named field in the properties map.","Validate all properties values against expected types before calling update().","Ensure field names in the properties map match declared field names exactly (case-sensitive).","If the field type is genuinely unsupported, change the field type or convert the value to a supported one before passing it in."],"exampleFix":"// before\nMap<String,String> props = Map.of(\"advertisedAddress\", \"\", \"port\", \"66-50\");\nFieldParser.update(props, conf); // failed to initialize port field while setting value 66-50\n// after\nprops = Map.of(\"advertisedAddress\", \"\", \"port\", \"6650\");\nFieldParser.update(props, conf);","handlingStrategy":"validation","validationCode":"static void prevalidate(Map<String,String> props, Class<?> cfgClass) {\n    for (Field f : cfgClass.getDeclaredFields()) {\n        String v = props.get(f.getName());\n        if (v != null && !v.isBlank() && !List.class.equals(f.getType())\n                && !Set.class.equals(f.getType()) && !Map.class.equals(f.getType())\n                && !Optional.class.equals(f.getType())) {\n            FieldParser.value(v.trim(), f); // throws early with field name if unparseable\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    FieldParser.update(props, conf);\n} catch (IllegalArgumentException e) {\n    // e.getMessage() names the field and raw value; e.getCause() has the real error\n    throw new IllegalStateException(\"invalid config: \" + e.getMessage(), e.getCause());\n}","preventionTips":["Keep properties keys exactly equal to declared field names","Validate the full properties map against the config class before applying","After upgrades, diff your config keys/types against the new config class fields","Wrap update() with a try-catch that surfaces the cause, not just the generic message"],"tags":["reflection","configuration","illegal-argument"],"backgroundTag":"config-field-initialization-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"}