{"record":{"id":"5de2eb8db8b22c8b","repo":"didi/DoKit","slug":"input-must-be-shorter-than-or-equal-to-the-number","errorCode":null,"errorMessage":"input must be shorter than or equal to the number of spaces: \" + size","messagePattern":"input must be shorter than or equal to the number of spaces: \" \\+ size","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/loginfo/util/StringUtil.java","lineNumber":23,"sourceCode":"import java.util.ArrayList;\nimport java.util.List;\n\n/**\n * @author nolan\n */\npublic class StringUtil {\n\n    /**\n     * Pad the specified number of spaces to the input string to make it that length\n     *\n     * @param input\n     * @param size\n     * @return\n     */\n    public static String padLeft(String input, int size) {\n\n        if (input.length() > size) {\n            throw new IllegalArgumentException(\"input must be shorter than or equal to the number of spaces: \" + size);\n        }\n\n        StringBuilder sb = new StringBuilder();\n        for (int i = input.length(); i < size; i++) {\n            sb.append(\" \");\n        }\n        return sb.append(input).toString();\n    }\n\n    /**\n     * same as the String.split(), except it doesn't use regexes, so it's faster.\n     *\n     * @param str       - the string to split up\n     * @param delimiter the delimiter\n     * @return the split string\n     */\n    public static String[] split(String str, String delimiter) {\n        List<String> result = new ArrayList<>();","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/loginfo/util/StringUtil.java#L5-L41","documentation":"Thrown by DoKit's StringUtil.padLeft(input, size) when the input string is longer than the target padded length. padLeft prepends spaces until the string reaches exactly `size` characters; if the input already exceeds that length there is no valid way to pad it, so the method rejects the call with IllegalArgumentException.","triggerScenarios":"Calling StringUtil.padLeft(\"hello\", 3) or any variant where input.length() > size, e.g. while formatting log/network trace columns in the loginfo kit with a string longer than the configured column width.","commonSituations":"Fixed-width formatting of dynamic content (URLs, headers, tag strings) where the developer assumed the input would fit; column width configured smaller than the longest expected value.","solutions":["Truncate or verify the input before calling: if (input.length() > size) input = input.substring(0, size);","Reconsider whether a hard fail is desired — for display purposes a truncate-and-warn policy is usually friendlier than an exception","Pass a size that is always >= the maximum possible input length"],"exampleFix":"// before\nString s = StringUtil.padLeft(longUrl, 8); // throws if longUrl > 8 chars\n\n// after\nString s = longUrl.length() > 8 ? longUrl.substring(0, 8) : StringUtil.padLeft(longUrl, 8);","handlingStrategy":"validation","validationCode":"if (input != null && input.length() <= size) { String s = StringUtil.padLeft(input, size); } else { /* truncate or reject */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-check input.length() <= size before every padLeft call","Prefer String.format(\"%\" + size + \"s\", input) patterns that don't throw on overflow when truncation is acceptable"],"tags":["android","string","formatting","validation"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}