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 type

View on GitHub (pinned to 820761864e)

Solutions

  1. Read the wrapped cause to identify the real failure, then fix the value of the named field in the properties map.
  2. Validate all properties values against expected types before calling update().
  3. Ensure field names in the properties map match declared field names exactly (case-sensitive).
  4. 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

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


AI-assisted analysis of apache/pulsar@820761864e (2026-09-06). Data as JSON: /api/errors/0d2b7d1f6aeec803. Report an issue: GitHub.