{"record":{"id":"769eb538a5297aae","repo":"theonedev/onedev","slug":"expected-single-character-not-s","errorCode":null,"errorMessage":"Expected single character, not \"{s}\"","messagePattern":"Expected single character, not \"(.+?)\"","errorType":"exception","errorClass":"org.apache.wicket.util.string.StringValueConversionException","httpStatus":null,"severity":"error","filePath":"server-core/src/main/java/org/apache/wicket/util/string/Strings.java","lineNumber":1007,"sourceCode":"\t * Converts the 1 character string s to a character.\n\t * \n\t * @param s\n\t *            The 1 character string to convert to a char.\n\t * @return Character value to convert\n\t * @throws StringValueConversionException\n\t *             when the string is longer or shorter than 1 character, or <code>null</code>.\n\t */\n\tpublic static char toChar(final String s) throws StringValueConversionException\n\t{\n\t\tif (s != null)\n\t\t{\n\t\t\tif (s.length() == 1)\n\t\t\t{\n\t\t\t\treturn s.charAt(0);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tthrow new StringValueConversionException(\"Expected single character, not \\\"\" + s +\n\t\t\t\t\t\"\\\"\");\n\t\t\t}\n\t\t}\n\n\t\tthrow new StringValueConversionException(\"Character value was null\");\n\t}\n\n\t/**\n\t * Converts unicodes to encoded &#92;uxxxx.\n\t * \n\t * @param unicodeString\n\t *            The unicode string\n\t * @return The escaped unicode string, like '\\u4F60\\u597D'.\n\t */\n\tpublic static String toEscapedUnicode(final String unicodeString)\n\t{\n\t\tif ((unicodeString == null) || (unicodeString.length() == 0))\n\t\t{","sourceCodeStart":989,"sourceCodeEnd":1025,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/util/string/Strings.java#L989-L1025","documentation":"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.","triggerScenarios":"Calling Strings.toChar(s) with a multi-character string such as \"ab\", \"null\", \" ,\" or a full word instead of a single character.","commonSituations":"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).","solutions":["Fix the source value so it contains exactly one character (trim surrounding whitespace)","If the value may be longer, take the intended character explicitly: s.charAt(0) after your own validation","Use a different parser (toChar/ValueModel of String) if the config genuinely holds multi-char separators","Handle null separately — null input throws the 'Character value was null' variant"],"exampleFix":"// before\nchar sep = Strings.toChar(\";\"); // fine\nchar bad = Strings.toChar(\"; \"); // throws\n// after\nString v = rawValue.trim();\nchar sep = (v.length() == 1) ? v.charAt(0) : fallbackSeparator;","handlingStrategy":"validation","validationCode":"// Java\nString v = s == null ? null : s.trim();\nif (v != null && v.length() != 1) {\n    throw new IllegalArgumentException(\"Expected single char, got: \" + s);\n}\nchar c = Strings.toChar(v);","typeGuard":null,"tryCatchPattern":"try {\n    c = Strings.toChar(value);\n} catch (StringValueConversionException e) {\n    log.warn(\"Not a single character: {}\", value);\n    c = DEFAULT_SEPARATOR;\n}","preventionTips":["Trim whitespace — multi-char failures are often trailing spaces or ', ' style separators","Validate length==1 in config loading code","Pick a different representation if the value is a multi-char delimiter","Distinguish null (separate error) from multi-char input"],"tags":["wicket","string-conversion","char"],"backgroundTag":"invalid-argument-format","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}