{"record":{"id":"1574ad627bb69425","repo":"apache/pulsar","slug":"byte-string-cannot-be-empty","errorCode":null,"errorMessage":"byte string cannot be empty","messagePattern":"byte string cannot be empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/ByteUnitUtil.java","lineNumber":35,"sourceCode":" * under the License.\n */\npackage org.apache.pulsar.cli.converters;\n\nimport java.util.Arrays;\nimport java.util.Collections;\nimport java.util.HashSet;\nimport java.util.Set;\nimport lombok.experimental.UtilityClass;\n\n@UtilityClass\npublic class ByteUnitUtil {\n\n    private static Set<Character> sizeUnit = Collections.unmodifiableSet(\n            new HashSet<>(Arrays.asList('k', 'K', 'm', 'M', 'g', 'G', 't', 'T')));\n\n    public static long validateSizeString(String byteStr) {\n        if (byteStr.isEmpty()) {\n            throw new IllegalArgumentException(\"byte string cannot be empty\");\n        }\n\n        char last = byteStr.charAt(byteStr.length() - 1);\n        String subStr = byteStr.substring(0, byteStr.length() - 1);\n        long size;\n        try {\n            size = sizeUnit.contains(last)\n                    ? Long.parseLong(subStr)\n                    : Long.parseLong(byteStr);\n        } catch (IllegalArgumentException e) {\n            throw new IllegalArgumentException(String.format(\"Invalid size '%s'. Valid formats are: %s\",\n                    byteStr, \"(4096, 100K, 10M, 16G, 2T)\"));\n        }\n        switch (last) {\n            case 'k':\n            case 'K':\n                return size * 1024;\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/ByteUnitUtil.java#L17-L53","documentation":"ByteUnitUtil.validateSizeString parses human-readable byte-size strings (e.g. '10M', '2G', plain numbers). Passing an empty string throws IllegalArgumentException 'byte string cannot be empty'. It performs no null check, so only the empty-string case throws here.","triggerScenarios":"Calling validateSizeString(\"\") — typically an empty CLI flag value like --size=\"\" or an empty environment variable interpolated into a size argument.","commonSituations":"Shell scripts with unset size variables producing empty flags; users hitting enter on a size prompt; config-driven tooling where a size key exists but is blank.","solutions":["Provide a non-empty size string, e.g. '10G' or a plain byte count like '10485760'.","Default the variable in scripts: SIZE=${SIZE:-1G} before invoking the CLI.","Omit the flag entirely if the tool supports a default instead of passing an empty value.","If input comes from a config file, fill in the blank size property."],"exampleFix":"// before\npulsar-admin namespaces set-retention --size \"$SIZE\"   # SIZE empty\n// after\nSIZE=${SIZE:-1G}\npulsar-admin namespaces set-retention --size \"$SIZE\"","handlingStrategy":"validation","validationCode":"public static String requireNonEmptySize(String size) {\n    if (size == null || size.trim().isEmpty()) {\n        throw new IllegalArgumentException(\"size string is required, e.g. 10G or 10485760\");\n    }\n    return size.trim();\n}\n// shell: SIZE=${SIZE:-1G} before invoking the CLI","typeGuard":null,"tryCatchPattern":"try {\n    long bytes = ByteUnitUtil.validateSizeString(sizeStr);\n} catch (IllegalArgumentException e) {\n    System.err.println(\"Invalid size argument: \" + e.getMessage());\n}","preventionTips":["Default size variables in scripts (${SIZE:-1G}) so empty values never reach the tool.","Use documented suffixes: k/K, m/M, g/G, t/T, or a plain byte count.","If a size config key exists, ensure it is not blank.","Trim inputs; whitespace-only strings will fail parsing downstream even if not empty."],"tags":["cli","validation","parsing","pulsar"],"backgroundTag":"empty-required-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}