{"record":{"id":"886780b3a0f89965","repo":"theonedev/onedev","slug":"character-value-was-null","errorCode":null,"errorMessage":"Character value was null","messagePattern":"Character value was null","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":1012,"sourceCode":"\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{\n\t\t\treturn unicodeString;\n\t\t}\n\t\tint len = unicodeString.length();\n\t\tint bufLen = len * 2;\n\t\tStringBuilder outBuffer = new StringBuilder(bufLen);","sourceCodeStart":994,"sourceCodeEnd":1030,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/org/apache/wicket/util/string/Strings.java#L994-L1030","documentation":"Strings.toChar(CharSequence) throws StringValueConversionException('Character value was null') when the input string is null (the empty-string case is handled separately upstream). The conversion API refuses to guess a default character, so callers must ensure the value is present before conversion.","triggerScenarios":"Calling Strings.toChar(null), or toChar(value) where value comes from an absent property/parameter resolving to null.","commonSituations":"Missing entries in properties/config files; optional request parameters that were never supplied; defaults not being applied before conversion.","solutions":["Check Strings.isEmpty(value) and supply a default character before calling toChar","Provide a fallback in the caller: value == null ? DEFAULT : Strings.toChar(value)","Ensure the config entry or parameter is actually set when the conversion is required"],"exampleFix":"// before\nchar sep = Strings.toChar(props.get(\"separator\")); // null -> throw\n// after\nString v = props.get(\"separator\");\nchar sep = Strings.isEmpty(v) ? ';' : Strings.toChar(v);","handlingStrategy":"validation","validationCode":"// Java\nif (Strings.isEmpty(s)) {\n    s = DEFAULT_SEPARATOR_STRING; // or skip conversion\n}\nchar c = Strings.toChar(s);","typeGuard":null,"tryCatchPattern":"try {\n    c = Strings.toChar(value);\n} catch (StringValueConversionException e) {\n    if (value == null) log.warn(\"Character value missing, using default\");\n    c = DEFAULT;\n}","preventionTips":["Apply defaults for missing config entries before conversion","Use Strings.isEmpty as the null/empty guard","Make optional char settings explicitly Optional in your config layer","Fail fast at config-load time rather than deep in conversion"],"tags":["wicket","string-conversion","null-value"],"backgroundTag":"null-argument","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"}