theonedev/onedev · error · org.apache.wicket.util.string.StringValueConversionException

Expected single character, not "{s}"

Error message

Expected single character, not "{s}"

What it means

Strings.toChar(CharSequence) expects the input string to contain exactly one character. If the string is non-null but longer than one character, it throws StringValueConversionException('Expected single character, not "..."'). This guards against silently taking the first char of a longer value that is likely a mistake.

Source

Thrown at server-core/src/main/java/org/apache/wicket/util/string/Strings.java:1007

	 * Converts the 1 character string s to a character.
	 * 
	 * @param s
	 *            The 1 character string to convert to a char.
	 * @return Character value to convert
	 * @throws StringValueConversionException
	 *             when the string is longer or shorter than 1 character, or <code>null</code>.
	 */
	public static char toChar(final String s) throws StringValueConversionException
	{
		if (s != null)
		{
			if (s.length() == 1)
			{
				return s.charAt(0);
			}
			else
			{
				throw new StringValueConversionException("Expected single character, not \"" + s +
					"\"");
			}
		}

		throw new StringValueConversionException("Character value was null");
	}

	/**
	 * Converts unicodes to encoded &#92;uxxxx.
	 * 
	 * @param unicodeString
	 *            The unicode string
	 * @return The escaped unicode string, like '\u4F60\u597D'.
	 */
	public static String toEscapedUnicode(final String unicodeString)
	{
		if ((unicodeString == null) || (unicodeString.length() == 0))
		{

View on GitHub (pinned to d44925c47c)

Solutions

  1. Fix the source value so it contains exactly one character (trim surrounding whitespace)
  2. If the value may be longer, take the intended character explicitly: s.charAt(0) after your own validation
  3. Use a different parser (toChar/ValueModel of String) if the config genuinely holds multi-char separators
  4. Handle null separately — null input throws the 'Character value was null' variant

Example fix

// before
char sep = Strings.toChar(";"); // fine
char bad = Strings.toChar("; "); // throws
// after
String v = rawValue.trim();
char sep = (v.length() == 1) ? v.charAt(0) : fallbackSeparator;
Defensive patterns

Strategy: validation

Validate before calling

// Java
String v = s == null ? null : s.trim();
if (v != null && v.length() != 1) {
    throw new IllegalArgumentException("Expected single char, got: " + s);
}
char c = Strings.toChar(v);

Try / catch

try {
    c = Strings.toChar(value);
} catch (StringValueConversionException e) {
    log.warn("Not a single character: {}", value);
    c = DEFAULT_SEPARATOR;
}

Prevention

When it happens

Trigger: Calling Strings.toChar(s) with a multi-character string such as "ab", "null", " ," or a full word instead of a single character.

Common situations: Parsing settings files where the value was meant to be a delimiter but a multi-char string was supplied; passing 'null' or empty-ish strings from property files; locale/keyboard variants of separators (e.g. ", " with a trailing space).

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/769eb538a5297aae. Report an issue: GitHub.