apache/pulsar · error · IllegalArgumentException
failed to initialize %s field while setting value %s
Error message
failed to initialize %s field while setting value %s
What it means
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.
Source
Thrown at pulsar-common/src/main/java/org/apache/pulsar/common/util/FieldParser.java:156
* @param obj
* object which needs to be updated
* @throws IllegalArgumentException
* if the properties key-value contains incorrect value type
*/
public static <T> void update(Map<String, String> properties, T obj) throws IllegalArgumentException {
Field[] fields = obj.getClass().getDeclaredFields();
Arrays.stream(fields).forEach(f -> {
if (properties.containsKey(f.getName())) {
try {
f.setAccessible(true);
String v = properties.get(f.getName());
if (!StringUtils.isBlank(v)) {
f.set(obj, value(trim(v), f));
} else {
setEmptyValue(v, f, obj);
}
} catch (Exception e) {
throw new IllegalArgumentException(format("failed to initialize %s field while setting value %s",
f.getName(), properties.get(f.getName())), e);
}
}
});
}
/**
* Converts value as per appropriate DataType of the field.
*
* @param strValue
* : string value of the object
* @param field
* : field of the attribute
* @return
*/
public static Object value(String strValue, Field field) {
requireNonNull(field);
// if field is not primitive typeView on GitHub (pinned to 820761864e)
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.
Example fix
// before
Map<String,String> props = Map.of("advertisedAddress", "", "port", "66-50");
FieldParser.update(props, conf); // failed to initialize port field while setting value 66-50
// after
props = Map.of("advertisedAddress", "", "port", "6650");
FieldParser.update(props, conf); Defensive patterns
Strategy: validation
Validate before calling
static void prevalidate(Map<String,String> props, Class<?> cfgClass) {
for (Field f : cfgClass.getDeclaredFields()) {
String v = props.get(f.getName());
if (v != null && !v.isBlank() && !List.class.equals(f.getType())
&& !Set.class.equals(f.getType()) && !Map.class.equals(f.getType())
&& !Optional.class.equals(f.getType())) {
FieldParser.value(v.trim(), f); // throws early with field name if unparseable
}
}
} Try / catch
try {
FieldParser.update(props, conf);
} catch (IllegalArgumentException e) {
// e.getMessage() names the field and raw value; e.getCause() has the real error
throw new IllegalStateException("invalid config: " + e.getMessage(), e.getCause());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- configuredService should not be an instance of SystemTopicBa
- Invalid auto split/merge configuration: ${message}
- Failed to instantiate ${className}
- Exception caused while converting configuration: ${message}
- Failed to compute configuration overrides
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/0d2b7d1f6aeec803.
Report an issue: GitHub.