{"record":{"id":"0da1928477712ff9","repo":"apache/dubbo","slug":"the-source-string-is-more-than-one-character","errorCode":null,"errorMessage":"The source String is more than one character!","messagePattern":"The source String is more than one character!","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/convert/StringToCharacterConverter.java","lineNumber":35,"sourceCode":"package org.apache.dubbo.common.convert;\n\nimport static org.apache.dubbo.common.utils.StringUtils.length;\n\n/**\n * The class to convert {@link String} to {@link Character}\n *\n * @since 2.7.6\n */\npublic class StringToCharacterConverter implements StringConverter<Character> {\n\n    @Override\n    public Character convert(String source) {\n        int length = length(source);\n        if (length == 0) {\n            return null;\n        }\n        if (length > 1) {\n            throw new IllegalArgumentException(\"The source String is more than one character!\");\n        }\n        return source.charAt(0);\n    }\n\n    @Override\n    public int getPriority() {\n        return NORMAL_PRIORITY + 8;\n    }\n}\n","sourceCodeStart":17,"sourceCodeEnd":45,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/convert/StringToCharacterConverter.java#L17-L45","documentation":"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.","triggerScenarios":"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\".","commonSituations":"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\".","solutions":["Set the source value to exactly one character (e.g. \"-\" instead of \"dash\").","If multi-character values are expected, change the target field type from char/Character to String so the converter is not selected.","Validate the input length before it reaches the converter if the value comes from user input."],"exampleFix":"// before (in dubbo URL param)\n&separator=comma\n\n// after\n&separator=comma  // <-- change the consuming field type to String, OR set a single char:\n&separator=,","handlingStrategy":"validation","validationCode":"if (source != null && source.length() > 1) {\n    // truncate, reject, or log before passing to the converter\n    throw new IllegalArgumentException(\"Expected single char, got: \" + source);\n}","typeGuard":"static boolean isSingleChar(String s) {\n    return s != null && s.length() == 1;\n}","tryCatchPattern":"try {\n    return converter.convert(source);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"more than one character\")) {\n        return source.charAt(0); // or return null / log\n    }\n    throw e;\n}","preventionTips":["Validate string length before converting to Character.","Use String-typed fields if multi-character values are expected.","Add input validation at the boundary where the value enters."],"tags":["converter","type-mismatch","character"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}