apache/dubbo · error · IllegalArgumentException

The source String is more than one character!

Error message

The source String is more than one character!

What it means

Thrown by StringToCharacterConverter.convert(source) when the input String has a length greater than 1. The converter is designed to map exactly one character; an empty string returns null, a single character returns that Character, and anything longer is rejected. This is part of Dubbo's SPI converter chain.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/convert/StringToCharacterConverter.java:35

package org.apache.dubbo.common.convert;

import static org.apache.dubbo.common.utils.StringUtils.length;

/**
 * The class to convert {@link String} to {@link Character}
 *
 * @since 2.7.6
 */
public class StringToCharacterConverter implements StringConverter<Character> {

    @Override
    public Character convert(String source) {
        int length = length(source);
        if (length == 0) {
            return null;
        }
        if (length > 1) {
            throw new IllegalArgumentException("The source String is more than one character!");
        }
        return source.charAt(0);
    }

    @Override
    public int getPriority() {
        return NORMAL_PRIORITY + 8;
    }
}

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Set the source value to exactly one character (e.g. "-" instead of "dash").
  2. If multi-character values are expected, change the target field type from char/Character to String so the converter is not selected.
  3. Validate the input length before it reaches the converter if the value comes from user input.

Example fix

// before (in dubbo URL param)
&separator=comma

// after
&separator=comma  // <-- change the consuming field type to String, OR set a single char:
&separator=,
Defensive patterns

Strategy: validation

Validate before calling

if (source != null && source.length() > 1) {
    // truncate, reject, or log before passing to the converter
    throw new IllegalArgumentException("Expected single char, got: " + source);
}

Type guard

static boolean isSingleChar(String s) {
    return s != null && s.length() == 1;
}

Try / catch

try {
    return converter.convert(source);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("more than one character")) {
        return source.charAt(0); // or return null / log
    }
    throw e;
}

Prevention

When it happens

Trigger: The converter is invoked when Dubbo's configuration or extension wiring needs to coerce a String property value into a Character-typed field or parameter, and the source string has 2+ characters. For example, a field of type char annotated for automatic conversion receiving the value "ab".

Common situations: A Dubbo config bean or @SPI extension has a char/Character field, and the user supplies a multi-character string in properties or URL parameters. Common when a single-character delimiter or flag (e.g. "-" or "?") is accidentally given as a full word like "dash" or "question".

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/0da1928477712ff9. Report an issue: GitHub.